π€ Agents¶
evoagentx.agents ¶
Agent ¶
Bases: BaseModule
Base class for all agents.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Unique identifier for the agent |
description |
str
|
Human-readable description of the agent's purpose |
llm_config |
Optional[LLMConfig]
|
Configuration for the language model. If provided, a new LLM instance will be created.
Otherwise, the existing LLM instance specified in the |
llm |
Optional[BaseLLM]
|
Language model instance. If provided, the existing LLM instance will be used. |
agent_id |
Optional[str]
|
Unique ID for the agent, auto-generated if not provided |
system_prompt |
Optional[str]
|
System prompt for the Agent. |
actions |
List[Action]
|
List of available actions |
n |
Optional[int]
|
Number of latest messages used to provide context for action execution. It uses all the messages in short term memory by default. |
is_human |
bool
|
Whether this agent represents a human user |
version |
int
|
Version number of the agent, default is 0. |
Source code in evoagentx/core/module.py
__call__ ¶
Make the operator callable and automatically choose between sync and async execution.
Source code in evoagentx/agents/agent.py
async_execute
async
¶
async_execute(action_name: str, msgs: Optional[List[Message]] = None, action_input_data: Optional[dict] = None, return_msg_type: Optional[MessageType] = UNKNOWN, return_action_input_data: Optional[bool] = False, **kwargs) -> Union[Message, Tuple[Message, dict]]
Execute an action asynchronously with the given context and return results.
This is the async version of the execute method, allowing it to perform actions based on the current conversation context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_name
|
str
|
The name of the action to execute |
required |
msgs
|
Optional[List[Message]]
|
Optional list of messages providing context for the action |
None
|
action_input_data
|
Optional[dict]
|
Optional pre-extracted input data for the action |
None
|
return_msg_type
|
Optional[MessageType]
|
Message type for the return message |
UNKNOWN
|
**kwargs
|
Any
|
Additional parameters, may include workflow information |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Message |
Union[Message, Tuple[Message, dict]]
|
A message containing the execution results |
Source code in evoagentx/agents/agent.py
execute ¶
execute(action_name: str, msgs: Optional[List[Message]] = None, action_input_data: Optional[dict] = None, return_msg_type: Optional[MessageType] = UNKNOWN, return_action_input_data: Optional[bool] = False, **kwargs) -> Union[Message, Tuple[Message, dict]]
Execute an action with the given context and return results.
This is the core method for agent functionality, allowing it to perform actions based on the current conversation context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_name
|
str
|
The name of the action to execute |
required |
msgs
|
Optional[List[Message]]
|
Optional list of messages providing context for the action |
None
|
action_input_data
|
Optional[dict]
|
Optional pre-extracted input data for the action |
None
|
return_msg_type
|
Optional[MessageType]
|
Message type for the return message |
UNKNOWN
|
**kwargs
|
Any
|
Additional parameters, may include workflow information |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Message |
Union[Message, Tuple[Message, dict]]
|
A message containing the execution results |
Source code in evoagentx/agents/agent.py
init_llm ¶
Initialize the language model for the agent.
Source code in evoagentx/agents/agent.py
init_long_term_memory ¶
Initialize long-term memory components.
Source code in evoagentx/agents/agent.py
add_action ¶
add_action(action: Type[Action])
Add a new action to the agent's available actions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action
|
Type[Action]
|
The action instance to add |
required |
Source code in evoagentx/agents/agent.py
check_action_name ¶
Check if an action name is valid for this agent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_name
|
str
|
Name of the action to check |
required |
Source code in evoagentx/agents/agent.py
get_action ¶
get_action(action_name: str) -> Action
Retrieves the Action instance associated with the given name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_name
|
str
|
Name of the action to retrieve |
required |
Returns:
Type | Description |
---|---|
Action
|
The Action instance with the specified name |
Source code in evoagentx/agents/agent.py
get_action_name ¶
get_action_name(action_cls: Type[Action]) -> str
Searches through the agent's actions to find one matching the specified type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_cls
|
Type[Action]
|
The Action class type to search for |
required |
Returns:
Type | Description |
---|---|
str
|
The name of the matching action |
Source code in evoagentx/agents/agent.py
get_action_inputs ¶
get_action_inputs(action: Action) -> Union[dict, None]
Uses the context extraction action to determine appropriate inputs for the specified action based on the conversation history.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action
|
Action
|
The action for which to extract inputs |
required |
Returns:
Type | Description |
---|---|
Union[dict, None]
|
Dictionary of extracted input data, or None if extraction fails |
Source code in evoagentx/agents/agent.py
get_all_actions ¶
get_all_actions() -> List[Action]
Get all actions except the context extraction action.
Returns:
Type | Description |
---|---|
List[Action]
|
List of Action instances available for execution |
Source code in evoagentx/agents/agent.py
get_agent_profile ¶
Generate a human-readable profile of the agent and its capabilities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_names
|
List[str]
|
Optional list of action names to include in the profile. If None, all actions are included. |
None
|
Returns:
Type | Description |
---|---|
str
|
A formatted string containing the agent profile |
Source code in evoagentx/agents/agent.py
get_prompts ¶
Get all the prompts of the agent.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary with keys in the format 'agent_name::action_name' and values containing the system_prompt and action prompt. |
Source code in evoagentx/agents/agent.py
set_prompt ¶
Set the prompt for a specific action of this agent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_name
|
str
|
Name of the action whose prompt should be updated |
required |
prompt
|
str
|
New prompt text to set for the action |
required |
system_prompt
|
Optional[str]
|
Optional new system prompt to set for the agent |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the prompt was successfully updated, False otherwise |
Raises:
Type | Description |
---|---|
KeyError
|
If the action_name does not exist for this agent |
Source code in evoagentx/agents/agent.py
set_prompts ¶
Set the prompts for all actions of this agent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
dict
|
A dictionary with keys in the format 'action_name' and values containing the system_prompt and action prompt. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the prompts were successfully updated, False otherwise |
Source code in evoagentx/agents/agent.py
save_module ¶
Save the agent to persistent storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
Path where the agent should be saved |
required |
ignore
|
List[str]
|
List of field names to exclude from serialization |
[]
|
**kwargs
|
Any
|
Additional parameters for the save operation |
{}
|
Returns:
Type | Description |
---|---|
str
|
The path where the agent was saved |
Source code in evoagentx/agents/agent.py
load_module
classmethod
¶
load_module(path: str, llm_config: LLMConfig = None, **kwargs) -> Agent
load the agent from local storage. Must provide llm_config
when loading the agent from local storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
The path of the file |
required |
llm_config
|
LLMConfig
|
The LLMConfig instance |
None
|
Returns:
Name | Type | Description |
---|---|---|
Agent |
Agent
|
The loaded agent instance |
Source code in evoagentx/agents/agent.py
CustomizeAgent ¶
CustomizeAgent(name: str, description: str, prompt: str, llm_config: Optional[LLMConfig] = None, inputs: Optional[List[dict]] = None, outputs: Optional[List[dict]] = None, system_prompt: Optional[str] = None, output_parser: Optional[Type[ActionOutput]] = None, parse_mode: Optional[str] = 'title', parse_func: Optional[Callable] = None, title_format: Optional[str] = None, **kwargs)
Bases: Agent
CustomizeAgent provides a flexible framework for creating specialized LLM-powered agents without writing custom code. It enables the creation of agents with well-defined inputs and outputs, custom prompt templates, and configurable parsing strategies.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the agent. |
description |
str
|
A description of the agent's purpose and capabilities. |
prompt |
str
|
The prompt template that will be used for the agent's primary action.
Should contain placeholders in the format |
llm_config |
LLMConfig
|
Configuration for the language model. |
inputs |
List[dict]
|
List of input specifications, where each dict (e.g., |
outputs |
List[dict]
|
List of output specifications, where each dict (e.g., |
system_prompt |
str
|
The system prompt for the LLM. Defaults to DEFAULT_SYSTEM_PROMPT. |
output_parser |
Type[ActionOutput]
|
A custom class for parsing the LLM's output. Must be a subclass of ActionOutput. |
parse_mode |
str
|
Mode for parsing LLM output. Options are: - "title": Parse outputs using section titles (default) - "str": Parse as plain text - "json": Parse as JSON - "xml": Parse as XML - "custom": Use a custom parsing function |
parse_func |
Callable
|
Custom function for parsing LLM output when parse_mode is "custom". Must accept a "content" parameter and return a dictionary. |
title_format |
str
|
Format string for title parsing mode with {title} placeholder. Default is "## {title}". |
Source code in evoagentx/agents/customize_agent.py
customize_action_name
property
¶
Get the name of the primary custom action for this agent.
Returns:
Type | Description |
---|---|
str
|
The name of the primary custom action |
action
property
¶
action: Action
Get the primary custom action for this agent.
Returns:
Type | Description |
---|---|
Action
|
The primary custom action |
prompt
property
¶
Get the prompt for the primary custom action.
Returns:
Type | Description |
---|---|
str
|
The prompt for the primary custom action |
create_customize_action ¶
create_customize_action(name: str, desc: str, prompt: str, inputs: List[dict], outputs: List[dict], parse_mode: str, parse_func: Optional[Callable] = None, output_parser: Optional[ActionOutput] = None, title_format: Optional[str] = '## {title}') -> Action
Create a custom action based on the provided specifications.
This method dynamically generates an Action class and instance with: - Input parameters defined by the inputs specification - Output format defined by the outputs specification - Custom execution logic using the customize_action_execute function
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Base name for the action |
required |
desc
|
str
|
Description of the action |
required |
prompt
|
str
|
Prompt template for the action |
required |
inputs
|
List[dict]
|
List of input field specifications |
required |
outputs
|
List[dict]
|
List of output field specifications |
required |
parse_mode
|
str
|
Mode to use for parsing LLM output |
required |
parse_func
|
Optional[Callable]
|
Optional custom parsing function |
None
|
output_parser
|
Optional[ActionOutput]
|
Optional custom output parser class |
None
|
Returns:
Type | Description |
---|---|
Action
|
A newly created Action instance |
Source code in evoagentx/agents/customize_agent.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
|
__call__ ¶
__call__(inputs: dict = None, return_msg_type: MessageType = UNKNOWN, **kwargs) -> Message
Call the customize action.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
dict
|
The inputs to the customize action. |
None
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
ActionOutput |
Message
|
The output of the customize action. |
Source code in evoagentx/agents/customize_agent.py
get_customize_agent_info ¶
Get the information of the customize agent.
Source code in evoagentx/agents/customize_agent.py
save_module ¶
Save the customize agent's configuration to a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
File path where the configuration should be saved |
required |
ignore
|
List[str]
|
List of keys to exclude from the saved configuration |
[]
|
**kwargs
|
Any
|
Additional parameters for the save operation |
{}
|
Returns:
Type | Description |
---|---|
str
|
The path where the configuration was saved |
Source code in evoagentx/agents/customize_agent.py
AgentManager ¶
Bases: BaseModule
Responsible for creating and managing all Agent objects required for workflow operation.
Attributes:
Name | Type | Description |
---|---|---|
storage_handler |
StorageHandler
|
Used to load and save agents from/to storage. |
agents |
List[Agent]
|
A list to keep track of all managed Agent instances. |
agent_states |
Dict[str, AgentState]
|
A dictionary to track the state of each Agent by name. |
Source code in evoagentx/core/module.py
check_agents ¶
Validate agent list integrity and state consistency.
Performs thorough validation of the agent manager's internal state: 1. Checks for duplicate agent names 2. Verifies that agent states exist for all agents 3. Ensures agent list and state dictionary sizes match
Source code in evoagentx/agents/agent_manager.py
has_agent ¶
Check if an agent with the given name exists in the manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_name
|
str
|
The name of the agent to check |
required |
Returns:
Type | Description |
---|---|
bool
|
True if an agent with the given name exists, False otherwise |
Source code in evoagentx/agents/agent_manager.py
load_agent ¶
load_agent(agent_name: str, **kwargs) -> Agent
Load an agent from local storage through storage_handler.
Retrieves agent data from storage and creates an Agent instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_name
|
str
|
The name of the agent to load |
required |
**kwargs
|
Any
|
Additional parameters for agent creation |
{}
|
Returns:
Type | Description |
---|---|
Agent
|
Agent instance with data loaded from storage |
Source code in evoagentx/agents/agent_manager.py
load_all_agents ¶
Load all agents from storage and add them to the manager.
Retrieves all available agents from storage and adds them to the managed agents collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Any
|
Additional parameters passed to storage handler |
{}
|
Source code in evoagentx/agents/agent_manager.py
create_customize_agent ¶
create_customize_agent(agent_data: dict, llm_config: Optional[Union[LLMConfig, dict]] = None, **kwargs) -> CustomizeAgent
create a customized agent from the provided agent_data
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_data
|
dict
|
The data used to create an Agent instance, must contain 'name', 'description' and 'prompt' keys. |
required |
llm_config
|
Optional[LLMConfig]
|
The LLM configuration to be used for the agent.
It will be used as the default LLM for agents without a |
None
|
**kwargs
|
Any
|
Additional parameters for agent creation |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Agent |
CustomizeAgent
|
the instantiated agent instance. |
Source code in evoagentx/agents/agent_manager.py
get_agent_name ¶
get_agent_name(agent: Union[str, dict, Agent]) -> str
Extract agent name from different agent representations.
Handles different ways to specify an agent (string name, dictionary, or Agent instance) and extracts the agent name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent
|
Union[str, dict, Agent]
|
Agent specified as a string name, dictionary with 'name' key, or Agent instance |
required |
Returns:
Type | Description |
---|---|
str
|
The extracted agent name as a string |
Source code in evoagentx/agents/agent_manager.py
add_agent ¶
add_agent(agent: Union[str, dict, Agent], llm_config: Optional[LLMConfig] = None, **kwargs)
add a single agent, ignore if the agent already exists (judged by the name of an agent).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent
|
Union[str, dict, Agent]
|
The agent to be added, specified as: - String: Agent name to load from storage - Dictionary: Agent specification to create a CustomizeAgent - Agent: Existing Agent instance to add directly |
required |
llm_config
|
Optional[LLMConfig]
|
The LLM configuration to be used for the agent. Only used when the |
None
|
**kwargs
|
Any
|
Additional parameters for agent creation |
{}
|
Source code in evoagentx/agents/agent_manager.py
add_agents ¶
add_agents(agents: List[Union[str, dict, Agent]], llm_config: Optional[LLMConfig] = None, **kwargs)
add several agents by using self.add_agent().
Source code in evoagentx/agents/agent_manager.py
add_agents_from_workflow ¶
Initialize agents from the nodes of a given WorkFlowGraph and add these agents to self.agents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
workflow_graph
|
WorkFlowGraph
|
The workflow graph containing nodes with agents information. |
required |
llm_config
|
Optional[LLMConfig]
|
The LLM configuration to be used for the agents. |
None
|
**kwargs
|
Any
|
Additional parameters passed to add_agent |
{}
|
Source code in evoagentx/agents/agent_manager.py
update_agents_from_workflow ¶
Update agents from a given WorkFlowGraph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
workflow_graph
|
WorkFlowGraph
|
The workflow graph containing nodes with agents information. |
required |
llm_config
|
Optional[LLMConfig]
|
The LLM configuration to be used for the agents. |
None
|
**kwargs
|
Additional parameters passed to update_agent |
{}
|
Source code in evoagentx/agents/agent_manager.py
get_agent ¶
get_agent(agent_name: str, **kwargs) -> Agent
Retrieve an agent by its name from managed agents.
Searches the list of managed agents for an agent with the specified name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_name
|
str
|
The name of the agent to retrieve |
required |
**kwargs
|
Any
|
Additional parameters (unused) |
{}
|
Returns:
Type | Description |
---|---|
Agent
|
The Agent instance with the specified name |
Source code in evoagentx/agents/agent_manager.py
update_agent ¶
update_agent(agent: Union[dict, Agent], llm_config: Optional[LLMConfig] = None, **kwargs)
Update an agent in the manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent
|
Union[dict, Agent]
|
The agent to be updated, specified as: - Dictionary: Agent specification to update a CustomizeAgent - Agent: Existing Agent instance to update |
required |
llm_config
|
Optional[LLMConfig]
|
The LLM configuration to be used for the agent. |
None
|
Source code in evoagentx/agents/agent_manager.py
remove_agent ¶
Remove an agent from the manager and optionally from storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_name
|
str
|
The name of the agent to remove |
required |
remove_from_storage
|
bool
|
If True, also remove the agent from storage |
False
|
**kwargs
|
Any
|
Additional parameters passed to storage_handler.remove_agent |
{}
|
Source code in evoagentx/agents/agent_manager.py
get_agent_state ¶
Get the state of a specific agent by its name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_name
|
str
|
The name of the agent. |
required |
Returns:
Name | Type | Description |
---|---|---|
AgentState |
AgentState
|
The current state of the agent. |
Source code in evoagentx/agents/agent_manager.py
set_agent_state ¶
Changes an agent's state and notifies any threads waiting on that agent's state. Thread-safe operation for coordinating multi-threaded agent execution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_name
|
str
|
The name of the agent |
required |
new_state
|
AgentState
|
The new state to set |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the state was updated successfully, False otherwise |
Source code in evoagentx/agents/agent_manager.py
get_all_agent_states ¶
Get the states of all managed agents.
Returns:
Type | Description |
---|---|
Dict[str, AgentState]
|
Dict[str, AgentState]: A dictionary mapping agent names to their states. |
save_all_agents ¶
Save all managed agents to persistent storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Any
|
Additional parameters passed to the storage handler |
{}
|
wait_for_agent_available ¶
Wait for an agent to be available.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_name
|
str
|
The name of the agent to wait for |
required |
timeout
|
Optional[float]
|
Maximum time to wait in seconds, or None to wait indefinitely |
None
|
Returns:
Type | Description |
---|---|
bool
|
True if the agent became available, False if timed out |