π― Actions¶
evoagentx.actions ¶
Action ¶
Bases: BaseModule
Base class for all actions in the EvoAgentX framework.
Actions represent discrete operations that can be performed by agents. They define inputs, outputs, and execution behavior, and can optionally use tools to accomplish their tasks.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Unique identifier for the action. |
description |
str
|
Human-readable description of what the action does. |
prompt |
Optional[str]
|
Optional prompt template for this action. |
tools |
Optional[List[Tool]]
|
Optional list of tools that can be used by this action. |
inputs_format |
Optional[Type[ActionInput]]
|
Optional class defining the expected input structure. |
outputs_format |
Optional[Type[Parser]]
|
Optional class defining the expected output structure. |
Source code in evoagentx/core/module.py
init_module ¶
Initialize the action module.
This method is called after the action is instantiated. Subclasses can override this to perform custom initialization.
to_dict ¶
Convert the action to a dictionary for saving.
Source code in evoagentx/actions/action.py
execute ¶
execute(llm: Optional[BaseLLM] = None, inputs: Optional[dict] = None, sys_msg: Optional[str] = None, return_prompt: bool = False, **kwargs) -> Optional[Union[Parser, Tuple[Parser, str]]]
Execute the action to produce a result.
This is the main entry point for executing an action. Subclasses must implement this method to define the action's behavior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
llm
|
Optional[BaseLLM]
|
The LLM used to execute the action. |
None
|
inputs
|
Optional[dict]
|
Input data for the action execution. The input data should be a dictionary that matches the input format of the provided prompt.
For example, if the prompt contains a variable |
None
|
sys_msg
|
Optional[str]
|
Optional system message for the LLM. |
None
|
return_prompt
|
bool
|
Whether to return the complete prompt passed to the LLM. |
False
|
**kwargs
|
Any
|
Additional keyword arguments for the execution. |
{}
|
Returns:
Type | Description |
---|---|
Optional[Union[Parser, Tuple[Parser, str]]]
|
If |
Optional[Union[Parser, Tuple[Parser, str]]]
|
If |
Source code in evoagentx/actions/action.py
async_execute
async
¶
async_execute(llm: Optional[BaseLLM] = None, inputs: Optional[dict] = None, sys_msg: Optional[str] = None, return_prompt: bool = False, **kwargs) -> Optional[Union[Parser, Tuple[Parser, str]]]
Asynchronous execution of the action.
This method is the asynchronous counterpart of the execute
method.
It allows the action to be executed asynchronously using an LLM.
Source code in evoagentx/actions/action.py
ActionInput ¶
Bases: LLMOutputParser
Input specification and parsing for actions.
This class defines the input requirements for actions and provides methods to generate structured input specifications. It inherits from LLMOutputParser to allow parsing of LLM outputs into structured inputs for actions.
Notes
Parameters in ActionInput should be defined in Pydantic Field format.
For optional variables, use format:
var: Optional[int] = Field(default=None, description="xxx")
Remember to add default=None
for optional parameters.
Source code in evoagentx/core/module.py
get_input_specification
classmethod
¶
Generate a JSON specification of the input requirements.
Examines the class fields and produces a structured specification of the input parameters, including their types, descriptions, and whether they are required.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ignore_fields
|
List[str]
|
List of field names to exclude from the specification. |
[]
|
Returns:
Type | Description |
---|---|
str
|
A JSON string containing the input specification, or an empty string |
str
|
if no fields are defined or all are ignored. |
Source code in evoagentx/actions/action.py
get_required_input_names
classmethod
¶
Get a list of all required input parameter names.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: Names of all parameters that are required (don't have default values). |
Source code in evoagentx/actions/action.py
ActionOutput ¶
Bases: LLMOutputParser
Output representation for actions.
This class handles the structured output of actions, providing methods to convert the output to structured data. It inherits from LLMOutputParser to support parsing of LLM outputs into structured action results.
Source code in evoagentx/core/module.py
CodeExtraction ¶
Bases: Action
An action that extracts and organizes code blocks from text.
This action uses an LLM to analyze text containing code blocks, extract them, suggest appropriate filenames, and save them to a specified directory. It can also identify which file is likely the main entry point based on heuristics.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the action. |
description |
str
|
A description of what the action does. |
prompt |
Optional[str]
|
The prompt template used by the action. |
inputs_format |
Optional[Type[ActionInput]]
|
The expected format of inputs to this action. |
outputs_format |
Optional[Type[Parser]]
|
The format of the action's output. |
Source code in evoagentx/actions/code_extraction.py
identify_main_file ¶
Identify the main file from the saved files based on content and file type.
This method uses a combination of common filename conventions and content analysis to determine which file is likely the main entry point of a project.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
saved_files
|
Dict[str, str]
|
Dictionary mapping filenames to their full paths |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
Path to the main file if found, None otherwise |
Source code in evoagentx/actions/code_extraction.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
save_code_blocks ¶
Save code blocks to files in the target directory.
Creates the target directory if it doesn't exist and saves each code block to a file with an appropriate name, handling filename conflicts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_blocks
|
List[Dict]
|
List of dictionaries containing code block information |
required |
target_directory
|
str
|
Directory path where files should be saved |
required |
Returns:
Type | Description |
---|---|
Dict[str, str]
|
Dictionary mapping filenames to their full paths |
Source code in evoagentx/actions/code_extraction.py
execute ¶
execute(llm: Optional[BaseLLM] = None, inputs: Optional[dict] = None, sys_msg: Optional[str] = None, return_prompt: bool = False, **kwargs) -> CodeExtractionOutput
Execute the CodeExtraction action.
Extracts code blocks from the provided text using the specified LLM, saves them to the target directory, and identifies the main file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
llm
|
Optional[BaseLLM]
|
The LLM to use for code extraction |
None
|
inputs
|
Optional[dict]
|
Dictionary containing: - code_string: The string with code blocks to extract - target_directory: Where to save the files - project_name: Optional project folder name |
None
|
sys_msg
|
Optional[str]
|
Optional system message override for the LLM |
None
|
return_prompt
|
bool
|
Whether to return the prompt along with the result |
False
|
**kwargs
|
Any
|
Additional keyword arguments |
{}
|
Returns:
Type | Description |
---|---|
CodeExtractionOutput
|
CodeExtractionOutput with extracted file information |
Source code in evoagentx/actions/code_extraction.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
|