Quick Start
from collections.abc import Sequence
from agent import Agent, CallableLLM, Message
def generate(messages: Sequence[Message]) -> str:
user_message = messages[-1].content
return f"Runtime received: {user_message}"
agent = Agent(
llm=CallableLLM(generate),
instructions="Answer clearly and briefly.",
)
print(agent.run("Explain the difference between 은/는 and 이/가."))
Add a Tool
def calculator(expression: str) -> str:
"""Evaluate a small arithmetic expression."""
return str(eval(expression, {"__builtins__": {}}, {}))
agent.add_tool(calculator)
Tools are exposed to the LLM as schemas. If the LLM returns a structured tool call, the runtime executes the registered function and sends the result back to the LLM.
Add RAG
from agent import Agent, CallableLLM
from rag import RAG
rag = RAG()
rag.add_text(
"In Korean, 은/는 are topic particles. 이/가 usually mark the subject.",
source="korean-grammar-notes",
)
agent = Agent(llm=CallableLLM(generate), rag=rag)
The runtime calls rag.retrieve(...) and adds retrieved chunks to the prompt.