Agents API

Complete reference for the Agents API including endpoints, parameters, and examples.

Base URL

All Agents API endpoints are available at:

https://your-instance.com/api/v1/agents

Authentication

All Agents API endpoints require authentication via session cookies or API keys.

Agent Management

List Agents

GET /

Retrieve all agents available to the current user.

Query Parameters

  • limit (integer, optional) - Maximum number of agents to return (default: 100)
  • offset (integer, optional) - Number of agents to skip (default: 0)
  • search (string, optional) - Search term to filter agents by name or description

Response

{
  "agents": [
    {
      "agent_id": "uuid",
      "name": "Agent Name",
      "description": "Agent description",
      "agent_type_id": "llm",
      "version": "1.0.0",
      "status": "active",
      "is_system": false,
      "created_at": "2024-01-01T00:00:00Z",
      "updated_at": "2024-01-01T00:00:00Z"
    }
  ],
  "total_count": 1,
  "has_more": false
}

Get Agent Details

GET /{agent_id}

Retrieve detailed information about a specific agent.

Response

{
  "agent_id": "uuid",
  "name": "Agent Name",
  "description": "Agent description",
  "agent_type_id": "llm",
  "version": "1.0.0",
  "status": "active",
  "is_system": false,
  "agent_config": {
    "model": "gpt-4",
    "temperature": 0.7,
    "system_message": "You are a helpful assistant."
  },
  "app_id": "uuid",
  "created_at": "2024-01-01T00:00:00Z",
  "updated_at": "2024-01-01T00:00:00Z"
}

Agent Activation

Activate Agent (App-Scoped)

POST /{agent_id}/activate

Activate an agent in the current app context. This is the primary activation endpoint for apps.

Request Body

{
  "input_data": {
    "prompt": "Your message to the agent",
    "additional_context": "optional context"
  },
  "context": {
    "chat_id": "optional-chat-id",
    "session_id": "optional-session-id",
    "user_context": "additional user context"
  },
  "metadata": {
    "provider_id": "llm-provider-uuid",
    "model": "gpt-4",
    "temperature": 0.7,
    "max_tokens": 2048,
    "system_prompt": "Custom system prompt override"
  }
}

Response

{
  "activation_id": "uuid",
  "agent_id": "uuid",
  "status": "queued",
  "input_data": {...},
  "context": {...},
  "metadata": {...},
  "priority": 1,
  "created_at": "2024-01-01T00:00:00Z",
  "started_at": null,
  "completed_at": null,
  "duration_ms": null,
  "output_data": null,
  "error": null
}

Get Agent Activations

GET /{agent_id}/activations

Retrieve activation history for a specific agent.

Query Parameters

  • limit (integer, optional) - Maximum number of activations to return (default: 50)
  • offset (integer, optional) - Number of activations to skip (default: 0)
  • status (string, optional) - Filter by status: queued, running, completed, failed
  • context (object, optional) - Filter by context fields (e.g., chat_id)

Response

{
  "activations": [
    {
      "activation_id": "uuid",
      "agent_id": "uuid",
      "status": "completed",
      "input_data": {...},
      "output_data": {...},
      "context": {...},
      "created_at": "2024-01-01T00:00:00Z",
      "completed_at": "2024-01-01T00:05:30Z",
      "duration_ms": 330000
    }
  ],
  "total_count": 1,
  "has_more": false
}

Activation Statuses

Agent activations go through the following status lifecycle:

Status Description Next States
queued Activation has been created and is waiting to be processed running, failed
running Agent is currently executing completed, failed
completed Agent execution completed successfully Final state
failed Agent execution failed due to an error Final state

Agent Types

Fiberwisesupports different types of agents:

LLM Agents (agent_type_id: "llm")

Agents that interface with Large Language Models. Configuration includes model selection, temperature, system prompts, and other LLM-specific parameters.

Custom Agents (agent_type_id: "custom")

Agents that execute custom Python code. These agents run user-defined functions with access to injected services like storage, OAuth, and LLM providers.

Real-Time Updates

Agent activations can be monitored in real-time using WebSocket connections. See the WebSocket API documentation for details on subscribing to activation updates.

// WebSocket message for activation completion
{
  "type": "activation_completed",
  "activation_id": "uuid",
  "status": "completed",
  "context": {
    "chat_id": "uuid",
    "app_id": "uuid"
  },
  "timestamp": "2024-01-01T00:05:30Z"
}

Error Responses

All endpoints return standard HTTP status codes and JSON error responses:

{
  "detail": "Agent not found",
  "status_code": 404,
  "error_type": "NotFoundError"
}

Common Error Scenarios

  • 400 Bad Request - Invalid input data or missing required fields
  • 401 Unauthorized - Authentication required or invalid credentials
  • 403 Forbidden - User does not have permission to access the agent
  • 404 Not Found - Agent does not exist or is not accessible
  • 429 Too Many Requests - Rate limit exceeded
  • 500 Internal Server Error - Server error during agent execution
Description id string Unique identifier for the agent name string Human-readable name of the agent version string Version number of the agent description string Brief description of agent functionality is_system boolean Whether this is a system-provided agent capabilities array List of agent capabilities/features

Get Agent Details

Retrieve detailed information about a specific agent.

GET /api/v1/agents/{agent_id}
Authorization: Bearer <api_key>

Path Parameters

Parameter Type Description
agent_id string The unique identifier of the agent

Activate Agent

Execute an agent with input data and receive results.

