Riza Code Interpreter는 AI 에이전트가 생성한 Python 또는 JavaScript를 실행하기 위한 WASM 기반 격리 환경입니다.
이 노트북에서는 LLM이 단독으로 해결할 수 없는 문제를 Python을 사용하여 해결하는 에이전트의 예제를 만들어보겠습니다: “strawberry”라는 단어에서 ‘r’의 개수를 세는 것입니다. 시작하기 전에 Riza dashboard에서 API key를 받으세요. 더 많은 가이드와 전체 API reference는 Riza Code Interpreter API documentation을 참조하세요. 필요한 dependencies가 설치되어 있는지 확인하세요.
pip install -qU langchain-community rizaio
API key를 환경 변수로 설정하세요.
%env ANTHROPIC_API_KEY=<your_anthropic_api_key_here>
%env RIZA_API_KEY=<your_riza_api_key_here>
from langchain_community.tools.riza.command import ExecPython
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_anthropic import ChatAnthropic
from langchain_core.prompts import ChatPromptTemplate
ExecPython tool을 초기화합니다.
tools = [ExecPython()]
Anthropic의 Claude Haiku model을 사용하여 agent를 초기화합니다.
llm = ChatAnthropic(model="claude-3-haiku-20240307", temperature=0)

prompt_template = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "You are a helpful assistant. Make sure to use a tool if you need to solve a problem.",
        ),
        ("human", "{input}"),
        ("placeholder", "{agent_scratchpad}"),
    ]
)

agent = create_tool_calling_agent(llm, tools, prompt_template)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
# Ask a tough question
result = agent_executor.invoke({"input": "how many rs are in strawberry?"})
print(result["output"][0]["text"])
> Entering new AgentExecutor chain...

Invoking: `riza_exec_python` with `{'code': 'word = "strawberry"\nprint(word.count("r"))'}`
responded: [{'id': 'toolu_01JwPLAAqqCNCjVuEnK8Fgut', 'input': {}, 'name': 'riza_exec_python', 'type': 'tool_use', 'index': 0, 'partial_json': '{"code": "word = \\"strawberry\\"\\nprint(word.count(\\"r\\"))"}'}]

3
[{'text': '\n\nThe word "strawberry" contains 3 "r" characters.', 'type': 'text', 'index': 0}]

> Finished chain.


The word "strawberry" contains 3 "r" characters.

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I