- call a model
- stream a response
- add a tool
- create an agent
- persist state
- inspect a structured turn
- build a live turn
Install
1. Call A Model
Usegenerate_text() when you do not need state.
- providers create models
generate_text()runs one model loop- the result contains text, usage, finish reason, and steps
2. Stream A Response
Usestream_text() for raw streaming.
Agent.turn() later when you need events and steering.
3. Add A Tool
Tools are typed Python functions the model can call.@toolturns 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
UseAgent when you want memory, state, or persistence.
- 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
UseSQLiteStorage when you want history to survive restarts.
6. Get A Structured Result
Userun() when your app needs more than final text.
chat() for user-facing responses. Use run() when your application logic needs the metadata.
7. Build A Live Turn
Useturn() for CLIs, web UIs, SSE streams, and controllable runtimes.
What To Read Next
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.