Overview
Concrete tool for creating, registering, and managing Agent lifecycle within workflows, including thread-safe state tracking and instantiation from workflow graphs.
Description
The AgentManager class is a Pydantic BaseModule that holds all `Agent` instances needed by a workflow. It provides thread-safe agent state management (`AVAILABLE` / `RUNNING`), duplicate detection, agent creation from dicts or strings, and batch instantiation from `WorkFlowGraph` nodes via `add_agents_from_workflow`. Agents are keyed by unique name; the manager enforces name uniqueness at initialization and on every `add_agent` call.
Usage
- Auto-generated workflows: Call `add_agents_from_workflow(graph, llm_config, tools)` to instantiate one agent per graph node.
- Manual agent management: Use `add_agent(agent_dict, llm_config)` or `add_agent(agent_instance)` for custom setups.
- Concurrency control: `wait_for_agent_available()` blocks until an agent's state returns to `AVAILABLE`, enabling safe multi-threaded execution.
- HITL workflows: Used to store interceptor agents alongside regular agents.
Code Reference
Source Location
- Repository: EvoAgentX
- File: evoagentx/agents/agent_manager.py (L20-390)
Signature
class AgentManager(BaseModule):
agents: List[Agent] = []
agent_states: Dict[str, AgentState] = {}
storage_handler: Optional[StorageHandler] = None
def add_agent(self, agent: Union[str, dict, Agent], llm_config: Optional[LLMConfig] = None, tools: Optional[List[Union[Tool, Toolkit]]] = None, **kwargs)
def add_agents(self, agents: List[Union[str, dict, Agent]], llm_config: Optional[LLMConfig] = None, tools: Optional[List[Union[Tool, Toolkit]]] = None, **kwargs)
def add_agents_from_workflow(self, workflow_graph: WorkFlowGraph, llm_config: Optional[LLMConfig] = None, tools: Optional[List[Union[Tool, Toolkit]]] = None, **kwargs)
def get_agent(self, agent_name: str, **kwargs) -> Agent
def has_agent(self, agent_name: str) -> bool
def remove_agent(self, agent_name: str, remove_from_storage: bool = False, **kwargs)
def wait_for_agent_available(self, agent_name: str, timeout: Optional[float] = None) -> bool
def set_agent_state(self, agent_name: str, new_state: AgentState) -> bool
def update_agents_from_workflow(self, workflow_graph: WorkFlowGraph, llm_config: Optional[LLMConfig] = None, tools: Optional[List[Union[Tool, Toolkit]]] = None, **kwargs)
Import
from evoagentx.agents.agent_manager import AgentManager, AgentState
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| agents |
List[Agent] |
No |
Initial agents list
|
| storage_handler |
StorageHandler |
No |
For load/save from persistent storage
|
| workflow_graph |
WorkFlowGraph |
Yes (for add_agents_from_workflow) |
Graph with agent specs per node
|
| llm_config |
LLMConfig |
No |
Shared LLM config for created agents
|
| tools |
Toolkit] |
No |
Tools to resolve `tool_names` in agent configs
|
Outputs
| Name |
Type |
Description
|
| get_agent returns |
Agent |
Agent instance by name
|
| list_agents returns |
List[str] |
All agent names
|
Usage Examples
Instantiate Agents from Generated Workflow
from evoagentx.agents.agent_manager import AgentManager
from evoagentx.models.model_configs import OpenRouterConfig
from evoagentx.tools.file_tool import FileToolkit
# graph was generated by WorkFlowGenerator
llm_config = OpenRouterConfig(model="anthropic/claude-3.5-sonnet", openrouter_key="sk-or-...")
agent_manager = AgentManager()
agent_manager.add_agents_from_workflow(
workflow_graph=graph,
llm_config=llm_config,
tools=[FileToolkit()],
)
print("Agents:", agent_manager.list_agents())
Manual Agent Addition
from evoagentx.agents.agent_manager import AgentManager
from evoagentx.agents.customize_agent import CustomizeAgent
agent_manager = AgentManager()
agent_manager.add_agent(agent={
"name": "Summarizer",
"description": "Summarizes text",
"prompt": "Summarize: {text}",
"inputs": [{"name": "text", "type": "str", "description": "Input"}],
"outputs": [{"name": "summary", "type": "str", "description": "Summary"}],
"parse_mode": "title",
}, llm_config=llm_config)
Related Pages
Implements Principle
Requires Environment