POST /api/v1/agents/{agent_id}/activate
Authorization: Bearer <api_key>
Content-Type: application/json

{
    "input_data": {
        "text": "Content to process",
        "options": {
            "mode": "analyze"
        }
    },
    "context_type": "general",
    "metadata": {
        "source": "api_call"
    }
}

Request Body

Field Type Description
input_data object Data to be processed by the agent
context_type string Optional context type for the activation
metadata object Optional metadata for tracking/logging

Response

{
    "activation_id": "activation_456",
    "status": "pending",
    "message": "Agent activation has been created successfully"
}

Response Fields

Field Type Description
activation_id string Unique identifier for this activation
status string Current status: pending, processing, completed, failed
message string Human-readable status message

Get Agent Activations

Retrieve a list of activations for a specific agent.

GET /api/v1/agents/{agent_id}/activations?limit=10
Authorization: Bearer <api_key>

Query Parameters

Parameter Type Description
limit integer Maximum number of activations to return (default: 50)
offset integer Number of activations to skip (default: 0)
status string Filter by status: pending, processing, completed, failed

Get Activation Details

Retrieve details about a specific activation, including results if completed.

GET /api/v1/activations/{activation_id}
Authorization: Bearer <api_key>

Response

{
    "activation_id": "activation_123",
    "status": "completed",
    "input_data": {
        "text": "Content to process",
        "options": {"mode": "analyze"}
    },
    "output_data": {
        "analysis": "Processed analysis results",
        "confidence": 0.95
    },
    "created_at": "2024-01-01T00:00:00Z",
    "completed_at": "2024-01-01T00:01:00Z"
}

Usage Examples

JavaScript/Node.js

// List all agents
async function listAgents() {
    const response = await fetch('http://localhost:5555/api/v1/agents', {
        headers: {
            'Authorization': 'Bearer fw_key_abc123...',
            'Content-Type': 'application/json'
        }
    });

    const data = await response.json();
    return data.agents;
}

// Activate an agent
async function activateAgent(agentId, inputData) {
    const response = await fetch(`http://localhost:5555/api/v1/agents/${agentId}/activate`, {
        method: 'POST',
        headers: {
            'Authorization': 'Bearer fw_key_abc123...',
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            input_data: inputData,
            context_type: 'general'
        })
    });

    const activation = await response.json();
    return activation.activation_id;
}

// Check activation status
async function checkActivation(activationId) {
    const response = await fetch(`http://localhost:5555/api/v1/activations/${activationId}`, {
        headers: {
            'Authorization': 'Bearer fw_key_abc123...',
            'Content-Type': 'application/json'
        }
    });

    return await response.json();
}

Python

import requests
import time

API_BASE = 'http://localhost:5555/api/v1'
HEADERS = {
    'Authorization': 'Bearer fw_key_abc123...',
    'Content-Type': 'application/json'
}

def list_agents():
    """List all available agents"""
    response = requests.get(f'{API_BASE}/agents', headers=HEADERS)
    return response.json()['agents']

def activate_agent(agent_id, input_data):
    """Activate an agent with input data"""
    payload = {
        'input_data': input_data,
        'context_type': 'general'
    }

    response = requests.post(
        f'{API_BASE}/agents/{agent_id}/activate',
        headers=HEADERS,
        json=payload
    )

    return response.json()['activation_id']

def wait_for_completion(activation_id, timeout=60):
    """Wait for activation to complete"""
    start_time = time.time()

    while time.time() - start_time < timeout:
        response = requests.get(
            f'{API_BASE}/activations/{activation_id}',
            headers=HEADERS
        )

        activation = response.json()
        status = activation['status']

        if status == 'completed':
            return activation['output_data']
        elif status == 'failed':
            raise Exception(f"Activation failed: {activation.get('error', 'Unknown error')}")

        time.sleep(1)

    raise TimeoutError(f"Activation {activation_id} did not complete within {timeout} seconds")

# Example usage
agents = list_agents()
text_agent = next((a for a in agents if 'text' in a['name'].lower()), None)

if text_agent:
    activation_id = activate_agent(text_agent['id'], {
        'text': 'Analyze this text for sentiment and key topics.'
    })

    result = wait_for_completion(activation_id)
    print(f"Analysis result: {result}")

cURL

# List agents
curl -X GET "http://localhost:5555/api/v1/agents" \
  -H "Authorization: Bearer fw_key_abc123..."

# Activate agent
curl -X POST "http://localhost:5555/api/v1/agents/agent_123/activate" \
  -H "Authorization: Bearer fw_key_abc123..." \
  -H "Content-Type: application/json" \
  -d '{
    "input_data": {
      "text": "Content to analyze"
    },
    "context_type": "general"
  }'

# Check activation status
curl -X GET "http://localhost:5555/api/v1/activations/activation_456" \
  -H "Authorization: Bearer fw_key_abc123..."

Error Handling

The Agents API returns standard HTTP status codes and error messages:

400 Bad Request

Invalid request format or missing required fields

{"detail": "Missing required field: input_data"}

401 Unauthorized

Invalid or missing API key

{"detail": "Invalid API key"}

404 Not Found

Agent or activation not found

{"detail": "Agent with id 'invalid_agent' not found"}

429 Too Many Requests

Rate limit exceeded

{"detail": "Rate limit exceeded. Try again in 60 seconds."}

500 Internal Server Error

Server error during agent execution

{"detail": "Internal server error occurred during agent activation"}

Next Steps

Explore related API endpoints to build complete applications: