Agent API
Manage AI agents, publish control, chat interaction, and statistics queries
Endpoint Overview
The Agent API provides agent lifecycle management, chat interaction, and statistics query capabilities. Base path: /api/v1/agents.
| Method | Path | Purpose |
|---|---|---|
| GET | /api/v1/agents | List agents accessible to the current user |
| POST | /api/v1/agents | Create a new agent |
| GET | /api/v1/agents/{agent_id} | Get agent details (including full configuration) |
| PUT | /api/v1/agents/{agent_id} | Update agent configuration |
| DELETE | /api/v1/agents/{agent_id} | Permanently delete an agent |
| POST | /api/v1/agents/{agent_id}/publish | Publish an agent |
| POST | /api/v1/agents/{agent_id}/unpublish | Unpublish an agent |
| GET | /api/v1/agents/{agent_id}/public | Get public agent basic info, authentication optional |
| POST | /api/v1/agents/{agent_id}/chat | Non-streaming chat |
| POST | /api/v1/agents/{agent_id}/chat/stream | SSE streaming chat |
| POST | /api/v1/agents/{agent_id}/messages/{message_id}/regenerate | Regenerate |
| POST | /api/v1/agents/{agent_id}/messages/{message_id}/edit/stream | Edit a user message and create a branch |
| GET | /api/v1/agents/{agent_id}/messages/{message_id}/versions | Query message versions |
| POST | /api/v1/agents/{agent_id}/messages/{message_id}/switch-version | Switch version |
| GET | /api/v1/agents/{agent_id}/stats | Query agent statistics overview |
| GET | /api/v1/agents/{agent_id}/stats/trends | Query trend data |
| GET | /api/v1/agents/{agent_id}/stats/tool-usage | Query tool usage statistics |
| GET | /api/v1/agents/{agent_id}/stats/recent-conversations | Query recent conversations |
Authentication
All endpoints require an authenticated JWT user session. Chat endpoints additionally support API Keys (with bound agent permissions).
Required scopes:
| Scope | Purpose |
|---|---|
agent:read | List and view agents |
agent:create | Create agents |
agent:update | Update agents |
agent:delete | Delete agents |
agent:publish | Publish or unpublish agents |
agent:chat | Chat with agents |
List Agents
GET /api/v1/agentsGet all agents accessible to the current user, with pagination, team filtering, status filtering, and keyword search.
Query Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
page | integer | No | 1 | Page number |
page_size | integer | No | 20 | Items per page |
team_id | string | No | - | Filter by team UUID |
status | string | No | - | Filter by status: draft, published |
visibility | string | No | - | Filter by visibility: private, team, public (legacy compatibility value) |
keyword | string | No | - | Search by name or description |
own_only | boolean | No | false | Only show agents created by the current user |
Request Example
curl -X GET "https://your-domain.com/api/v1/agents?page=1&page_size=20" \
-H "Authorization: Bearer YOUR_TOKEN"Response Fields
| Field | Type | Description |
|---|---|---|
id | string | Agent UUID |
name | string | Name |
description | string | Description |
icon | string | Icon emoji or URL |
avatar_url | string | Avatar URL |
team | object | Team info (id, name, avatar_url) |
model | object | Model info (id, name, provider, model_id), null if unset |
status | string | draft or published |
visibility | string | private or team |
conversation_count | integer | Number of conversations |
message_count | integer | Number of messages |
created_by | object | Creator info (id, username, avatar_url) |
created_at | string | ISO 8601 timestamp |
updated_at | string | ISO 8601 timestamp |
Success Response (200 OK)
{
"code": 0,
"data": {
"items": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "Customer Support Agent",
"description": "Helps customers with common questions",
"icon": "🤖",
"avatar_url": "https://example.com/avatar.png",
"team": {
"id": "team-123",
"name": "Support Team",
"avatar_url": "https://example.com/team.png"
},
"model": {
"id": "model-456",
"name": "GPT-4",
"provider": "openai",
"provider_display_name": "OpenAI",
"model_id": "gpt-4"
},
"status": "published",
"visibility": "team",
"conversation_count": 156,
"message_count": 1234,
"created_by": {
"id": "user-001",
"username": "alice",
"avatar_url": "https://example.com/avatars/alice.jpg"
},
"created_at": "2026-02-11T10:00:00Z",
"updated_at": "2026-02-11T15:30:00Z"
}
],
"total": 42,
"page": 1,
"page_size": 20
},
"msg": "success"
}Get Agent Details
GET /api/v1/agents/{agent_id}Get the complete configuration of a specified agent, including system prompt, tool configuration, knowledge base associations, and RAG parameters.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent UUID |
Request Example
curl -X GET "https://your-domain.com/api/v1/agents/550e8400-e29b-41d4-a716-446655440000" \
-H "Authorization: Bearer YOUR_TOKEN"Response Fields
In addition to the list fields above, the details endpoint returns the full configuration:
| Field | Type | Description |
|---|---|---|
model_id | string | Team model UUID |
system_prompt | string | System prompt |
max_iterations | integer | Max tool call iterations (1–200, default 5) |
hide_tool_calls | boolean | Hide tool call details in chat UI |
hide_message_actions | boolean | Hide token usage/speed stats |
hide_reasoning | boolean | Hide reasoning/chain-of-thought |
tools_config | array | Tool configs (type/name/tool_id/server_id/skill_id/config) |
enable_attachments | boolean | Enable file and image attachments |
enable_user_input_request | boolean | Enable model-callable ask_user tool |
enable_memory | boolean | Enable cross-conversation memory |
rag_mode | string | RAG mode: off, auto, agentic (default) |
variables | array | Chat input variable definitions |
knowledge_bases | array | Associated knowledge base configs (with retrieval_top_k, score_threshold, search_mode) |
Success Response (200 OK)
{
"code": 0,
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "Customer Support Agent",
"description": "Helps customers with common questions",
"system_prompt": "You are a helpful customer support agent...",
"max_iterations": 5,
"hide_tool_calls": false,
"tools_config": [
{
"type": "builtin",
"name": "web_search"
}
],
"enable_memory": false,
"rag_mode": "agentic",
"knowledge_bases": [
{
"id": "kb-assoc-001",
"knowledge_base": {
"id": "kb-789",
"name": "Product Documentation",
"description": "Product docs and FAQs",
"icon": "📚",
"document_count": 156
},
"retrieval_top_k": 5,
"score_threshold": 0.3,
"search_mode": "hybrid"
}
],
"status": "published",
"visibility": "team",
"created_at": "2026-02-11T10:00:00Z",
"updated_at": "2026-02-11T15:30:00Z"
},
"msg": "success"
}Error Response (404 Not Found)
{
"code": 6200,
"data": {
"agent_id": "550e8400-e29b-41d4-a716-446655440000"
},
"msg": "Agent not found"
}Create Agent
POST /api/v1/agentsCreate a new AI agent. The agent is in draft status by default and must be published before it can be used for chat.
Request Body
{
"name": "Customer Support Agent",
"description": "Helps customers with common questions",
"avatar_url": "https://example.com/avatar.png",
"team_id": "team-123",
"model_id": "model-456",
"system_prompt": "You are a helpful customer support agent...",
"max_iterations": 5,
"hide_tool_calls": false,
"tools_config": [
{
"type": "builtin",
"name": "web_search"
}
],
"enable_memory": false,
"rag_mode": "agentic",
"knowledge_base_configs": [
{
"knowledge_base_id": "kb-789",
"retrieval_top_k": 5,
"score_threshold": 0.3,
"search_mode": "hybrid"
}
],
"visibility": "team"
}Request Fields
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Name (max 100 chars) |
description | string | No | Description (max 500 chars) |
icon | string | No | Icon emoji or URL (max 500 chars) |
avatar_url | string | No | Avatar URL |
team_id | string | Yes | Team UUID |
model_id | string | No | Team model UUID; uses team default if unset |
system_prompt | string | No | System prompt/instructions |
max_iterations | integer | No | Max tool call iterations (1–200, default 5) |
hide_tool_calls | boolean | No | Hide tool call details in chat UI (default false) |
hide_message_actions | boolean | No | Hide token usage/speed stats (default false) |
hide_reasoning | boolean | No | Hide reasoning/chain-of-thought (default false) |
tools_config | array | No | Tool configs (type/name/tool_id/server_id/skill_id/config) |
tools_credentials | object | No | Tool credentials (API keys, tokens, etc.) |
enable_attachments | boolean | No | Enable file and image attachments (default false) |
attachment_config | object | No | Attachment limits configuration |
enable_user_input_request | boolean | No | Enable ask_user tool (default false) |
enable_memory | boolean | No | Enable cross-conversation memory (default false) |
memory_config | object | No | Memory configuration |
context_compression_config | object | No | Context compression configuration |
enable_image_generation | boolean | No | Enable image generation tool (default false) |
image_generation_config | object | No | Image generation configuration |
enable_video_generation | boolean | No | Enable video generation tool (default false) |
video_generation_config | object | No | Video generation configuration |
rag_mode | string | No | RAG mode: off, auto, agentic (default agentic) |
knowledge_base_configs | array | No | KB configs (knowledge_base_id, retrieval_top_k, score_threshold, search_mode) |
variables | array | No | Chat input variable definitions |
opening_message | string | No | Opening message shown in chat |
suggested_questions | array | No | Suggested questions |
visibility | string | No | private or team (default team) |
Request Example
curl -X POST "https://your-domain.com/api/v1/agents" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Customer Support Agent",
"description": "Helps customers with common questions",
"team_id": "team-123",
"model_id": "model-456",
"system_prompt": "You are a helpful customer support agent...",
"tools_config": [{"type": "builtin", "name": "web_search"}],
"knowledge_base_configs": [
{
"knowledge_base_id": "kb-789",
"retrieval_top_k": 5,
"score_threshold": 0.3,
"search_mode": "hybrid"
}
],
"rag_mode": "agentic"
}'Success Response (200 OK)
{
"code": 0,
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "Customer Support Agent",
"description": "Helps customers with common questions",
"status": "draft",
"visibility": "team",
"team": {
"id": "team-123",
"name": "Support Team",
"avatar_url": null
},
"model_id": "model-456",
"model": {
"id": "model-456",
"name": "GPT-4",
"provider": "openai",
"provider_display_name": "OpenAI",
"model_id": "gpt-4"
},
"created_at": "2026-02-11T10:00:00Z",
"created_by": {
"id": "user-001",
"username": "alice",
"avatar_url": null
}
},
"msg": "Agent created successfully"
}Error Response (1001 Validation Error)
{
"code": 1001,
"data": {
"errors": [
{
"field": "name",
"message": "Name is required"
},
{
"field": "model_id",
"message": "Invalid model ID"
}
]
},
"msg": "Validation failed"
}After creation, the agent is in draft status. Call the publish endpoint to make it available for chat.
Update Agent
PUT /api/v1/agents/{agent_id}Update the configuration of an existing agent. All fields are optional; only include the fields you want to update.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent UUID |
Request Body
{
"name": "Updated Agent Name",
"description": "Updated description",
"system_prompt": "Updated system prompt...",
"max_iterations": 8,
"tools_config": [
{"type": "builtin", "name": "web_search"},
{"type": "builtin", "name": "code_interpreter"}
],
"rag_mode": "auto"
}Request Example
curl -X PUT "https://your-domain.com/api/v1/agents/550e8400-e29b-41d4-a716-446655440000" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Updated Agent Name",
"max_iterations": 8
}'Success Response (200 OK)
{
"code": 0,
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "Updated Agent Name",
"max_iterations": 8,
"updated_at": "2026-02-11T16:00:00Z"
},
"msg": "Agent updated successfully"
}Delete Agent
DELETE /api/v1/agents/{agent_id}Permanently delete the specified agent. This action cannot be undone.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent UUID |
Request Example
curl -X DELETE "https://your-domain.com/api/v1/agents/550e8400-e29b-41d4-a716-446655440000" \
-H "Authorization: Bearer YOUR_TOKEN"Success Response (200 OK)
{
"code": 0,
"data": null,
"msg": "Agent deleted successfully"
}Error Response (6200 Not Found)
{
"code": 6200,
"data": {
"agent_id": "550e8400-e29b-41d4-a716-446655440000"
},
"msg": "Agent not found"
}Publish Agent
POST /api/v1/agents/{agent_id}/publishSet the agent status to published, making it available for chat. The publish operation does not validate whether a model is configured (model validation occurs in subsequent chat/access paths with error code 6202).
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent UUID |
Request Example
curl -X POST "https://your-domain.com/api/v1/agents/550e8400-e29b-41d4-a716-446655440000/publish" \
-H "Authorization: Bearer YOUR_TOKEN"Success Response (200 OK)
{
"code": 0,
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"status": "published"
},
"msg": "Agent published successfully"
}The publish endpoint only sets the status and does not validate the model. If the agent is in draft status during a subsequent chat, 6202 Agent not published will be returned.
Unpublish Agent
POST /api/v1/agents/{agent_id}/unpublishSet the agent status to draft, making it unavailable for chat.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent UUID |
Request Example
curl -X POST "https://your-domain.com/api/v1/agents/550e8400-e29b-41d4-a716-446655440000/unpublish" \
-H "Authorization: Bearer YOUR_TOKEN"Success Response (200 OK)
{
"code": 0,
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"status": "draft"
},
"msg": "Agent unpublished successfully"
}Chat (Non-Streaming)
POST /api/v1/agents/{agent_id}/chatSend a message to the agent and synchronously receive the complete response. Suitable for short responses; for long tasks, use the SSE streaming endpoint.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent UUID |
Request Body
{
"message": "What are your business hours?",
"conversation_id": "conv-123",
"files": [
{
"name": "document.pdf",
"url": "https://example.com/document.pdf",
"type": "application/pdf"
}
],
"file_urls": [
{
"asset_id": "asset-456",
"url": "https://your-domain.com/api/v1/upload/files/asset-456",
"filename": "report.pdf"
}
],
"variables": {
"customer_tier": "premium"
}
}Request Fields
| Field | Type | Required | Description |
|---|---|---|---|
message | string | Yes | User message (max 32000 chars) |
images | array | No | Images for vision (name, url, type) |
files | array | No | Parsed files (deprecated, use file_urls) |
file_urls | array | No | Raw uploaded asset metadata (asset_id, url, filename) |
conversation_id | string | No | Conversation UUID; creates a new one if not provided |
variables | object | No | Variable values for the chat input form |
history_override | array | No | Override conversation history (used for version switching/regeneration) |
Request Example
curl -X POST "https://your-domain.com/api/v1/agents/550e8400-e29b-41d4-a716-446655440000/chat" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"message": "What are your business hours?",
"conversation_id": "conv-123"
}'Success Response (200 OK)
{
"code": 0,
"data": {
"conversation_id": "conv-123",
"message": {
"id": "msg-456",
"conversation_id": "conv-123",
"role": "assistant",
"content": "Our business hours are Monday-Friday, 9 AM to 5 PM EST.",
"tool_calls": [],
"tool_name": null,
"model_used": "gpt-4",
"token_usage": {
"prompt": 150,
"completion": 25,
"total": 175
},
"duration_ms": 2300,
"rag_context": [
{
"document_id": "doc-789",
"document_name": "Business Hours Policy",
"chunk_id": "chunk-012",
"content": "Business hours: Monday-Friday, 9 AM to 5 PM EST",
"score": 0.95
}
],
"created_at": "2026-02-11T16:00:00Z",
"version_number": 1,
"version_count": 1
},
"usage": {
"prompt": 150,
"completion": 25,
"total": 175
}
},
"msg": "success"
}Chat (Streaming)
POST /api/v1/agents/{agent_id}/chat/streamReturn the response as a stream via SSE (Server-Sent Events). The request body is the same as the non-streaming endpoint; there is no stream flag parameter.
Request Example
curl -X POST "https://your-domain.com/api/v1/agents/550e8400-e29b-41d4-a716-446655440000/chat/stream" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"message": "What are your business hours?",
"conversation_id": "conv-123"
}'SSE Event Format
event: message_start
data: {"conversation_id": "conv-123", "message_id": "msg-456"}
event: content_delta
data: {"delta": "Our"}
event: content_delta
data: {"delta": " business"}
event: content_delta
data: {"delta": " hours"}
event: rag_context
data: {"contexts": [{"document_name": "FAQ", "content": "...", "score": 0.95}]}
event: message_end
data: {"usage": {"prompt_tokens": 150, "completion_tokens": 25, "total_tokens": 175}, "timing": {"first_token_ms": 320, "duration_ms": 2300, "tokens_per_second": 10.9}}| Event | Description |
|---|---|
message_start | Message started, returns conversation_id and message_id |
content_delta | Incremental text fragment |
rag_context | RAG retrieval context (document name, content, relevance score) |
message_end | Message ended, returns token usage and timing metrics |
SSE clients need to parse the event stream as text/event-stream. See SSE Streaming Events for details.
Regenerate
POST /api/v1/agents/{agent_id}/messages/{message_id}/regenerateRegenerate the response for a specified message. The request body structure is the same as the chat endpoint, and history_override can be used to adjust the historical context.
Edit Message and Create Branch
POST /api/v1/agents/{agent_id}/messages/{message_id}/edit/streamEdit a user message and generate a branch response, returned as an SSE stream.
Query Message Versions
GET /api/v1/agents/{agent_id}/messages/{message_id}/versionsQuery all versions of a specified message (including historical branches generated by regeneration and editing).
Switch Version
POST /api/v1/agents/{agent_id}/messages/{message_id}/switch-versionSwitch to a specified version as the currently active message.
Agent Statistics
GET /api/v1/agents/{agent_id}/statsQuery the usage statistics overview of an agent within a specified time range.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent UUID |
Query Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
period | string | No | 7d | Time range: 24h, 7d, 30d, all |
Request Example
curl -X GET "https://your-domain.com/api/v1/agents/550e8400-e29b-41d4-a716-446655440000/stats?period=30d" \
-H "Authorization: Bearer YOUR_TOKEN"Success Response (200 OK)
{
"code": 0,
"data": {
"period": "30d",
"overview": {
"total_conversations": 156,
"total_messages": 1234,
"user_messages": 620,
"assistant_messages": 610,
"tool_messages": 4,
"active_users": 23
},
"tokens": {
"prompt_tokens": 250000,
"completion_tokens": 206789,
"total_tokens": 456789
},
"performance": {
"avg_response_time_ms": 2300
},
"tools": {
"tool_call_count": 512
}
},
"msg": "success"
}Other Statistics Endpoints
| Endpoint | Description | Parameters |
|---|---|---|
GET /agents/{agent_id}/stats/trends | Trend data | period: 24h/7d/30d |
GET /agents/{agent_id}/stats/tool-usage | Tool usage statistics | period: 24h/7d/30d/all |
GET /agents/{agent_id}/stats/recent-conversations | Recent conversations | limit: default 10 |
Access Boundaries
- The agent must be in
publishedstatus to be used for chat. - The API Key must have the corresponding permissions; if the API Key is bound to a specific agent, it can only access agent IDs in the allowlist.
- The agent's attachment limits, tool iteration caps, and model quotas still apply during API calls.
Error Codes
| Code | Message | Description |
|---|---|---|
6200 | Agent not found | Agent does not exist |
6201 | Access denied | Current user does not have access to the agent |
6202 | Agent not published | Agent is in draft status |
3000 | Permission denied | Insufficient permissions |
1001 | Validation failed | Invalid request data |
5104 | Duplicate name | Agent name is already taken |
The current endpoints do not implement individual rate limiting; there is no rate-limit middleware.
Related Documentation
- API Get Started — Create an API Key, configure the base URL, and send your first request
- Agent Chat — Send messages, attachments, variables, and consume streaming responses
- SSE Streaming Events — Parse SSE events for agents and workflows
- Error Handling — Recover by HTTP status and business error codes
How is this guide?