calute.cortex.agents.universal_agent#
Universal Agent for Cortex framework.
This module provides the UniversalAgent class, a versatile agent that can handle any type of task with comprehensive real tools. It extends CortexAgent with pre-configured tools for web research, file operations, git operations, code analysis, and Python execution.
The module also provides UniversalTaskCreator for creating and assigning tasks using the universal agent as a fallback for unassigned tasks.
Key features: - Web searching and research via DuckDuckGo - File operations (read, write, copy, move, delete) - Git operations (status, diff, log, add, apply patches) - Code analysis and manipulation - Python code execution - Diff creation and application
- Typical usage example:
- agent = UniversalAgent(
llm=my_llm, verbose=True, allow_delegation=True
) result = agent.execute(“Analyze the project structure”)
# Or using the task creator task_creator = UniversalTaskCreator(llm=my_llm) task_plan, tasks = task_creator.create_and_assign_tasks(
prompt=”Build a REST API”, specialized_agents=[api_expert_agent]
)
- class calute.cortex.agents.universal_agent.UniversalAgent(llm=None, verbose: bool = True, allow_delegation: bool = True, temperature: float = 0.7, max_tokens: int = 4096, additional_tools: list[Any] | None = None)[source]#
Bases:
CortexAgentVersatile agent that can handle any type of task with comprehensive tools.
UniversalAgent extends CortexAgent with a pre-configured set of real, functional tools enabling it to perform a wide variety of tasks including web research, file operations, git management, code analysis, and Python code execution. It serves as an all-purpose agent suitable for general tasks or as a fallback when specialized agents are not available.
The agent comes pre-configured with: - DuckDuckGoSearch: Web searching and information gathering - WriteFile: File writing capabilities - read_file: Read files with line numbers and range selection - list_directory: Directory listing with filtering options - copy_file, move_file, delete_file: File management operations - git_status, git_diff, git_log, git_add, git_apply_patch: Git operations - create_diff, apply_diff: Diff creation and application - find_and_replace: Text replacement with regex support - analyze_code_structure: Code structure analysis - ExecutePythonCode: Python code execution
- capabilities#
List of string descriptions of the agent’s capabilities.
Example
- agent = UniversalAgent(
llm=llm_instance, verbose=True, additional_tools=[my_custom_tool]
) result = agent.execute(“Search for information about Python”)
- describe_capabilities() str[source]#
Get a formatted description of the agent’s capabilities.
Generates a human-readable, formatted string describing all capabilities of the universal agent, including a bulleted list of capabilities and the total number of available tools.
- Returns
Formatted multi-line string containing the agent’s capabilities as a bulleted list, followed by the total tool count.
Example
>>> agent = UniversalAgent() >>> print(agent.describe_capabilities()) Universal Agent Capabilities:
Web research and information gathering
Advanced file operations (read, write, copy, move, delete)
…
Total Tools Available: 16
- class calute.cortex.agents.universal_agent.UniversalTaskCreator(llm=None, verbose: bool = True, temperature: float = 0.7, max_tokens: int = 4096)[source]#
Bases:
objectTask creator that uses UniversalAgent as default for unassigned tasks.
UniversalTaskCreator wraps a TaskCreator and UniversalAgent to provide automatic task creation and assignment. When specialized agents are provided, it attempts to match tasks to appropriate agents based on role similarity. Tasks that cannot be matched to a specialized agent are automatically assigned to the built-in UniversalAgent.
This class simplifies the process of creating and executing multi-step task plans by handling agent assignment automatically.
- task_creator#
Internal TaskCreator instance for generating task plans.
- universal_agent#
UniversalAgent instance used for unassigned tasks.
- llm#
LLM instance used by both the task creator and universal agent.
- verbose#
Whether to output detailed logs.
Example
creator = UniversalTaskCreator(llm=my_llm, verbose=True) task_plan, cortex_tasks = creator.create_and_assign_tasks(
prompt=”Build a user authentication system”, specialized_agents=[security_agent, database_agent]
) # Tasks related to security go to security_agent # Tasks related to database go to database_agent # All other tasks go to universal_agent
- create_and_assign_tasks(prompt: str, background: str | None = None, specialized_agents: list[calute.cortex.agents.agent.CortexAgent] | None = None) tuple[source]#
Create tasks and assign them, using universal agent for unassigned tasks.
Generates a task plan from the given prompt and assigns each task to an appropriate agent. Tasks are matched to specialized agents based on role name similarity (case-insensitive substring matching). Any tasks that cannot be matched to a specialized agent are assigned to the built-in UniversalAgent.
- Parameters
prompt – The objective or goal to create tasks for. This is passed to the task creator to generate a structured task plan.
background – Optional background information or context to help guide task creation and provide additional constraints.
specialized_agents – Optional list of CortexAgent instances with specific roles. Tasks will be matched to these agents based on role name similarity before falling back to universal agent.
- Returns
task_plan: The original TaskPlan generated by the task creator
cortex_tasks: List of CortexTask instances with agents assigned
If the task creator returns a tuple directly, that tuple is returned as-is.
- Return type
Tuple containing (task_plan, cortex_tasks) where
Example
- task_plan, tasks = creator.create_and_assign_tasks(
prompt=”Create a web scraper”, background=”Should handle JavaScript-rendered pages”, specialized_agents=[browser_agent, data_agent]
)