Agents API
Create, manage, and interact with AI agents — including chat, streaming, sub-agents, training, and web search.
Overview
The Agents API is the core of Arcanflows. It lets you create AI agents backed by any supported LLM, attach tools and knowledge bases, configure sub-agent delegation, and interact via synchronous chat, SSE streaming, or async jobs.
Endpoint Summary
Core CRUD
| Method | Endpoint | Description |
|---|---|---|
GET | /api/v1/agents | List agents |
POST | /api/v1/agents | Create agent |
GET | /api/v1/agents/:id | Get agent |
PUT | /api/v1/agents/:id | Update agent |
DELETE | /api/v1/agents/:id | Delete agent |
Chat & Runtime
| Method | Endpoint | Description |
|---|---|---|
POST | /api/v1/agents/:id/chat | Synchronous chat |
POST | /api/v1/agents/:id/chat/stream | SSE streaming chat |
POST | /api/v1/agents/:id/chat/async | Async chat (returns job ID) |
POST | /api/v1/agents/:id/chat/audio | Send audio message |
POST | /api/v1/agents/:id/chat/tts | Text-to-speech response |
GET | /api/v1/agents/:id/status | Agent runtime status |
Sub-Agents
| Method | Endpoint | Description |
|---|---|---|
GET | /api/v1/agents/:id/sub-agents | List sub-agents |
POST | /api/v1/agents/:id/sub-agents/attach | Attach sub-agent from template |
POST | /api/v1/agents/:id/sub-agents/direct | Create a direct sub-agent |
PUT | /api/v1/agents/:id/sub-agents/direct/:subId | Update direct sub-agent |
PATCH | /api/v1/agents/:id/sub-agents/:subId | Update sub-agent config |
DELETE | /api/v1/agents/:id/sub-agents/:subId | Detach sub-agent |
Training & Knowledge
| Method | Endpoint | Description |
|---|---|---|
POST | /api/v1/agents/:id/train | Train agent on documents |
Stats & Logs
| Method | Endpoint | Description |
|---|---|---|
GET | /api/v1/agents/:id/stats | Usage statistics |
GET | /api/v1/agents/:id/logs | Chat logs |
GET | /api/v1/agents/:id/log-settings | Get log settings |
PUT | /api/v1/agents/:id/log-settings | Update log settings |
SerpAPI (Web Search)
| Method | Endpoint | Description |
|---|---|---|
GET | /api/v1/agents/:id/serpapi/config | Get search config |
PUT | /api/v1/agents/:id/serpapi/config | Update search config |
POST | /api/v1/agents/:id/serpapi/enable | Enable web search |
POST | /api/v1/agents/:id/serpapi/disable | Disable web search |
Public / Embed
| Method | Endpoint | Description |
|---|---|---|
GET | /api/v1/public/agents/:id/embed | Get embeddable chat widget script |
List Agents
GET /api/v1/agents
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
page | integer | 1 | Page number |
per_page | integer | 20 | Items per page (max 100) |
search | string | — | Search by agent name |
status | string | — | Filter: draft, published, archived |
Example
bashcurl "https://your-instance.arcanflows.com/api/v1/agents?status=published&per_page=10" \ -H "Authorization: Bearer <your_login_jwt>"
Response
json{ "data": [ { "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "name": "Support Bot", "description": "Handles customer inquiries", "primary_model": "gpt-4o", "status": "published", "temperature": 0.7, "created_at": "2026-03-10T08:00:00Z", "updated_at": "2026-04-01T12:30:00Z" } ], "pagination": { "page": 1, "per_page": 10, "total": 3, "total_pages": 1 } }
Create Agent
POST /api/v1/agents
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Agent name (max 100 characters) |
description | string | No | Short description |
primary_model | string | Yes | LLM model identifier (see available models below) |
system_prompt | string | Yes | System prompt defining agent behavior |
temperature | number | No | Creativity level, 0.0 to 1.0 (default 0.7) |
max_tokens | integer | No | Max response tokens (default 2048) |
status | string | No | draft or published (default draft) |
Available Models
Models depend on what backends and Ollama models are configured on your instance. Common options:
| Model | Provider |
|---|---|
gpt-4o | OpenAI |
gpt-4-turbo | OpenAI |
gpt-3.5-turbo | OpenAI |
claude-3.5-sonnet | Anthropic |
claude-3-opus | Anthropic |
claude-3-haiku | Anthropic |
gemini-pro | |
gemini-1.5 | |
grok-2 | xAI |
grok-3 | xAI |
| Any Ollama model | Local (Ollama) |
Example
bashcurl -X POST "https://your-instance.arcanflows.com/api/v1/agents" \ -H "Authorization: Bearer <your_login_jwt>" \ -H "Content-Type: application/json" \ -d '{ "name": "Support Bot", "primary_model": "gpt-4o", "system_prompt": "You are a helpful customer support assistant for Acme Inc. Answer questions accurately and politely.", "temperature": 0.7, "max_tokens": 2048 }'
Response (201 Created)
json{ "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "name": "Support Bot", "description": "", "primary_model": "gpt-4o", "system_prompt": "You are a helpful customer support assistant for Acme Inc. Answer questions accurately and politely.", "temperature": 0.7, "max_tokens": 2048, "status": "draft", "created_at": "2026-04-12T09:00:00Z", "updated_at": "2026-04-12T09:00:00Z" }
Get Agent
GET /api/v1/agents/:id
Returns the full agent object including tools, knowledge base status, and sub-agent configuration.
Example
bashcurl "https://your-instance.arcanflows.com/api/v1/agents/a1b2c3d4-e5f6-7890-abcd-ef1234567890" \ -H "Authorization: Bearer <your_login_jwt>"
Response
json{ "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "name": "Support Bot", "description": "Handles customer inquiries", "primary_model": "gpt-4o", "system_prompt": "You are a helpful customer support assistant...", "temperature": 0.7, "max_tokens": 2048, "status": "published", "tools": [ { "id": "tool-uuid-here", "name": "Get Order Status", "tool_type": "rest_api", "is_enabled": true } ], "knowledge_base": { "enabled": true, "document_count": 15, "chunk_count": 342 }, "sub_agents": [ { "id": "sub-agent-uuid", "name": "Billing Assistant", "relationship_type": "template" } ], "created_at": "2026-03-10T08:00:00Z", "updated_at": "2026-04-01T12:30:00Z" }
Update Agent
PUT /api/v1/agents/:id
Send only the fields you want to update.
Example
bashcurl -X PUT "https://your-instance.arcanflows.com/api/v1/agents/a1b2c3d4-e5f6-7890-abcd-ef1234567890" \ -H "Authorization: Bearer <your_login_jwt>" \ -H "Content-Type: application/json" \ -d '{ "name": "Support Bot v2", "temperature": 0.5, "status": "published" }'
Returns the updated agent object.
Delete Agent
DELETE /api/v1/agents/:id
bashcurl -X DELETE "https://your-instance.arcanflows.com/api/v1/agents/a1b2c3d4-e5f6-7890-abcd-ef1234567890" \ -H "Authorization: Bearer <your_login_jwt>"
Returns 204 No Content on success.
Chat with Agent (Synchronous)
POST /api/v1/agents/:id/chat
Sends a message and waits for the full response. This endpoint requires a console JWT (it is what the web app uses).
Calling an agent from your own code? Use the public endpoint instead —
POST /api/v1/public/agents/:id/chat— authenticated with an Embed API Key (emb_). Its body is{ "session_id", "message" }and the reply is inassistant_reply.content. Full details on the API overview and Authentication pages. The examples below use the console-JWT endpoint.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
message | string | Yes | User message |
conversation_id | string | No | Continue an existing conversation |
context | object | No | Additional context passed to the agent |
Example
bashcurl -X POST "https://your-instance.arcanflows.com/api/v1/agents/AGENT_ID/chat" \ -H "Authorization: Bearer <your_login_jwt>" \ -H "Content-Type: application/json" \ -d '{ "message": "How do I reset my password?", "conversation_id": "conv-uuid-here" }'
Response
json{ "conversation_id": "conv-uuid-here", "message": { "id": "msg-uuid-here", "role": "assistant", "content": "To reset your password:\n\n1. Go to Settings > Security\n2. Click Reset Password\n3. Check your email for the reset link\n\nLet me know if you need anything else!", "created_at": "2026-04-12T09:15:00Z" }, "usage": { "prompt_tokens": 150, "completion_tokens": 85, "total_tokens": 235 }, "sources": [ { "document_name": "Password Reset Guide.pdf", "chunk_preview": "To reset your password, navigate to...", "relevance_score": 0.92 } ], "tool_calls": [] }
Chat with Agent (SSE Streaming)
POST /api/v1/agents/:id/chat/stream
Returns a Server-Sent Events stream. The request body is identical to the synchronous chat endpoint.
SSE Event Format
event: message_start
data: {"conversation_id": "conv-uuid", "message_id": "msg-uuid"}
event: content_delta
data: {"delta": "To reset"}
event: content_delta
data: {"delta": " your password"}
event: tool_use
data: {"tool": "get_user_info", "input": {"user_id": "123"}}
event: tool_result
data: {"tool": "get_user_info", "output": {"email": "[email protected]"}}
event: message_stop
data: {"usage": {"prompt_tokens": 150, "completion_tokens": 85}}
JavaScript Streaming Example
javascriptconst response = await fetch( "https://your-instance.arcanflows.com/api/v1/agents/AGENT_ID/chat/stream", { method: "POST", headers: { "Authorization": "Bearer <your_login_jwt>", "Content-Type": "application/json", }, body: JSON.stringify({ message: "Tell me about your services" }), } ); const reader = response.body.getReader(); const decoder = new TextDecoder(); while (true) { const { done, value } = await reader.read(); if (done) break; const chunk = decoder.decode(value); const lines = chunk.split("\n"); for (const line of lines) { if (line.startsWith("data: ")) { const data = JSON.parse(line.slice(6)); if (data.delta) { process.stdout.write(data.delta); } } } }
Async Chat
POST /api/v1/agents/:id/chat/async
Starts a chat job and immediately returns a job ID. Useful for long-running agent tasks with tool execution.
Request Body
Same as synchronous chat.
Response (202 Accepted)
json{ "job_id": "job-uuid-here", "status": "pending" }
Poll the job status or use webhooks to get notified when the response is ready.
Audio Chat
POST /api/v1/agents/:id/chat/audio
Send an audio file as a message. The audio is transcribed via STT and then processed by the agent.
Request
Content-Type: multipart/form-data
| Field | Type | Required | Description |
|---|---|---|---|
audio | file | Yes | Audio file (wav, mp3, webm) |
conversation_id | string | No | Continue existing conversation |
Text-to-Speech
POST /api/v1/agents/:id/chat/tts
Generates an audio response from text using the configured TTS voice.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to convert to speech |
Response
Returns audio binary with Content-Type: audio/mpeg.
Agent Status
GET /api/v1/agents/:id/status
Returns the current runtime status of the agent.
json{ "agent_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "status": "published", "is_online": true, "active_conversations": 3 }
Sub-Agents
Sub-agents allow an agent to delegate specific tasks to specialized child agents. There are two types:
- Template sub-agents: Attached from existing agents in the system
- Direct sub-agents: Created inline, specific to the parent agent
List Sub-Agents
GET /api/v1/agents/:id/sub-agents
json{ "data": [ { "id": "sub-uuid-1", "name": "Billing Assistant", "relationship_type": "template", "is_enabled": true, "delegation_prompt": "Handle all billing and payment questions" }, { "id": "sub-uuid-2", "name": "Technical Support", "relationship_type": "direct", "is_enabled": true, "delegation_prompt": "Handle technical troubleshooting" } ] }
Attach Sub-Agent from Template
POST /api/v1/agents/:id/sub-agents/attach
json{ "agent_id": "existing-agent-uuid", "delegation_prompt": "Handle billing questions", "is_enabled": true }
Create Direct Sub-Agent
POST /api/v1/agents/:id/sub-agents/direct
json{ "name": "FAQ Bot", "primary_model": "gpt-3.5-turbo", "system_prompt": "You answer frequently asked questions.", "delegation_prompt": "Handle simple FAQ inquiries", "temperature": 0.3 }
Update Direct Sub-Agent
PUT /api/v1/agents/:id/sub-agents/direct/:subId
Update Sub-Agent Config
PATCH /api/v1/agents/:id/sub-agents/:subId
json{ "delegation_prompt": "Updated delegation instructions", "is_enabled": false }
Detach Sub-Agent
DELETE /api/v1/agents/:id/sub-agents/:subId
Returns 204 No Content.
Train Agent
POST /api/v1/agents/:id/train
Triggers training (document indexing into the RAG knowledge base). Upload documents first via the Storage API, then reference them here.
Request (multipart/form-data)
| Field | Type | Required | Description |
|---|---|---|---|
files | file[] | Yes | Documents to index (PDF, TXT, DOCX, MD, CSV) |
Response
json{ "status": "training", "document_count": 3, "message": "Training started. Documents are being processed." }
Training runs asynchronously. Check agent status or logs to monitor progress.
Agent Stats
GET /api/v1/agents/:id/stats
Response
json{ "agent_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "total_conversations": 1520, "total_messages": 8432, "total_tokens_used": 2450000, "avg_response_time_ms": 1850, "period": "all_time" }
Agent Logs
GET /api/v1/agents/:id/logs
Returns chat interaction logs for debugging and monitoring.
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
page | integer | 1 | Page number |
per_page | integer | 20 | Items per page |
Log Settings
GET /api/v1/agents/:id/log-settings
PUT /api/v1/agents/:id/log-settings
Configure what gets logged (messages, tool calls, token usage, etc.).
json{ "log_messages": true, "log_tool_calls": true, "log_token_usage": true, "retention_days": 30 }
SerpAPI (Web Search)
Give an agent the ability to search the web via SerpAPI integration.
Get Search Config
GET /api/v1/agents/:id/serpapi/config
json{ "enabled": true, "search_engine": "google", "max_results": 5, "safe_search": true }
Update Search Config
PUT /api/v1/agents/:id/serpapi/config
json{ "max_results": 10, "safe_search": false }
Enable / Disable
bash# Enable curl -X POST "https://your-instance.arcanflows.com/api/v1/agents/AGENT_ID/serpapi/enable" \ -H "Authorization: Bearer <your_login_jwt>" # Disable curl -X POST "https://your-instance.arcanflows.com/api/v1/agents/AGENT_ID/serpapi/disable" \ -H "Authorization: Bearer <your_login_jwt>"
Public Embed
GET /api/v1/public/agents/:id/embed
Returns an embeddable script tag for adding a chat widget to any website.
Response
json{ "embed_code": "<script src=\"https://your-instance.arcanflows.com/embed/AGENT_ID.js\" async></script>", "agent_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "agent_name": "Support Bot" }
Full Example: Create, Configure, and Chat
bash# 1. Create the agent AGENT_ID=$(curl -s -X POST "https://your-instance.arcanflows.com/api/v1/agents" \ -H "Authorization: Bearer <your_login_jwt>" \ -H "Content-Type: application/json" \ -d '{ "name": "Product Assistant", "primary_model": "claude-3.5-sonnet", "system_prompt": "You help customers learn about our products.", "temperature": 0.6 }' | jq -r '.id') # 2. Enable web search curl -X POST "https://your-instance.arcanflows.com/api/v1/agents/$AGENT_ID/serpapi/enable" \ -H "Authorization: Bearer <your_login_jwt>" # 3. Publish the agent curl -X PUT "https://your-instance.arcanflows.com/api/v1/agents/$AGENT_ID" \ -H "Authorization: Bearer <your_login_jwt>" \ -H "Content-Type: application/json" \ -d '{"status": "published"}' # 4. Chat curl -X POST "https://your-instance.arcanflows.com/api/v1/agents/$AGENT_ID/chat" \ -H "Authorization: Bearer <your_login_jwt>" \ -H "Content-Type: application/json" \ -d '{"message": "What are your top products this year?"}'