Skip to main content
This guide covers the three patterns you’ll use most: plain chat, tools, and streaming.

1. Plain chat (no tools)

agent.run() loops until the model stops calling tools and returns final text. For chat-only agents, pass an empty tools array.

2. Agent with a tool

Define a tool with defineTool, pass it to the agent, and ask a question that requires it:
kenpachi handles the full loop: model calls get_weather → your execute runs → result goes back to the model → model writes the final answer.

3. Stream text to your UI

Add onText to show tokens as they arrive:
See Streaming for the full event API (agent.stream()).

What’s next?

Handoffs

Delegate to billing, support, or other specialist agents.

Time-travel context

Undo, edit, or branch conversations without extra API cost.

Schema Validation & Coercion

Recover when the model sends bad tool arguments.

Agent API

Full reference for run(), stream(), and options.