BuildContext management

Context management

⚠️
Preview — this feature is being built; the design below is the spec.

Long agent runs keep adding to the conversation: tool results, file contents, search pages. Eventually the conversation no longer fits in the model’s context window, or each round becomes expensive. Context management lets the server keep it in bounds for you, with two opt-in strategies:

StrategyWhat it does
Clear old tool resultsReplaces the content of older tool results with a short placeholder. The calls stay, so the model knows what it did.
CompactionWhen the conversation passes a size you set, earlier turns are replaced by a summary the model writes, and the run carries on.

Both are off unless you ask for them.

When to use it

  • Agents that run for dozens of rounds.
  • Workflows that read many large files or web pages.
  • Chats that should be able to go on indefinitely.

If you need full control over what is kept, trim the history yourself with token counting instead.

Endpoint and auth

POST https://app.syntic.ai/v1/chat/completions (and Messages), Authorization: Bearer sk_live_....

Request fields

FieldTypeDefaultDetails
context_management.clear_tool_results.enabledbooleanfalseTurn on clearing.
context_management.clear_tool_results.trigger_tokensinteger100,000Start clearing once the input passes this size.
context_management.clear_tool_results.keep_recentinteger3Always keep the newest this-many tool results in full.
context_management.clear_tool_results.exclude_toolsarray of strings[]Tool names whose results are never cleared.
context_management.compact.enabledbooleanfalseTurn on compaction.
context_management.compact.trigger_tokensinteger150,000Compact once the input passes this size. Minimum 20,000.
context_management.compact.instructionsstringnoneExtra guidance for the summary, for example “Keep every file path and decision.”

Clearing runs first; compaction runs only if the conversation is still over its trigger.

What comes back

The changes are applied to the model’s view of the conversation for this request. Your own copy of messages is not edited, so the response tells you what happened and gives you what you need to continue cheaply:

{
  "choices": [{ "index": 0, "message": { "role": "assistant", "content": "Next I will update the tests." }, "finish_reason": "stop" }],
  "context_management": {
    "applied": ["clear_tool_results", "compact"],
    "cleared_tool_results": 14,
    "cleared_tokens": 61200,
    "compaction": {
      "summary": "The user asked to migrate the billing module... Files changed so far: ...",
      "replaced_messages": 38,
      "tokens_before": 172400,
      "tokens_after": 23100
    }
  },
  "usage": { "prompt_tokens": 23100, "completion_tokens": 18, "total_tokens": 23118 }
}

To continue, replace the messages that were compacted with one assistant message holding a compaction part:

{ "role": "assistant", "content": [{ "type": "compaction", "summary": "The user asked to migrate the billing module..." }] }

On Messages, a compaction block appears at the start of content instead.

Streaming

A context_management object arrives on the first chunk, before any text, so a UI can show “Earlier conversation summarised”.

Examples

curl https://app.syntic.ai/v1/chat/completions \
  -H "Authorization: Bearer $SYNTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "Syntic Code",
    "stream": false,
    "context_management": {
      "clear_tool_results": { "enabled": true, "keep_recent": 5, "exclude_tools": ["read_plan"] },
      "compact": { "enabled": true, "trigger_tokens": 150000, "instructions": "Keep every file path and test result." }
    },
    "tools": [ ... ],
    "messages": [ ... ]
  }'

Errors

Unified envelope.

StatuscodeCause
400invalid_context_managementUnknown key or value out of range. param names it.
400context_window_exceededStill too large after clearing and compaction (for example a single message bigger than the window).

Cost

  • Clearing is free and reduces input tokens.
  • Compaction runs one extra model call to write the summary, billed as normal input and output and shown in usage.context_management_tokens.
  • Clearing or compacting changes the beginning of the prompt, so the next request has fewer cache hits. Set triggers high enough that it happens rarely.

Build notes for the platform team

  • Reference design: the condensing logic in Syntic Code (our own code). Never summarise the system message or the newest user turn.
  • Run the summary with the same model unless it lacks capacity, then fall back to Amara S1.2.
  • Never remove a tool call while keeping its result, or the reverse.
Was this page helpful?