Agents

chevron-rightRelevant source fileshashtag

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:

Field
Type
Description

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

spinner

Sources:


Agent Types and Categories

Agents use a dual-type system for flexibility:

Database Types (agent_type)

Backend database values stored in the agent_type column:

  • code_architect - Software architecture and design

  • security_expert - Security analysis and audits

  • performance_optimizer - Performance tuning

  • data_analyst - Data processing and insights

  • infrastructure_manager - Deployment and infrastructure

  • custom - User-defined agents

  • system - System-level operations

  • specialized - Domain-specific expertise

UI Categories (marketplace_category)

User-facing categories displayed in the frontend:

  • Personal Assistant

  • Customer Support

  • DevOps

  • Social Media

  • Accounting

  • E-commerce

  • Content Creation

  • HR

  • Data Analysis

  • Custom

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

spinner

Sources:

Agent Creation API

Endpoint: POST /api/agents

Request Payload:

Response:

Backend Flow:

  1. Name Uniqueness Check - orchestrator/api/agents.py:369-372

  2. Tag Normalization - orchestrator/api/agents.py:374 uses _normalize_tags()

  3. Skill Assignment (if provided) - orchestrator/api/agents.py:392-401

  4. 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

spinner

Sources:

General Configuration

Basic agent properties and operational settings:

Field
Type
Description

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, production

  • logging_level: debug, info, warning, error

  • performance_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 config

  • PUT /api/heartbeat/agents/{agent_id}/config - Update config

  • POST /api/heartbeat/agents/{agent_id}/run - Trigger manual heartbeat

  • GET /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

spinner

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

spinner

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:

  1. Global Approval - Admin approves plugin in marketplace (marketplace_plugins.status = 'published')

  2. Workspace Enable - Workspace admin enables plugin (workspace_plugins entry)

  3. Agent Assignment - Agent assigned specific plugins (agent_assigned_plugins entry)

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:

spinner

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

Status
Description
Icon
Color

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

spinner

Impact Analysis

When changing agent status, the system analyzes:

  1. Active Workflows - Workflows currently using the agent

  2. Queued Tasks - Tasks waiting for the agent

  3. Dependent Agents - Other agents that depend on this agent

  4. 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

spinner

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_execute function

Sources:

System Prompt Assembly in Chat Service

The StreamingChatService.stream_response_with_agent() method assembles the final context:

Diagram: System Prompt Construction Pipeline

spinner

Prompt Assembly Sequence:

  1. Base System Prompt - From SmartChatIntegration.prepare()

  2. Agent Identity - Name, description, agent_type

  3. Persona - Custom or predefined system prompt

  4. Skill Summaries - Brief descriptions from agent.agent_skills

  5. Plugin Content - From PluginContentCache (if assigned)

  6. Tool Definitions - OpenAI function calling schemas

  7. Execution Policy - Multi-step task handling instructions

  8. Composio Scope - Available app names for direct action calls

  9. 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

spinner

ToolExecutionTracker Deduplication:

The ToolExecutionTracker class prevents infinite loops through:

  1. Exact Matching - Hash of (tool_name, args_hash)

  2. Semantic Similarity - For search tools, compares query strings with 75% threshold

  3. 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

spinner

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

Method
Endpoint
Description

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

Method
Endpoint
Description

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

Method
Endpoint
Description

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):

Parameter
Type
Description

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

spinner

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

spinner

Workspace Resolution:

  1. JWT Claims - workspace_id extracted from Clerk JWT

  2. Header Override - X-Workspace-ID header (validated against user permissions)

  3. 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