How Agents Work
The agent follows a loop: The loop continues until the model returns a text response with no tool calls, or the maximum iteration limit is reached.Creating an Agent
Key Concepts
Configuration
Control retries, iteration limits, tracing, knowledge, compression, and more through
AgentConfig.Running Agents
Four execution modes: sync, async, sync streaming, and async streaming.
Multi-Turn
Maintain conversation history across multiple interactions using session IDs and message lists.
Middleware
Wrap agent execution with logging, retries, metrics, and custom logic.
Tracing
Export structured events from every run for debugging and observability.
Testing
Test agents without API calls using
MockModel and AgentTestCase.Memory
Persistent multi-tier memory with automatic recall, distillation, and cross-session context.
Readers
Extract text from PDF, DOCX, XLSX, and audio files attached to agent messages.
Runtime
Deploy with HTTP endpoints, webhooks, cron jobs, and messaging interfaces via agent.serve().
Authentication
Secure HTTP endpoints with API key or JWT authentication.
Agent Properties
Once created, the agent exposes useful metadata:Adding Middleware
Chain middleware onto an agent with the fluent.use() method:
Deploying with serve()
Useagent.serve() to start the full agent runtime — messaging interfaces, HTTP endpoints, webhooks, and cron jobs: