The Agents API provides full lifecycle management for OpenFang agents: spawning, messaging, session management, configuration updates, and termination.
List Agents
curl http://127.0.0.1:4200/api/agents
List of running agents Agent state: Running, Stopped, Errored
Operating mode: Normal or Stable
LLM provider (e.g., groq, anthropic)
Model ID (e.g., llama-3.3-70b-versatile)
Model tier: frontier, smart, fast, or unknown
Provider auth status: configured, missing, or unknown
true if agent is running AND provider is authenticated
Get Agent Details
curl http://127.0.0.1:4200/api/agents/{id}
Spawn Agent
Create a new agent from a TOML manifest.
curl -X POST http://127.0.0.1:4200/api/agents \
-H "Content-Type: application/json" \
-d '{
"manifest_toml": "name = \"my-agent\"\nversion = \"0.1.0\"\ndescription = \"Test agent\"\nauthor = \"me\"\nmodule = \"builtin:chat\"\n\n[model]\nprovider = \"groq\"\nmodel = \"llama-3.3-70b-versatile\"\n\n[capabilities]\ntools = [\"file_read\", \"web_fetch\"]\nmemory_read = [\"*\"]\nmemory_write = [\"self.*\"]\n"
}'
Agent manifest in TOML format (max 1MB)
Optional Ed25519-signed manifest JSON for verification
UUID of the newly spawned agent
{
"agent_id" : "a1b2c3d4-e5f6-7890-abcd-ef1234567890" ,
"name" : "my-agent"
}
Send Message
Send a message to an agent and receive the complete response.
curl -X POST http://127.0.0.1:4200/api/agents/{id}/message \
-H "Content-Type: application/json" \
-d '{"message": "What files are in the current directory?"}'
Optional file attachments MIME type (e.g., image/png)
Agent’s complete text response
Total input tokens consumed
Total output tokens generated
Number of LLM iterations (agentic loops)
{
"response" : "Here are the files in the current directory: \n - Cargo.toml \n - README.md \n - src/ \n " ,
"input_tokens" : 142 ,
"output_tokens" : 87 ,
"iterations" : 1 ,
"cost_usd" : 0.0012
}
Stream Message (SSE)
Send a message and receive a token-by-token streaming response.
curl -X POST http://127.0.0.1:4200/api/agents/{id}/message/stream \
-H "Content-Type: application/json" \
-d '{"message": "Explain quantum computing"}'
SSE Event Types:
Text delta from the LLM { "content" : "Quantum" , "done" : false }
Tool invocation completed { "tool" : "web_search" , "input" : { "query" : "quantum computing basics" }}
Final event with token usage { "done" : true , "usage" : { "input_tokens" : 150 , "output_tokens" : 340 }}
Get Session History
Retrieve an agent’s conversation history.
curl http://127.0.0.1:4200/api/agents/{id}/session
Total messages in session
Current context window size
Conversation messages User, Assistant, or System
Tool invocations in this message Tool output (truncated to 2000 chars)
true if tool execution failed
Update Agent Configuration
Update an agent’s description, system prompt, or tags at runtime.
curl -X PUT http://127.0.0.1:4200/api/agents/{id}/update \
-H "Content-Type: application/json" \
-d '{
"description": "Updated description",
"system_prompt": "You are a specialized assistant.",
"tags": ["updated", "v2"]
}'
{
"status" : "updated" ,
"agent_id" : "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
Set Agent Mode
Switch an agent between Normal and Stable modes.
Stable mode:
Pins the current model (prevents auto-upgrades)
Freezes the skill registry (no new skills)
Useful for production deployments
curl -X PUT http://127.0.0.1:4200/api/agents/{id}/mode \
-H "Content-Type: application/json" \
-d '{"mode": "Stable"}'
Switch Model
Change an agent’s LLM model at runtime.
curl -X PUT http://127.0.0.1:4200/api/agents/{id}/model \
-H "Content-Type: application/json" \
-d '{"model": "claude-sonnet-4-20250514"}'
Model ID or alias (e.g., sonnet, gpt4, llama)
{
"status" : "updated" ,
"model" : "claude-sonnet-4-20250514"
}
Reset Session
Clear an agent’s conversation history.
curl -X POST http://127.0.0.1:4200/api/agents/{id}/session/reset
{
"status" : "reset" ,
"agent_id" : "a1b2c3d4-e5f6-7890-abcd-ef1234567890" ,
"new_session_id" : "s5e6f7g8-h9i0-1234-jklm-nopqrstuv567"
}
Compact Session
Trigger LLM-based session compaction (summarizes old messages to reduce context window usage).
curl -X POST http://127.0.0.1:4200/api/agents/{id}/session/compact
{
"status" : "compacted" ,
"message" : "Session compacted: 80 messages summarized, 20 kept"
}
Stop Agent Run
Cancel the agent’s current LLM generation.
curl -X POST http://127.0.0.1:4200/api/agents/{id}/stop
{
"status" : "stopped" ,
"message" : "Agent run cancelled"
}
Delete Agent
Terminate an agent and remove it from the registry.
curl -X DELETE http://127.0.0.1:4200/api/agents/{id}
{
"status" : "killed" ,
"agent_id" : "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
WebSocket Connection
Connect to an agent via WebSocket for real-time bidirectional chat.
const ws = new WebSocket ( 'ws://127.0.0.1:4200/api/agents/{id}/ws' )
ws . onopen = () => {
console . log ( 'Connected to agent' )
ws . send ( JSON . stringify ({ type: 'message' , content: 'Hello!' }))
}
ws . onmessage = ( event ) => {
const msg = JSON . parse ( event . data )
if ( msg . type === 'text_delta' ) {
console . log ( msg . content ) // Stream tokens as they arrive
} else if ( msg . type === 'response' ) {
console . log ( 'Complete:' , msg . content )
}
}
Message types from server:
connected — Connection established
thinking — Agent started processing
text_delta — Streaming token
tool_start — Tool invocation started
response — Complete response with usage stats
error — Error occurred
agents_updated — Agent list update (sent every 5s)
Message types from client:
{"type": "message", "content": "..."} — Send message
{"type": "ping"} — Keepalive ping
Plain text (non-JSON) — Treated as message
Chat commands (send as messages with / prefix):
/new — Start new session
/compact — Compact session
/model <name> — Switch model
/stop — Cancel current run
/usage — Show token usage
/think — Toggle extended thinking
/models — List models
/providers — List providers
Next Steps
Workflows Orchestrate multi-agent workflows
Memory Store and retrieve agent memory
Skills Extend agent capabilities
Channels Connect to messaging platforms