Skip to main content
This guide teaches the product in the same order you should use it:
  1. call a model
  2. stream a response
  3. add a tool
  4. create an agent
  5. persist state
  6. inspect a structured turn
  7. build a live turn

Install

1. Call A Model

Use generate_text() when you do not need state.
What you learned:
  • providers create models
  • generate_text() runs one model loop
  • the result contains text, usage, finish reason, and steps

2. Stream A Response

Use stream_text() for raw streaming.
Use core streaming for scripts and simple UIs. Use Agent.turn() later when you need events and steering.

3. Add A Tool

Tools are typed Python functions the model can call.
What you learned:
  • @tool turns a Python function into a model-callable tool
  • tool arguments are described with type hints and Field
  • ai-query handles the tool-call loop

4. Create An Agent

Use Agent when you want memory, state, or persistence.
What changed:
  • the agent has an identity: assistant
  • message history is stored on the agent
  • chat() appends the user message and assistant response

5. Persist Agent History

Use SQLiteStorage when you want history to survive restarts.
Later, recreate the same agent ID with the same storage file:

6. Get A Structured Result

Use run() when your app needs more than final text.
Use chat() for user-facing responses. Use run() when your application logic needs the metadata.

7. Build A Live Turn

Use turn() for CLIs, web UIs, SSE streams, and controllable runtimes.
Steer a live turn at the next safe step boundary:
Abort a live turn:

Concepts

Learn the mental model behind the framework.

Navigating ai-query

Choose the right API for your use case.

Stateful Agents

Go deeper on storage, state, and conversations.

Live Turns

Build interactive runtimes with events and steering.