Appearance
Agents API
An agent is a model with instructions, your project's tools and skills, and rules. Agents answer in the chat widget, the Telegram bot and voice calls; your own code runs them through the API, with a project API key. A turn follows the environment's write policy, redaction and audit, like every other channel.
Defining an agent
Managers create agents in the dashboard or with POST /v1/projects/{id}/agents:
bash
curl -X POST "https://api.frege.io/v1/projects/$PROJECT/agents" \
-H "Authorization: Bearer $TOKEN" -H "X-Frege-Stage: staging" \
-H "Content-Type: application/json" \
-d '{"name": "Support", "instructions": "Help customers with their orders.", "tools": ["listOrders", "getOrder"]}'toolsis an allow-list. An agent starts with no tools, so a tool your spec gains later is not handed to it.["$all"]gives every tool the environment has at that moment: a snapshot, not a live grant.- Tool names not in the spec are accepted and reported back in
unknown_tools, so an agent can be defined before its spec. model,fallback_model,skills,guardrail_ids,subagents,max_turnsand the voice settings are optional.
GET /v1/projects/{id}/agents lists them; an agent is addressed by its id.
Running a turn
bash
curl -X POST "https://api.frege.io/v1/projects/$PROJECT/agents/$AGENT/run" \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d '{"message": "Where is my last order?", "client_id": 42, "session_id": "new"}'| Field | What it is |
|---|---|
message | What the customer says. |
client_id | The customer the agent acts as: one who has signed in. Required. |
session_id | "new" to have Frege keep the conversation, then the id it returns. Leave it out to keep the conversation yourself in history. |
history | The previous messages, when you keep the conversation. |
approvals | Answers to writes the agent is waiting on: [{"ref": "...", "approved": true, "scope": "once"}]. |
attachments | Ids of files uploaded with POST /v1/projects/{id}/attachments. |
model | One of the models the agent may run on (GET .../agents/{agentRef}/models). |
The answer:
| Field | What it is |
|---|---|
text | The agent's reply. |
calls | The tools it called, with their arguments and answers. |
session_id | The stored conversation, when there is one. |
history | The conversation so far, when you keep it. |
pending | Writes waiting for approval: ref, tool, arguments. |
model, model_fallback | The model that answered, and whether a fallback stepped in. |
duration_ms | How long the turn took. |
A stored conversation belongs to the customer it ran as: another customer presenting its id is refused.
Approvals
With the write policy ask, a turn that wants to write stops and lists the write in pending. Send the next turn with approvals, one per ref. scope is how far an approval reaches: once (the default, this write), conversation (every such write in this conversation) or always (for 30 days, for the one who approves).
Streaming
POST /v1/projects/{id}/agents/{agentRef}/stream takes the same body and answers with Server-Sent Events. Each frame is a JSON object on a data: line, with a type:
type | When |
|---|---|
session | Once at the start, with the conversation's id. |
text_delta | As the model writes text. |
tool_call | When the model calls a tool. |
choices | When the model asks the person a question with options to pick. |
pending | When the turn paused for a person to approve a write. |
error | The turn failed. |
done | The end, with the same body /run returns. |
The stream ends after done or error. Only the stream offers the model the question tool, because only a streamed caller can show the question and send the answer back.
bash
curl -N -X POST "https://api.frege.io/v1/projects/$PROJECT/agents/$AGENT/stream" \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{"message": "Cancel my last order", "client_id": 42, "session_id": "new"}'Files
POST /v1/projects/{id}/attachments takes one file (multipart, field file) and returns its id for the next turn's attachments. Text is read as it is and HTML loses its markup; PDFs, Office files, slides and images with text become Markdown; audio and video become their transcript (up to 14 MB or 30 minutes). A document whose text is too long for the conversation is refused, not cut.
Limits
Organization and environment limits can cap agent turns. A refused turn answers 429 too_many_requests with Retry-After. If the organization's billing is suspended, turns are refused.