Agents
Purpose and Scope
This document covers the Agent Management System in Automatos AI, including agent creation, configuration, lifecycle management, and capability assignment. Agents are the core AI entities that execute tasks, coordinate workflows, and interact with external tools.
For information about agent execution and orchestration, see Universal Router. For agent-to-agent coordination patterns, see Agent Coordination. For workflow recipe execution using agents, see Workflows & Recipes.
Agent Entity Model
Agents are represented by the Agent SQLAlchemy model with the following core structure:
id
Integer
Primary key
name
String
Unique agent name within workspace
description
Text
Agent purpose and capabilities
agent_type
String
Database type (e.g., code_architect, custom)
marketplace_category
String
UI category name (e.g., DevOps, Custom)
status
String
active, inactive, maintenance
configuration
JSONB
Priority, concurrency, resource limits
tags
ARRAY
Searchable keywords
model_config
JSONB
LLM provider, model, parameters
model_usage_stats
JSONB
Token counts, costs, request metrics
performance_metrics
JSONB
Success rate, tasks completed
workspace_id
UUID
Multi-tenant isolation
created_by
String
Creator identifier
created_at
Timestamp
Creation time
updated_at
Timestamp
Last modification time
Agent Data Model with Relationships
Diagram: Agent Database Schema with SQLAlchemy Models
Sources:
Agent Types and Categories
Agents use a dual-type system for flexibility:
Database Types (agent_type)
agent_type)Backend database values stored in the agent_type column:
code_architect- Software architecture and designsecurity_expert- Security analysis and auditsperformance_optimizer- Performance tuningdata_analyst- Data processing and insightsinfrastructure_manager- Deployment and infrastructurecustom- User-defined agentssystem- System-level operationsspecialized- Domain-specific expertise
UI Categories (marketplace_category)
marketplace_category)User-facing categories displayed in the frontend:
Personal AssistantCustomer SupportDevOpsSocial MediaAccountingE-commerceContent CreationHRData AnalysisCustom
Mapping Logic: The frontend uses CATEGORY_TO_DB_MAP and DB_TO_CATEGORY_MAP to translate between UI categories and database types. This allows specialized database types (e.g., security_expert) to preserve their identity while displaying as a generic UI category (e.g., Custom).
Sources:
Agent Creation
Create Agent Modal Workflow
Diagram: Agent Creation Flow with API Endpoints
Sources:
Agent Creation API
Endpoint: POST /api/agents
Request Payload:
Response:
Backend Flow:
Name Uniqueness Check - orchestrator/api/agents.py:369-372
Tag Normalization - orchestrator/api/agents.py:374 uses
_normalize_tags()Agent Creation - orchestrator/api/agents.py:377-388
Skill Assignment (if provided) - orchestrator/api/agents.py:392-401
Tool Assignment - orchestrator/api/agents.py:408-421 via
AgentAppAssignment
Sources:
Agent Configuration
The AgentConfigurationModal provides a comprehensive configuration interface with seven tabs:
Configuration Tabs Structure
Diagram: AgentConfigurationModal Component Hierarchy
Sources:
General Configuration
Basic agent properties and operational settings:
priority_level
Enum
low, medium, high, critical
max_concurrent_tasks
Integer
Max parallel task execution (1-10)
auto_start
Boolean
Start agent automatically on system boot
retry_attempts
Integer
Failed task retry count (0-5)
timeout_seconds
Integer
Task timeout in seconds (60-3600)
Resource Limits:
Environment & Logging:
environment:development,staging,productionlogging_level:debug,info,warning,errorperformance_monitoring: Boolean
Sources:
Model Configuration (PRD-15)
LLM provider and parameter settings stored in Agent.model_config JSONB field:
ModelSelector Component:
The ModelSelector component filters available models by provider and displays model metadata (cost, context window, capabilities).
Update Endpoint: PUT /api/models/agents/{agent_id}/config
Sources:
Heartbeat Configuration (PRD-55)
Autonomous agent check-ins for proactive monitoring:
Endpoints:
GET /api/heartbeat/agents/{agent_id}/config- Fetch configPUT /api/heartbeat/agents/{agent_id}/config- Update configPOST /api/heartbeat/agents/{agent_id}/run- Trigger manual heartbeatGET /api/heartbeat/agents/{agent_id}/last- Last result
Sources:
Agent Personas (US-021)
Personas define agent identity, voice, and behavior through system prompts.
Persona Modes
Persona API
Fetch Agent Persona: GET /api/agents/{agent_id}/persona
Response:
Update Persona: PUT /api/agents/{agent_id}/persona
Request (Predefined):
Request (Custom):
Persona Library
Personas are stored in the system_prompts table (reusing the prompt management infrastructure) and filtered by category to match agent types.
Category Filtering: When creating a DevOps agent, only personas with category = 'devops' are shown. Custom agents see all personas.
Pre-fill Behavior: Switching from "Predefined" to "Custom" mode pre-fills the textarea with the selected persona's system prompt for easy editing.
Sources:
Capability Assignment
Agents gain functionality through three mechanisms: Skills, Plugins, and Tools.
Assignment Architecture
Skills Assignment
Add Skill: POST /api/agents/{agent_id}/skills
Request:
Skills are stored in a many-to-many relationship via the agent_skills join table. At runtime, the SkillLoader fetches skill content progressively (metadata → core → resources) to optimize token usage.
Sources:
Plugins Assignment
Fetch Workspace Plugins: GET /api/workspaces/{workspace_id}/plugins
Fetch Agent Plugins: GET /api/agents/{agent_id}/plugins
Update Assignment: PUT /api/agents/{agent_id}/plugins
Request:
Three-Tier Enablement:
Global Approval - Admin approves plugin in marketplace (
marketplace_plugins.status = 'published')Workspace Enable - Workspace admin enables plugin (
workspace_pluginsentry)Agent Assignment - Agent assigned specific plugins (
agent_assigned_pluginsentry)
Only workspace-enabled plugins appear in the agent configuration UI. Plugin content is cached in Redis with 1-hour TTL.
Token Estimation: The UI displays total token estimate for assigned plugins:
Sources:
Tools Assignment
Tools are Composio integrations (Slack, GitHub, Gmail, etc.). Only connected tools are assignable to agents.
Tool Resolution Logic:
Stable Tool ID: Frontend uses stableId() hash function to generate negative IDs for apps without database cache entries. Backend matches these hashes via _stable_tool_id().
Update Tools: PUT /api/agents/{agent_id}
Request:
Backend converts IDs to app names, then inserts/updates AgentAppAssignment rows:
Sources:
Agent Lifecycle & Status
Status States
active
Agent running, accepting tasks
CheckCircle
Success green
inactive
Agent stopped, no task execution
Clock
Muted gray
maintenance
Agent undergoing updates/repairs
Settings
Warning yellow
paused
Agent paused, tasks queued
Pause
Primary blue
Status Control Flow
Impact Analysis
When changing agent status, the system analyzes:
Active Workflows - Workflows currently using the agent
Queued Tasks - Tasks waiting for the agent
Dependent Agents - Other agents that depend on this agent
System Impact - Performance degradation estimate
Shutdown Options:
Immediate - Stop agent immediately (may interrupt tasks)
Graceful - Finish current tasks before stopping
Scheduled - Schedule shutdown after workflow completion
Required Confirmations:
Acknowledge active workflows will be affected
Confirm backup/recovery plan in place
Confirm dependent systems have been notified
Sources:
Agent Runtime Architecture
Agents are instantiated through the AgentFactory class, which creates AgentRuntime instances with complete execution context.
Agent Factory Initialization
The AgentFactory class (orchestrator/modules/agents/factory/agent_factory.py) manages agent lifecycle:
Key Methods:
activate_agent(agent_id, use_system_llm=False)- Creates runtime instance_build_tools_prompt(required_tools)- Generates tool usage instructions_build_skill_tool_schemas(agent_skills)- Extracts skill tools_ensure_llm_provider()- Lazy LLM initialization
AgentRuntime Dataclass
The AgentRuntime dataclass represents an active agent instance:
Runtime Assembly Process
Diagram: Agent Activation Flow with Code Entities
Sources:
Tool Schema Generation
Agents receive tool schemas through two mechanisms:
1. Skill-Based Tools (_build_skill_tool_schemas)
Extracts executable tools from assigned skills' tools_schema JSONB field:
2. Composio Integration Tools
Via ComposioToolService.get_tools_for_step():
Strategy A (Primary): SDK semantic search for relevant actions
Strategy B (Fallback): Hint-based mega-tool with
composio_executefunction
Sources:
System Prompt Assembly in Chat Service
The StreamingChatService.stream_response_with_agent() method assembles the final context:
Diagram: System Prompt Construction Pipeline
Prompt Assembly Sequence:
Base System Prompt - From
SmartChatIntegration.prepare()Agent Identity - Name, description, agent_type
Persona - Custom or predefined system prompt
Skill Summaries - Brief descriptions from
agent.agent_skillsPlugin Content - From
PluginContentCache(if assigned)Tool Definitions - OpenAI function calling schemas
Execution Policy - Multi-step task handling instructions
Composio Scope - Available app names for direct action calls
Memory Context - Retrieved from Mem0
Special Case: CTO Agent Prompt Override (PRD-67)
For agents with slug='auto-cto':
Sources:
Tool Execution Pipeline
Diagram: Tool Call Execution Flow with Code Classes
ToolExecutionTracker Deduplication:
The ToolExecutionTracker class prevents infinite loops through:
Exact Matching - Hash of
(tool_name, args_hash)Semantic Similarity - For search tools, compares query strings with 75% threshold
Retry Limits - Per-tool execution limits (e.g.,
composio_execute: 2,read_file: 3)
Sources:
Agent Analytics & Usage Tracking (PRD-54)
Every agent execution generates usage records for cost tracking and optimization.
Usage Tracking Flow
Usage Record Schema
Agent Usage Statistics
Aggregated statistics stored in Agent.model_usage_stats JSONB:
Zero-Impact Design: The UsageTracker uses a separate database session (SessionLocal()) to ensure tracking failures never break agent execution.
Sources:
Agent API Reference
Core Endpoints
GET
/api/agents
List agents (filtered by workspace)
GET
/api/agents/{agent_id}
Get single agent with relationships
POST
/api/agents
Create new agent
PUT
/api/agents/{agent_id}
Update agent configuration
DELETE
/api/agents/{agent_id}
Delete agent and relationships
GET
/api/agents/types
List available agent types
GET
/api/agents/stats
Workspace-wide agent statistics
Status & Execution
GET
/api/agents/{agent_id}/status
Current status and workload
POST
/api/agents/{agent_id}/execute
Trigger agent execution
POST
/api/agents/bulk
Bulk agent creation
Relationships
GET
/api/agents/{agent_id}/skills
List agent skills
POST
/api/agents/{agent_id}/skills
Add skills to agent
GET
/api/agents/{agent_id}/plugins
List assigned plugins
PUT
/api/agents/{agent_id}/plugins
Update plugin assignments
GET
/api/agents/{agent_id}/persona
Get agent persona
PUT
/api/agents/{agent_id}/persona
Update persona
Query Parameters
List Agents (GET /api/agents):
skip
Integer
Pagination offset (default: 0)
limit
Integer
Page size (default: 100, max: 1000)
status
Enum
Filter by status (active, inactive, maintenance)
agent_type
Enum
Filter by type (code_architect, custom, etc.)
priority_level
Enum
Filter by priority (low, medium, high, critical)
search
String
Search in name or description
Response Format:
All endpoints return workspace-filtered results. The workspace_id is extracted from the JWT token or X-Workspace-ID header.
Sources:
Frontend Components
Component Hierarchy
React Query Hooks
All API interactions use React Query for caching and state management:
Cache Keys: All queries use workspace-scoped cache keys to prevent cross-workspace data leakage:
Invalidation Strategy: Mutations automatically invalidate related queries:
Sources:
Multi-Tenancy & Workspace Isolation
All agent operations are workspace-scoped via the workspace_id foreign key.
Workspace Context Flow
Workspace Resolution:
JWT Claims -
workspace_idextracted from Clerk JWTHeader Override -
X-Workspace-IDheader (validated against user permissions)Admin Override - Special
__all__sentinel for platform-wide queries
Query Filtering: All agent queries include workspace filter:
Admin Access: Admin users with X-Workspace-ID: __all__ header can query across all workspaces (e.g., for platform analytics).
Sources:
Last updated

