Base¶
base
¶
AgentLifecycleProtocol
¶
AgentControlProtocol
¶
Agent
¶
Bases: ABC, AgentLifecycleProtocol, AgentControlProtocol
Enhanced base class for AI agents with comprehensive lifecycle and control management.
This base class provides: - Unified context management - Lifecycle protocols (initialize, run, close) - Control protocols (pause, resume, stop, terminate) - Event system integration - Tool management - Metrics and logging - Extensible architecture for future enhancements
Initializes the Agent with a pre-configured AgentContext.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
AgentContext
|
The AgentContext instance holding configuration, state, and managers. |
required |
Source code in reactive_agents/app/agents/base.py
initialize
async
¶
Initialize the agent and its components.
This method should be called before using the agent. Subclasses can override this to add custom initialization logic.
Source code in reactive_agents/app/agents/base.py
close
async
¶
Close the agent and clean up resources.
This method should be called when done with the agent.
Source code in reactive_agents/app/agents/base.py
pause
async
¶
Pause the agent execution. Override in subclasses for specific behavior.
Source code in reactive_agents/app/agents/base.py
resume
async
¶
Resume the agent execution. Override in subclasses for specific behavior.
Source code in reactive_agents/app/agents/base.py
stop
async
¶
Stop the agent execution. Override in subclasses for specific behavior.
Source code in reactive_agents/app/agents/base.py
terminate
async
¶
Terminate the agent execution. Override in subclasses for specific behavior.
Source code in reactive_agents/app/agents/base.py
run
async
¶
Run the agent with a task.
This is the main entry point for agent execution. Subclasses should implement _execute_task for specific behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_task
|
str
|
The task to execute |
required |
**kwargs
|
Additional parameters for execution |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Execution results with comprehensive metrics |
Source code in reactive_agents/app/agents/base.py
extract_json_from_string
¶
Try to extract and parse the first valid JSON object or array from a string. Returns the parsed object (dict/list) or {} if not found/invalid.