Skip to content

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"]}'
  • tools is 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_turns and 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"}'
FieldWhat it is
messageWhat the customer says.
client_idThe 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.
historyThe previous messages, when you keep the conversation.
approvalsAnswers to writes the agent is waiting on: [{"ref": "...", "approved": true, "scope": "once"}].
attachmentsIds of files uploaded with POST /v1/projects/{id}/attachments.
modelOne of the models the agent may run on (GET .../agents/{agentRef}/models).

The answer:

FieldWhat it is
textThe agent's reply.
callsThe tools it called, with their arguments and answers.
session_idThe stored conversation, when there is one.
historyThe conversation so far, when you keep it.
pendingWrites waiting for approval: ref, tool, arguments.
model, model_fallbackThe model that answered, and whether a fallback stepped in.
duration_msHow 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:

typeWhen
sessionOnce at the start, with the conversation's id.
text_deltaAs the model writes text.
tool_callWhen the model calls a tool.
choicesWhen the model asks the person a question with options to pick.
pendingWhen the turn paused for a person to approve a write.
errorThe turn failed.
doneThe 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.