Aller au contenu principal

Contextes

Files​

You can add files as context to a chat. Files are parsed and included completely in the prompt as text. Therefore, adding large or many files will break the request size limit very quickly. Audio files are sent as is to models that read audio, or transcribed: see Audio files.

Add file to context​

Call the create attachment endpoint to request a new upload URL. Then upload the file to the given URL.

POST /conversations/:conversationId/context/attachments
Content-Type: application/json
Body :
{
type: 'file'',
name: string,
mimeType: string,
size: number,
ext: string,
}

Response:
{
type: 'file'',
name: string,
mimeType: string,
size: number,
ext: string,
postURL: string,
formData: {[p: string]: any},
}

Upload your file with at postURL with the provided formData and your file content.

Once your file as been uploaded call the complete attachment endpoint to notify the system that your file is ready to be processed.

POST /conversations/:conversationId/context/attachments/:attachmentId/uploaded

Your file should now be ready to be used by your agent in your chat.

After the upload, the attachment goes from TO_UPLOAD to PROCESSING, then PROCESSED when the agent can use it, or ERROR with an errorCode.

Audio files​

Audio attachments are accepted in mp3, wav, m4a, ogg and webm (ext), up to 25 MB. Upload them like any other file. What the model receives depends on the agent's model:

  • The model reads audio (the Audio input capability on the model, and a format its provider accepts: mp3 and wav on OpenAI, with the gpt-audio models, and on vLLM; mp3, wav and ogg on Gemini): the attachment is PROCESSED right away, and the file is sent as is with the message it is attached to.
  • Otherwise, Breign transcribes the audio first, and the model receives the transcript like a parsed document. The attachment stays PROCESSING until the transcript is ready.

The transcription model is the agent's speech-to-text model, or else the organization's first OpenAI (Whisper, gpt-4o-transcribe) or Mistral (Voxtral) transcription model. Breign transcribes the audio even for a model that reads it: the following turns reuse the transcript instead of sending the file again, and a conversation behind an anonymizer only gets the transcript.

When the audio cannot be transcribed, a model that reads audio still gets the file. For any other model, the attachment goes to ERROR with one of these codes:

errorCodeMeaning
SPEECH_TO_TEXT_NOT_CONFIGUREDNo transcription model in the organization or on the agent.
AUDIO_TOO_LARGEThe audio is over 25 MB. Split or compress it (mp3).
TRANSCRIPTION_FAILEDThe transcription model returned an error.

A transcription still running after 30 minutes (for example after an API restart) is marked ERROR. Deleting the attachment also deletes its transcript.

If the agent has a bash sandbox, the text of each non-image attachment (the file itself for text formats, the parsed Markdown for documents) is also copied into the conversation's workspace, under /home/user/attachments/. The attachment then carries workspacePath and workspaceBytes. A document too large to fit in the prompt is still accepted in that case: the agent reads it from the workspace instead of failing with ATTACHMENT_TOO_LARGE. Deleting the attachment removes the copy. See Workspace files.

Context window usage​

When a turn completes, Breign records the size of the prompt of its last model call. You get it back as a contextUsage object:

  • in the message status, GET /conversations/:conversationId/messages/:messageId/status, once status is completed;
  • in the conversation returned by GET /agents/:agentId/conversations/:conversationId.
GET /conversations/:conversationId/messages/:messageId/status
Response:
{
status: 'completed',
content: string,
...
contextUsage?: {
usedTokens: number, // prompt of the turn's last model call, in tokens
contextWindow: number, // context window of the agent's model, in tokens
contextWindowConfidence: 'declared' | 'catalog' | 'fallback',
modelName?: string,
}
}
  • contextUsage is absent until a turn has been measured: treat it as unknown, not as zero.
  • contextWindowConfidence says where the window comes from: declared on the model definition, catalog known to Breign for that model, fallback an approximate default (128,000 tokens). Present fallback as an estimate.
  • The window is resolved when you read it, from the agent's current model. usedTokens does not include the reply itself.

Compact a conversation​

Send the message /compact to a conversation (POST /conversations/:conversationId/prompts). It is listed by GET /agents/:agentId/commands with source: 'predefined'. Instead of a normal answer, the agent summarises the conversation: the reply text is a confirmation followed by the summary. Earlier messages stay in the conversation history but are no longer sent to the model; the summary replaces them. This reply does not update contextUsage, which changes with the next answered message. If the summary cannot be produced, the message fails like any other turn (error code PIPELINE_ERROR).