Skip to main content

Build Your First Agent

This guide builds a simple agent that can use tools to answer questions. You’ll see the full loop: user message → LLM reasoning → tool call → tool result → final response.

Define a Tool

Tools are async functions decorated with @tool:
Key points:
  • Tools MUST be async def
  • The docstring becomes the tool’s description for the LLM
  • Best Practices section is injected into the system prompt as usage guidance
  • Return type annotation tells the framework what to expect

Define the Agent

Key points:
  • @llm_chat creates a multi-turn agent (vs @llm_function for single calls)
  • toolkit=[...] gives the agent access to tools
  • stream=True enables streaming responses
  • history parameter name is special — the framework manages conversation state through it
  • The docstring is the agent’s system prompt

Run and Consume Events

@llm_chat returns an async generator of ReactOutput — either response chunks or lifecycle events:

What Happened Under the Hood

This is the ReAct loop — reason, act, observe, repeat. The framework handles all of it. You defined a function signature and a tool.

Add More Tools

What’s Next

Multi-Turn Chat

Manage longer conversations with history and streaming.

Why This Design?

Understand why LLM calls are functions, not chains.