Agent API Reference

chevron-rightRelevant source fileshashtag

This page provides a complete API reference for agent management endpoints. It covers CRUD operations for agents, plugin assignment, persona configuration, and agent context assembly. For conceptual information about agents and their architecture, see Agents. For details on the agent runtime lifecycle, see Agent Factory & Runtime.


Overview

The Agent API provides REST endpoints for managing AI agents in the Automatos AI platform. All endpoints require authentication via Clerk JWT and workspace isolation via X-Workspace-ID header. The API is organized into three primary routers:

Router
Prefix
Purpose

agents_router

/api/agents

Core CRUD operations (create, read, update, delete agents)

agent_plugins_router

/api/agents/{agent_id}/plugins

Plugin assignment and context assembly

agent_endpoints_router

/api/agents

Additional agent operations (start, stop, logs, stats)

Sources: orchestrator/main.py:691-692, orchestrator/api/agent_plugins.py:1-338


Authentication & Headers

All agent endpoints require two headers:

Authorization: Bearer <clerk_jwt_token>
X-Workspace-ID: <workspace_uuid>

The API uses hybrid authentication via get_request_context_hybrid dependency, which validates both the JWT and workspace context. Rate limiting is enforced at 60 requests/minute per IP.

Sources: orchestrator/main.py:583-596, orchestrator/api/agent_plugins.py:22-23


Endpoint Architecture

spinner

Sources: orchestrator/main.py:555-596, orchestrator/api/agent_plugins.py:27-86


Core Agent CRUD Endpoints

List Agents

Returns all agents for the authenticated workspace.

Query Parameters:

  • status (optional): Filter by status (active, idle, failed)

  • type (optional): Filter by agent type

Response:

Sources: orchestrator/main.py:691

Get Agent by ID

Returns a single agent with full configuration details.

Path Parameters:

  • agent_id (integer): Agent ID

Validation:

  • Agent must exist

  • Agent's workspace_id must match authenticated workspace

Response: Same structure as list item, with additional fields:

  • custom_persona_prompt (if use_custom_persona is true)

  • skills (array of assigned skills)

  • patterns (array of assigned patterns)

Sources: orchestrator/api/agent_plugins.py:84-89

Create Agent

Creates a new agent in the authenticated workspace.

Request Body:

Required Fields:

  • name (string, max 255)

  • type (string)

Optional Fields:

  • description (string)

  • model_config (object)

  • persona_id (integer)

  • use_custom_persona (boolean)

  • custom_persona_prompt (string)

Response:

Sources: orchestrator/main.py:691

Update Agent

Updates an existing agent. Only the agent owner (workspace match) can update.

Request Body: Same as create, all fields optional

Response: Updated agent object

Sources: orchestrator/main.py:691

Delete Agent

Soft-deletes an agent by setting status to deleted.

Response:

Sources: orchestrator/main.py:691


Plugin Assignment Endpoints

List Agent Plugins

Returns all plugins assigned to an agent, with marketplace plugin details joined.

Response:

Sources: orchestrator/api/agent_plugins.py:69-125

Update Agent Plugins

Replaces all plugin assignments for an agent. Validates that all plugins are enabled for the workspace.

Request Body:

Validation:

  1. All plugin_ids must exist in marketplace_plugins

  2. All plugin_ids must be enabled in workspace_enabled_plugins for the agent's workspace

  3. Duplicates are automatically removed while preserving order

Response:

Database Operations:

  1. Deletes existing agent_assigned_plugins records for the agent

  2. Inserts new records with priority based on array order (0, 1, 2, ...)

Sources: orchestrator/api/agent_plugins.py:127-209


Assembled Context Endpoint

Get Assembled Context

Returns the fully assembled agent context including persona prompt, plugin skills, and tool definitions. This endpoint is called by AgentFactory at runtime to build the agent's system prompt.

Response:

Assembly Process:

spinner

Tier Structure:

Tier
Purpose
Source
Token Budget

Persona

Behavioral instructions

Persona.system_prompt or Agent.custom_persona_prompt

Variable (500-2000)

Tier 1

Plugin quick reference

PluginContextService.build_tier1_summary()

~50-200 per plugin

Tier 2

Full skill/command docs

PluginContextService.build_tier2_content()

~500-1500 per plugin

Sources: orchestrator/api/agent_plugins.py:211-338, orchestrator/core/services/plugin_context_service.py


Data Models

Agent Model

Located in core.models.core.Agent:

Sources: orchestrator/api/agent_plugins.py:84

Plugin Assignment Models

Located in core.models.marketplace_plugins:

Sources: orchestrator/api/agent_plugins.py:78-101


Request Flow Example

spinner

Sources: orchestrator/api/agent_plugins.py:127-338


Error Handling

All endpoints follow consistent error response format:

Common Error Codes

Code
Scenario
Example

400

Validation failure

Plugin not enabled for workspace

403

Permission denied

Workspace ID mismatch

404

Resource not found

Agent does not exist

422

Invalid request body

Missing required fields

500

Internal server error

Database connection failure

Validation Rules

Agent Updates:

  • Only agent owner (matching workspace_id) can update or delete

  • status transitions must be valid: activeidlefailed, deleted is terminal

Plugin Assignment:

  • All plugin_ids must exist in marketplace_plugins table

  • All plugin_ids must be enabled in workspace_enabled_plugins for the agent's workspace

  • Circular dependencies in plugin requirements are checked at enable time (not at assignment time)

Sources: orchestrator/api/agent_plugins.py:120-124, orchestrator/api/agent_plugins.py:145-178


Frontend Integration

The frontend uses ApiClient with automatic JWT injection:

Auto-Injected Headers:

  • Authorization: Bearer <token> from Clerk useAuth()

  • X-Workspace-ID from localStorage.getItem('last_active_workspace')

Admin Override: When viewing agents in admin mode, setAdminWorkspaceOverride() allows viewing agents from any workspace without authentication.

Sources: frontend/lib/api-client.ts:818-880


Configuration

Environment Variables

Variable
Default
Purpose

REQUIRE_AUTH

true

Enable Clerk JWT validation

CLERK_SECRET_KEY

-

Clerk API secret for JWT verification

PLUGIN_CACHE_TTL_SECONDS

3600

Redis cache TTL for plugin content

S3_DOCUMENTS_BUCKET

automatos-ai

S3 bucket for plugin storage

Sources: orchestrator/config.py:87-88, orchestrator/config.py:283


Rate Limiting

Agent endpoints are rate-limited using SlowAPI:

Rate limit headers are returned in responses:

Sources: orchestrator/main.py:583-596


Database Relationships

spinner

Sources: orchestrator/api/agent_plugins.py:78-101, orchestrator/api/agent_plugins.py:249-252


Plugin Context Service

The PluginContextService builds tiered plugin context for agent prompts:

Tier 1 Summary (compact reference):

Tier 2 Content (full documentation):

Sources: orchestrator/api/agent_plugins.py:266-286


Testing Endpoints

Use the interactive API docs at http://localhost:8000/docs (disabled in production):

  1. Click "Authorize" and enter your Clerk JWT token

  2. Add X-Workspace-ID header in request

  3. Test endpoints with live validation

Alternative: Use curl with explicit headers:

Sources: orchestrator/main.py:533-534


Last updated