Agents
Agents are the core building block of BindAI. An agent combines a language model provider with instructions and optional capabilities such as tools, memory, knowledge, retrieval, middleware, hooks, callbacks, execution configuration, delegation, and multi-agent coordination. Agents provide a consistent interface for executing AI tasks without requiring application code to manage provider-specific execution details.What Is an Agent?
A BindAI agent is responsible for:- Receiving user input
- Executing an AI model
- Applying configured instructions
- Calling registered tools
- Using optional memory
- Using optional knowledge or retrieval
- Managing conversation context
- Applying execution configuration
- Running middleware and lifecycle hooks
- Returning an
AgentResult
Agent class provides the primary execution interface.
Creating an Agent
The recommended way to create an agent is withAgent.builder().
Agent Configuration
Agents can be configured with several capabilities through the builder. Common configuration methods include:- Name
- Model
- Instructions
- Tools
- Memory
- Knowledge
- Retrievers
- Middleware
- Execution configuration
- Hooks and callbacks
Model Configuration
Models are specified using a provider-qualified model name.- OpenAI
- Anthropic
- Google Gemini
- Groq
- Ollama
- OpenRouter
Running an Agent
Use therun() method as the primary application-level execution entry point.
run() delegates to the agent’s conversational execution path and returns an AgentResult.
You can inspect the result:
ExecutionContext can be passed to agent.execute():
AgentResult
Agent execution returns anAgentResult.
Sending Prompts
The primary execution method accepts a message:Structured Output
BindAI supports structured output using a Python type. For example, a Pydantic model can define the expected result:run():
Streaming
Agents support streaming execution through two interfaces. For normal message-based streaming, usestream_chat():
ExecutionContext, use stream():
stream_chat() creates the execution context from the supplied message, while stream() operates on an existing execution context.
Chat Execution
BindAI provideschat() for conversational execution.
run() and chat() currently use the same conversational execution path.
Use run() as the general application-facing entry point and chat() when the conversational nature of the operation is important to the application.
Conversation state can be managed independently through BindAI’s conversation and memory capabilities.
Adding Tools
Agents can execute registered tools. A tool can be attached directly to an agent:add_tool() is also available as a backwards-compatible alias for tool().
Tool execution is handled through BindAI’s tool registry and execution system.
Tool Calling
When a configured model determines that a tool is required, BindAI can execute the registered tool and incorporate its result into the agent execution. This separates the model-facing tool definition from the application’s tool implementation. A typical architecture is:Memory
Memory is optional and can be attached to an agent.- In-memory memory
- SQLite memory
- PostgreSQL memory
- Vector memory
- Pinecone-backed memory
- Chroma-backed memory
- Conversation-oriented memory
- Custom memory implementations
Conversation Context
Agents can maintain conversational context through BindAI’s conversation support. Conversation state allows an application to work with multiple related messages rather than treating every execution as an isolated request. This is particularly useful for:- Chat applications
- Assistants
- Multi-turn workflows
- Stateful agent execution
- Applications combining conversation history with long-term memory
Knowledge
Agents can be connected to knowledge sources.Retrievers
A retriever can be attached directly to an agent:- Vector retrieval
- BM25 retrieval
- Hybrid retrieval
Retrieval-Augmented Generation
An agent can use retrieved knowledge as additional context during execution. A typical RAG flow is:Middleware
Middleware can be attached to an agent using:- Logging
- Authentication
- Telemetry
- Metrics
- Request processing
- Response processing
- Cross-cutting application behavior
Hooks and Callbacks
Agents expose lifecycle and callback mechanisms that allow applications to react to execution events. Agents provide callback registration throughon():
before_runafter_runerror
- Logging
- Auditing
- Monitoring
- Analytics
- Notifications
- Debugging
- Custom application behavior
Events
Agents expose an event bus throughagent.events.
Tool execution publishes framework events such as ToolExecutedEvent:
- Observability
- Logging
- Metrics
- Application events
- Debugging
- Notifications
- Automation integrations
Execution Configuration
Agent execution can be configured independently from the agent’s core identity and capabilities. Execution configuration can be used to control aspects of execution such as:- Tool execution behavior
- Maximum tool iterations
- Execution limits
- Timeout-related behavior
- Other runtime execution settings
Execution Context
BindAI uses execution context to carry information associated with an agent execution. Execution context can provide the runtime information required by execution components such as:- Agents
- Tools
- Middleware
- Streaming
- Workflows
Agent Delegation
Agents can delegate work to other agents throughdelegate_to().
Agent Handoff
BindAI can also be used to implement handoff patterns between specialized agents. A handoff allows responsibility for a task to move from one agent to another when another specialist is better suited to continue the execution. A typical pattern is:Specialist Agents
Specialist agents can be created around specific roles. Examples include:- Research agents
- Writing agents
- Coding agents
- Analysis agents
- Support agents
- Retrieval-focused agents
Agent Groups
BindAI provides an Agent Group abstraction for coordinating multiple agents around a collection of tasks. Agent Groups are useful when the application needs explicit task-oriented multi-agent execution rather than asking one agent to dynamically delegate every operation. The public group API is provided bybindai-group.
A basic group can be created with GroupBuilder:
Group- represents the agent group and its tasks.GroupBuilder- provides the fluent construction API.Task- describes work assigned to a specific agent.GroupResult- contains the overall group execution result.SequentialProcess- executes tasks sequentially.ParallelProcess- executes independent tasks concurrently.
Sequential Agent Groups
The default group process is sequential execution.Parallel Agents
Independent Agent Group tasks can be executed concurrently usingParallelProcess.
Analysis does not start until Research has completed successfully.
If multiple tasks have no unresolved dependencies, they can execute concurrently:
Team Delegation
Multiple agents can also participate in team-oriented execution. A team can divide a larger task between agents with different responsibilities. For example:delegate_to() and explicit Agent Groups solve related but different coordination problems:
delegate_to()lets an agent dynamically invoke another agent as a tool.- Agent Groups provide explicit tasks and process-based orchestration.
ParallelProcessallows independent group tasks to execute concurrently.- Task context allows dependent tasks to consume previous task results.
Specialist Role Chains
Specialists can also be organized into role-oriented execution chains. For example:RAG-Enabled Multi-Agent Systems
Knowledge and retrieval capabilities can be combined with delegation and specialist agents. For example:Agents in Workflows
Agents can be used as components within larger BindAI workflows. A workflow can coordinate agents with operations such as:- Conditions
- Loops
- Parallel execution
- Retries
- Timeouts
- Human tasks
- Scheduling
Agents in Projects
Agents can be organized as part of a BindAI project. A project can provide the surrounding application structure for:- Agents
- Tools
- Workflows
- Knowledge
- Memory
- Templates
- Tests
- Configuration
Agents and External Integrations
Agents can work with external services through BindAI connections. Current connection integrations include:- Webhooks
- GitHub
- Slack
- Notion
- Jira
- Discord
- Resend
- Vercel
- Netlify
Agents and MCP
BindAI also supports MCP connections and MCP-discovered tools. MCP integrations can provide agents with access to tools exposed by MCP-compatible services. The current MCP integration supports:- MCP client connections
- Tool discovery
- Tool calling
- MCP tools exposed as BindAI tools
- Basic connection handling
Building a Complete Agent
A more complete agent can combine several capabilities:Agent Architecture
A typical BindAI agent can be viewed as several layers:Best Practices
- Give each agent a clear responsibility.
- Keep instructions focused.
- Prefer reusable tools over increasingly complex prompts.
- Use memory for information that must persist beyond a single execution.
- Use knowledge and retrievers for external information.
- Use middleware for reusable cross-cutting behavior.
- Use hooks and callbacks for lifecycle behavior.
- Use the event system for event-driven application integration and observability.
- Use execution configuration for runtime behavior rather than embedding runtime concerns in prompts.
- Use specialist agents when responsibilities are clearly separated.
- Use
delegate_to()when an agent should dynamically invoke another specialist. - Use Agent Groups when multi-agent work should be represented as explicit tasks.
- Use
SequentialProcesswhen task order matters. - Use
ParallelProcesswhen independent tasks can safely execute concurrently. - Use task context when one task depends on the result of another.
- Use workflows when multiple agents or execution stages need explicit orchestration and control flow.
- Keep external integrations behind connections or tools.
- Use MCP when an external MCP service provides capabilities that should be exposed to the agent.
