Agent Module
Agent orchestration utilities for LLM applications.
This module provides comprehensive agent frameworks and execution patterns.
Import Structure:
## Top-level imports (most common):
`python
from kerb.agent import Agent, run_agent, AgentResult
from kerb.agent import Tool, create_tool
`
## Submodule imports (for organized access):
`python
from kerb.agent import patterns, tools, reasoning, memory, planning, teams, monitoring, execution
# Then: patterns.ReActAgent, tools.ToolRegistry, reasoning.Chain, execution.run_agent_loop
`
## Direct submodule access:
`python
from kerb.agent.patterns import ReActAgent, PlanAndExecuteAgent
from kerb.agent.tools import validate_tool_call, global_tool_registry
from kerb.agent.reasoning import Chain, SequentialChain, ParallelChain
from kerb.agent.memory import AgentMemory, WorkingMemory
from kerb.agent.planning import Planner, create_plan
from kerb.agent.teams import AgentTeam, delegate_task
from kerb.agent.monitoring import AgentTracer, evaluate_agent
from kerb.agent.execution import run_agent_loop, run_agent_async
`
Key Components:
Core: Agent, AgentResult, AgentStep, AgentState, AgentStatus
Execution: run_agent, run_agent_loop, run_agent_async, run_agent_stream, AgentExecutor
Patterns: ReActAgent, PlanAndExecuteAgent, ChainOfThoughtAgent, TreeOfThoughtAgent, ReflexAgent
Tools: Tool, ToolRegistry, create_tool, register_tool, execute_tool, global_tool_registry
Reasoning: Chain, SequentialChain, ParallelChain, ConditionalChain, LoopChain
Memory: AgentMemory, WorkingMemory, EpisodicMemory, save_agent_state, load_agent_state
Planning: Planner, Plan, create_plan, execute_plan, replan, validate_plan
Teams: AgentTeam, Conversation, delegate_task, aggregate_results
Monitoring: AgentTracer, evaluate_agent, benchmark_agent, compare_agents
- class kerb.agent.Agent(name='Agent', llm_func=None, tools=None, max_iterations=10, memory=None, verbose=False)[source]
Bases:
ABCBase class for all agents.
An agent perceives its environment, reasons about it, and takes actions to achieve its goals.
- __init__(name='Agent', llm_func=None, tools=None, max_iterations=10, memory=None, verbose=False)[source]
Initialize agent.
- Parameters:
name (
str) – Name of the agentllm_func (
Optional[Callable]) – Function to call LLM (should accept prompt and return response)tools (
Optional[List[Any]]) – List of tools available to the agentmax_iterations (
int) – Maximum number of iterationsmemory (
Optional[AgentMemory]) – Agent memory instanceverbose (
bool) – Whether to print execution details
- class kerb.agent.AgentResult(output, steps, status, total_time, metadata=<factory>)[source]
Bases:
objectResult from agent execution.
- output
Final output from the agent
- steps
List of execution steps
- status
Final status of execution
- total_time
Total execution time in seconds
- metadata
Additional result metadata
- status: AgentStatus
- __init__(output, steps, status, total_time, metadata=<factory>)
- class kerb.agent.Tool(name, description, func, parameters=<factory>, returns='', examples=<factory>)[source]
Bases:
objectRepresents a tool/function that an agent can use.
- name
Tool name
- description
What the tool does
- func
The actual function to execute
- parameters
Parameter descriptions
- returns
Return value description
- examples
Usage examples
- execute(*args, **kwargs)[source]
Execute the tool.
- Parameters:
*args – Positional arguments
**kwargs – Keyword arguments
- Return type:
ToolResult- Returns:
ToolResult with output or error
- async execute_async(*args, **kwargs)[source]
Execute tool asynchronously.
- Parameters:
*args – Positional arguments
**kwargs – Keyword arguments
- Return type:
ToolResult- Returns:
ToolResult
- __init__(name, description, func, parameters=<factory>, returns='', examples=<factory>)
- kerb.agent.create_tool(name, func, description='', parameters=None, returns='', examples=None, auto_parse=True)[source]
Create a tool from a function.
- Parameters:
- Return type:
- Returns:
Tool instance
Agent orchestration and execution patterns for multi-step reasoning.