Skip to main content

Agent API

/api/agent - Agent management endpoints

Overview

An Agent is a user-created configuration that defines:

  • Which executor to use (executor_type: CLAUDE_CODE, CURSOR, etc.)
  • System prompt and append prompt
  • Model and parameters (temperature, max_tokens)
  • MCP servers and skills configuration

Important Concept Distinction:

  • Agent: User-created configuration file, stored in .viben/agents/, editable
  • Executor: Underlying AI tool runtime (Claude Code, Cursor, etc.), managed via /api/executors, read-only

Agents specify which executor to use via the executor_type field.

Endpoint List

Basic CRUD

MethodPathDescription
GET/api/agentList all agents
POST/api/agentCreate Viben agent
GET/api/agent/:idGet agent details
PATCH/api/agent/:idUpdate Viben agent
DELETE/api/agent/:idDelete Viben agent

Default Agent

MethodPathDescription
GET/api/agent/defaultGet default agent ID
PUT/api/agent/defaultSet default agent

Template Management

MethodPathDescription
GET/api/agent/templatesList all templates
GET/api/agent/templates/:idGet template details
POST/api/agent/templatesCreate template from agent
POST/api/agent/templates/:id/instantiateCreate agent from template

Availability Check

MethodPathDescription
GET/api/agent/:id/availabilityCheck agent availability

Process Management

MethodPathDescription
POST/api/agent/:id/spawnStart agent process
POST/api/agent/:id/stopStop agent process

Session Management

MethodPathDescription
GET/api/agent/:id/sessionsList sessions
POST/api/agent/:id/sessionsCreate session
GET/api/agent/:id/sessions/:sidGet session details
DELETE/api/agent/:id/sessions/:sidDelete session

Message Management

MethodPathDescription
GET/api/agent/:id/sessions/:sid/messagesList messages
POST/api/agent/:id/sessions/:sid/messagesAdd message
GET/api/agent/:id/sessions/:sid/ui-messagesGet UI messages

History

MethodPathDescription
GET/api/agent/:id/historyGet history records
POST/api/agent/:id/historyAdd history record
GET/api/agent/:id/history/statsGet history statistics
DELETE/api/agent/:id/historyClear history

Detailed Description

GET /api/agent

List all user-created agents.

info

This API returns only agents (user-created configurations), not executors. Executors are managed separately via /api/executors.

Query Parameters:

ParameterTypeRequiredDefaultDescription
workspace_pathstringNo-Workspace path
include_globalboolNotrueInclude global agents

Response:

{
"agents": [
{
"id": "my-agent",
"name": "My Agent",
"executor_type": "CLAUDE_CODE",
"model": "claude-3-sonnet",
"description": "A helpful coding assistant",
"source": "global",
"config_path": "~/.viben/agents/my-agent/config.yaml",
"is_available": true
},
{
"id": "project-helper",
"name": "Project Helper",
"executor_type": "CURSOR",
"model": "gpt-4",
"description": "Project-specific assistant",
"source": "workspace",
"workspace_path": "/path/to/project",
"config_path": "/path/to/project/.viben/agents/project-helper/config.yaml",
"is_available": true
}
]
}

Agent Response Fields:

FieldTypeDescription
idstringAgent ID
namestringAgent name
executor_typestringExecutor type (e.g., CLAUDE_CODE, CURSOR)
modelstringModel ID
descriptionstringAgent description
sourcestringAgent source (global or workspace)
config_pathstringPath to the agent's config.yaml file
workspace_pathstringWorkspace path (only for workspace-scoped agents)
is_availablebooleanWhether the agent's executor is available

POST /api/agent

Create a new Viben agent.

Request Body:

{
"name": "My Agent",
"id": "my-agent",
"description": "A helpful coding assistant",
"model": "claude-3-sonnet",
"provider": "anthropic",
"system_prompt": "You are a helpful assistant.",
"temperature": 0.7,
"max_tokens": 4096,
"from_template": "coding-assistant",
"base_path": "/path/to/workspace"
}
FieldTypeRequiredDescription
namestringYesAgent name
idstringNoAgent ID (auto-generated)
descriptionstringNoDescription
modelstringNoModel ID
providerstringNoProvider ID
system_promptstringNoSystem prompt
temperaturefloatNoTemperature parameter
max_tokensintNoMaximum tokens
from_templatestringNoCreate from template
base_pathstringNoStorage path

Response: Created agent details


GET /api/agent/:id

Get agent details. Supports both Viben agents and Executor agents.

Path Parameters:

  • id: Agent ID or Executor type (e.g., CLAUDE_CODE)

Response (Viben Agent):

{
"id": "my-agent",
"name": "My Agent",
"description": "A helpful assistant",
"model": "claude-3-sonnet",
"provider": "anthropic",
"system_prompt": "You are helpful.",
"temperature": 0.7,
"max_tokens": 4096,
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}

Response (Executor Agent):

{
"id": "CLAUDE_CODE",
"name": "Claude Code",
"type": "executor",
"is_available": true,
"availability": {
"available": true,
"reason": null
},
"supports_mcp": true,
"features": ["chat", "code", "tools", "streaming"]
}

POST /api/agent/:id/spawn

Start an agent process.

Request Body:

{
"prompt": "Analyze this code",
"workdir": "/path/to/project",
"session_id": "optional-session-id"
}
FieldTypeRequiredDescription
promptstringYesPrompt
workdirstringYesWorking directory
session_idstringNoSession ID

Response:

{
"success": true,
"session_id": "abc123",
"pid": 12345
}

POST /api/agent/:id/stop

Stop an agent process.

Request Body:

{
"session_id": "abc123"
}

Response:

{
"success": true
}

GET /api/agent/:id/sessions/:sid/ui-messages

Get UI-friendly message list for frontend rendering.

Response:

{
"messages": [
{
"id": "msg-1",
"role": "user",
"content": "Hello",
"timestamp": "2024-01-01T10:00:00Z"
},
{
"id": "msg-2",
"role": "assistant",
"content": "Hi! How can I help?",
"timestamp": "2024-01-01T10:00:05Z",
"tool_calls": []
}
]
}

GET /api/agent/:id/history

Get agent history records.

Query Parameters:

ParameterTypeRequiredDefaultDescription
limitintNo50Number of records to return
searchstringNo-Search keyword

Response:

{
"records": [
{
"id": "record-1",
"prompt": "Write a function",
"response_preview": "Here's a function...",
"created_at": "2024-01-01T10:00:00Z",
"tokens": {
"input": 50,
"output": 200
}
}
],
"total": 100
}

Agent Types

Viben Agents

User-defined agents stored in:

  • Global: ~/.viben/agents/<id>/config.yaml
  • Workspace: <workspace>/.viben/agents/<id>/config.yaml

Executor Types (executor_type)

Agents specify which executor to use via the executor_type field. All executor types use uppercase format:

executor_typeExecutorDescription
CLAUDE_CODEClaude CodeAnthropic Claude Code CLI
AMPAMPAMP coding agent
GEMINIGeminiGoogle Gemini CLI
CODEXCodexOpenAI Codex
CURSORCursorCursor IDE agent
QWEN_CODEQwen CodeQwen coding agent
COPILOTCopilotGitHub Copilot
note

Executors themselves are managed via the Executor API. Agents only reference an executor type.