Skip to main content
ai-query has three layers. Most confusion disappears once you know which layer you are using.

The Three Layers

Core Generation

Core generation is the raw model loop.
Use this for scripts, background jobs, extraction, summarization, and anywhere you do not need durable conversation state.

Stateful Agents

Agents add identity and memory.
Use agents when your app has users, sessions, persistent history, tools, or server routes.

Live Turns

A turn is one live execution of an agent.
Use turns when you need events, cancellation, steering, or a custom runtime around the agent.

Tools

Tools are typed Python functions the model can call.
Tools work with both core generation and agents.

Storage

Storage belongs to agents, not core generation.
Storage persists state, messages, and optionally events.

Events

There are two event concepts:
  • agent.emit(...) is for application events sent to clients and optionally replayed later.
  • turn.events() is a live execution stream for text, steps, reasoning, completion, and failure.
Example of an ephemeral UI command that should not replay:

Choosing Correctly

Use the smallest primitive that gives you what you need.