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 configured 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 Builder
Agent.builder() returns an AgentBuilder that can configure the provider, model, instructions, tools, memory, knowledge, retrieval, middleware, hooks, execution configuration, and events.
Common builder methods include:
- Name
- Model
- Provider
- Instructions
- Temperature
- Maximum output tokens
- Maximum tool iterations
- Tools
- Memory
- Knowledge
- Retrievers
- Middleware
- Hooks
- Events
Model Configuration
Models are specified using a provider-qualified model name:model() method separates the provider name from the model name and resolves the provider through BindAI’s provider system.
Current provider integrations include:
- OpenAI
- Anthropic
- Google Gemini
- Groq
- Ollama
- OpenRouter
Provider Configuration
Providers can be configured explicitly withprovider():
ModelProvider can also be supplied:
Project-Based Provider Configuration
An agent can use project configuration instead of specifying provider settings directly in application code. For example, a project can define:build() loads the project runtime configuration and uses the configured provider, model, connection, and temperature.
The builder can also explicitly load project configuration with from_project():
from_project() loads project-defined tools and provider configuration.
This allows an agent definition to remain focused on application behavior while project-level configuration controls provider selection and other runtime settings.
Project-Scoped Provider Connections
A project can select a named provider connection instead of placing provider credentials directly in application code orbindai.toml.
For example:
- An explicitly supplied API key.
- The credential stored for the selected project connection.
- The provider’s environment variable.
Agent Configuration
Execution behavior can be configured independently from the agent’s identity and capabilities. For example:temperature()- configures model sampling behavior.max_tokens()- configures the maximum output token count.max_tool_iterations()- limits tool execution iterations.
Instructions
Instructions define the system-level behavior of an agent. For example:Running an Agent
Use therun() method as the primary application-level execution entry point.
run() creates the execution context and delegates to the agent’s conversational execution path.
The method accepts an optional output type:
Chat Execution
BindAI also provideschat() for conversational execution.
run() and chat() currently use the same execution path. run() is the primary application-facing entry point, while chat() makes the conversational nature of the operation explicit.
Structured output can also be requested:
Lower-Level Execution
When an application already has anExecutionContext, it can execute the agent directly:
AgentResult
Agent execution returns anAgentResult.
Sending Prompts
The primary execution methods accept 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.
Both methods delegate streaming to the agent execution engine.
Streaming is useful for interactive applications that need to process model output progressively rather than waiting for the complete execution.
Adding Tools
Agents can execute registered tools. A tool can be attached directly to an agent:tools() for registering multiple tools during construction:
Tool objects as well as callable functions that can be converted into BindAI function tools.
add_tool() is available as a backwards-compatible alias for tool().
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. A typical architecture is:ToolRegistry.
Applications can also execute a registered tool directly:
ToolExecutedEvent through the agent event bus.
Memory
Agents have a memory component that is initialized with an in-memory provider by default. A different memory implementation can be attached to an agent:- In-memory state
- SQLite-backed memory
- PostgreSQL-backed memory
- Vector-based memory
- Pinecone-backed memory
- Chroma-backed memory
- Conversation-oriented memory
- Custom memory implementations
Conversation Context
Agents maintain aConversation component for conversational state.
Conversation context allows an application to work with multiple related messages rather than treating every execution as an isolated request.
This is useful for:
- Chat applications
- Assistants
- Multi-turn workflows
- Stateful agent execution
- Applications combining conversation history with longer-term memory
Agent Sessions
Agents providesession() for creating an AgentSession.
Agent object.
Knowledge
Agents can be connected to knowledge sources.- Document ingestion
- Parsing
- Chunking
- Embeddings
- Metadata
- Retrieval
- Reranking
- Conversational retrieval
- Knowledge pipelines
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.
The event bus can be supplied through the builder:
ToolExecutedEvent.
The event system is useful for:
- 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. The current agent configuration includes settings such as:- Temperature
- Maximum output tokens
- Maximum tool iterations
Execution Context
BindAI usesExecutionContext to carry information associated with an agent execution.
Execution context can provide runtime information required by components such as:
- Agents
- Tools
- Middleware
- Streaming
- Workflows
run() and chat() calls.
Agents can also execute directly from an existing context:
Agent Delegation
Agents can delegate work to other agents throughdelegate_to().
Agent Teams
BindAI also providesAgentTeam for coordinating a collection of existing agents.
A team can register agents directly:
AgentTeam is a lightweight coordination abstraction around existing agents.
It is distinct from the task-oriented Agent Group system provided by bindai-group.
Agent Groups
BindAI also provides an Agent Group abstraction for coordinating multiple agents around explicit tasks. Agent Groups are useful when the application needs task-oriented multi-agent execution rather than simply running a collection of agents. 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.
AgentTeam solve different coordination problems:
AgentTeamcoordinates an existing collection of agents.- Agent Groups represent explicit tasks assigned to agents.
SequentialProcessandParallelProcesscontrol group task execution.- Task context can connect dependent tasks.
Sequential Agent Groups
The default group process is sequential execution.Parallel Agent Groups
Independent Agent Group tasks can be executed concurrently usingParallelProcess.
Analysis depends on Research and therefore cannot begin until its dependency has completed.
If multiple tasks have no unresolved dependencies, they can execute concurrently:
Handoffs
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 should continue the execution. A typical pattern is:AgentTeam or Agent Groups depending on the required coordination model.
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
Team Delegation
Multiple agents can participate in team-oriented execution. A team can divide a larger task between agents with different responsibilities. For example:delegate_to() lets one agent invoke another agent as a tool.
AgentTeam provides direct coordination of a collection of existing agents.
Agent Groups provide explicit task-oriented orchestration.
These mechanisms can therefore be selected according to the application’s coordination requirements.
Specialist Role Chains
Specialists can also be organized into role-oriented execution chains. For example:AgentTeam.run_chain() or sequential Agent Group tasks.
Each stage can receive the output required from the previous stage.
This pattern is useful when an application needs predictable specialization rather than entirely dynamic delegation.
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
AgentBuilder.
Agents and External Integrations
Agents can work with external services through BindAI connections and tools. Connections provide application-level access to external services, while tools can expose that functionality to an agent when appropriate. This makes it possible to build agents that interact with external systems without embedding provider-specific integration logic directly into the agent. Project-scoped provider connections are a separate concept from external service connections. Provider connections select credentials for AI model providers, while external service connections represent integrations with application services.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 MCP integration can provide capabilities such as:- MCP client connections
- Tool discovery
- Tool calling
- MCP tools exposed as BindAI tools
- 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 should 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
AgentTeamwhen a collection of existing agents should be coordinated directly. - Use Agent Groups when multi-agent work should be represented as explicit tasks.
- Use
SequentialProcesswhen group task order or dependencies require sequential execution. - Use
ParallelProcesswhen independent group tasks can safely execute concurrently. - Use task context when one group 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.
- Use project configuration when provider and model settings should be managed outside application code.
- Use project-scoped provider connections when credentials should remain in the operating system credential store.
