context::assemble
Build the model-ready context (system prompt + budgeted messages) from a history; applies prune and/or compaction as needed to fit the model's usable token budget.
- messagesone of[]
Full candidate history, oldest first.
one of (4)variant 1- contentone of[]required
… expand 5 nestedcollapse
one of (5)variant 1- textstringrequired
- typestringrequiredenum: text
variant 2- datastringrequired
Base64-encoded image bytes.
- mimestringrequired
MIME type, e.g. `image/png`.
- typestringrequiredenum: image
variant 3- signaturestring
- textstringrequired
- typestringrequiredenum: thinking
variant 4- argumentsunknown
Model-produced arguments (JSON).
- function_idstringrequired
The iii function id to invoke.
- idstringrequired
Unique per call, echoed by the result.
- typestringrequiredenum: function_call
variant 5- contentunknown[]required
- function_call_idstringrequired
- is_errorboolean
- typestringrequiredenum: function_result
- rolestringrequiredenum: user
- timestampinteger· int64required
Milliseconds since epoch.
variant 2- contentone of[]required
… expand 5 nestedcollapse
one of (5)variant 1- textstringrequired
- typestringrequiredenum: text
variant 2- datastringrequired
Base64-encoded image bytes.
- mimestringrequired
MIME type, e.g. `image/png`.
- typestringrequiredenum: image
variant 3- signaturestring
- textstringrequired
- typestringrequiredenum: thinking
variant 4- argumentsunknown
Model-produced arguments (JSON).
- function_idstringrequired
The iii function id to invoke.
- idstringrequired
Unique per call, echoed by the result.
- typestringrequiredenum: function_call
variant 5- contentunknown[]required
- function_call_idstringrequired
- is_errorboolean
- typestringrequiredenum: function_result
- error_kindany of
… expand 2 nestedcollapse
any of (2)variant 1valuestringenum: auth_expired, rate_limited, context_overflow, transient, permanentvariant 2valuenull - error_messagestring
- modelstringrequired
- native_stop_reasonstring
Provider's raw finish reason, passed through untouched.
- providerstringrequired
- rolestringrequiredenum: assistant
- stop_reasonstringrequiredenum: end, length, function_call, aborted, error
Why an assistant message stopped generating.
- timestampinteger· int64required
Milliseconds since epoch.
- usageany of
… expand 2 nestedcollapse
any of (2)variant 1- cache_readinteger· uint64min 0
- cache_writeinteger· uint64min 0
- cost_usdnumber· double
- inputinteger· uint64min 0
- outputinteger· uint64min 0
- reasoninginteger· uint64min 0
variant 2valuenull - warningsstring[]
Report-and-continue notices (e.g. dropped unsupported param).
variant 3- contentone of[]required
… expand 5 nestedcollapse
one of (5)variant 1- textstringrequired
- typestringrequiredenum: text
variant 2- datastringrequired
Base64-encoded image bytes.
- mimestringrequired
MIME type, e.g. `image/png`.
- typestringrequiredenum: image
variant 3- signaturestring
- textstringrequired
- typestringrequiredenum: thinking
variant 4- argumentsunknown
Model-produced arguments (JSON).
- function_idstringrequired
The iii function id to invoke.
- idstringrequired
Unique per call, echoed by the result.
- typestringrequiredenum: function_call
variant 5- contentunknown[]required
- function_call_idstringrequired
- is_errorboolean
- typestringrequiredenum: function_result
- detailsunknown
Opaque structured payload kept alongside the rendered content.
- function_call_idstringrequired
Echoes the `function_call` block id this result answers.
- function_idstringrequired
- is_errorboolean
- rolestringrequiredenum: function_result
- timestampinteger· int64required
Milliseconds since epoch.
variant 4- contentone of[]required
… expand 5 nestedcollapse
one of (5)variant 1- textstringrequired
- typestringrequiredenum: text
variant 2- datastringrequired
Base64-encoded image bytes.
- mimestringrequired
MIME type, e.g. `image/png`.
- typestringrequiredenum: image
variant 3- signaturestring
- textstringrequired
- typestringrequiredenum: thinking
variant 4- argumentsunknown
Model-produced arguments (JSON).
- function_idstringrequired
The iii function id to invoke.
- idstringrequired
Unique per call, echoed by the result.
- typestringrequiredenum: function_call
variant 5- contentunknown[]required
- function_call_idstringrequired
- is_errorboolean
- typestringrequiredenum: function_result
- custom_typestringrequired
App-defined discriminator.
- detailsunknown
- displaystring
- rolestringrequiredenum: custom
- timestampinteger· int64required
Milliseconds since epoch.
- modelobjectrequired
How callers identify the target model (context-manager.md § Model input). Inline `limits` keep the call standalone; `id`/`provider` alone defer limit resolution to `router::models::budget`.
- idstringrequired
Model id, e.g. `claude-sonnet-4`.
- limitsany of
Inline token limits; when present no router lookup happens.
any of (2)variant 1- context_windowinteger· uint64requiredmin 0
Total context window in tokens.
- input_limitinteger· uint64min 0
Usable input budget when distinct from `context_window`.
- max_output_tokensinteger· uint64requiredmin 0
Maximum output tokens the model can produce per call.
variant 2valuenull - providerstring
Provider id, e.g. `anthropic`; disambiguates when a model id exists on multiple providers.
- optionsany ofany of (2)variant 1
- allow_compactionboolean
Default true.
- allow_pruneboolean
Default true.
- lease_keystring
Compaction mutual-exclusion key (e.g. a session id); default: hash of the message set.
- previous_summarystring
Persisted summary from a prior compaction (see the spec's "The compaction round trip"); rendered into the system prompt and used as the anchor if compaction triggers again.
- protected_functionsstring[]
`function_id`s exempt from the normal prune pass. Emergency safety reduction may still replace their oversized results.
- request_overhead_tokensinteger· uint64min 0
Estimated tokens for final provider request fields and framing not otherwise represented by the prompt, messages, or tools.
- reserved_tokensinteger· uint64min 0
Override the default reserve (`min(20000, 10% of context_window)`).
- tail_turnsinteger· uintmin 0
user+assistant pairs always kept verbatim (default 2).
- thinking_levelany of
Reserve the model's thinking budget for this tier.
… expand 2 nestedcollapse
any of (2)variant 1valuestringenum: minimal, low, medium, high, xhighvariant 2valuenull
variant 2valuenull - system_promptstring
Base system prompt to prepend/merge.
- toolsobject[]
Model-facing invocation schemas included in every budget count.
- descriptionstringrequired
- execution_modeany ofany of (2)variant 1valuestringenum: parallel, sequentialvariant 2valuenull
- labelstring
- namestringrequired
Invocation surface name (`agent_trigger`, `submit_result`, or a function id in native exposure mode).
- parametersunknown
JSON Schema for the function parameters.
- appliedobjectrequired
What the pipeline actually did this call.
- compactedbooleanrequired
- initial_token_countinteger· uint64requiredmin 0
Full estimated request size before pruning or compaction, including the system prompt, tool schemas, and provider framing overhead.
- prunedbooleanrequired
- pruned_tokensinteger· uint64requiredmin 0
- summarized_head_tokensinteger· uint64min 0
Unambiguous alias for `tokens_before`; retained separately so callers do not mistake the summarised head for the full pre-compaction request.
- summarystring
Present when compacted; the caller should persist it and pass it back as `options.previous_summary` (compaction round trip).
- tail_start_indexinteger· uintmin 0
Present when compacted: index into the request messages where the verbatim tail begins (`null` = everything was summarised).
- tokens_beforeinteger· uint64min 0
Present when compacted: estimated tokens of the summarised head.
- effective_max_output_tokensinteger· uint64requiredmin 0
Effective output allocation used to derive `usable`. This is the router-resolved request limit, not the model catalog ceiling.
- messagesone of[]required
Budgeted, ready to send to llm-router.
one of (4)variant 1- contentone of[]required
… expand 5 nestedcollapse
one of (5)variant 1- textstringrequired
- typestringrequiredenum: text
variant 2- datastringrequired
Base64-encoded image bytes.
- mimestringrequired
MIME type, e.g. `image/png`.
- typestringrequiredenum: image
variant 3- signaturestring
- textstringrequired
- typestringrequiredenum: thinking
variant 4- argumentsunknown
Model-produced arguments (JSON).
- function_idstringrequired
The iii function id to invoke.
- idstringrequired
Unique per call, echoed by the result.
- typestringrequiredenum: function_call
variant 5- contentunknown[]required
- function_call_idstringrequired
- is_errorboolean
- typestringrequiredenum: function_result
- rolestringrequiredenum: user
- timestampinteger· int64required
Milliseconds since epoch.
variant 2- contentone of[]required
… expand 5 nestedcollapse
one of (5)variant 1- textstringrequired
- typestringrequiredenum: text
variant 2- datastringrequired
Base64-encoded image bytes.
- mimestringrequired
MIME type, e.g. `image/png`.
- typestringrequiredenum: image
variant 3- signaturestring
- textstringrequired
- typestringrequiredenum: thinking
variant 4- argumentsunknown
Model-produced arguments (JSON).
- function_idstringrequired
The iii function id to invoke.
- idstringrequired
Unique per call, echoed by the result.
- typestringrequiredenum: function_call
variant 5- contentunknown[]required
- function_call_idstringrequired
- is_errorboolean
- typestringrequiredenum: function_result
- error_kindany of
… expand 2 nestedcollapse
any of (2)variant 1valuestringenum: auth_expired, rate_limited, context_overflow, transient, permanentvariant 2valuenull - error_messagestring
- modelstringrequired
- native_stop_reasonstring
Provider's raw finish reason, passed through untouched.
- providerstringrequired
- rolestringrequiredenum: assistant
- stop_reasonstringrequiredenum: end, length, function_call, aborted, error
Why an assistant message stopped generating.
- timestampinteger· int64required
Milliseconds since epoch.
- usageany of
… expand 2 nestedcollapse
any of (2)variant 1- cache_readinteger· uint64min 0
- cache_writeinteger· uint64min 0
- cost_usdnumber· double
- inputinteger· uint64min 0
- outputinteger· uint64min 0
- reasoninginteger· uint64min 0
variant 2valuenull - warningsstring[]
Report-and-continue notices (e.g. dropped unsupported param).
variant 3- contentone of[]required
… expand 5 nestedcollapse
one of (5)variant 1- textstringrequired
- typestringrequiredenum: text
variant 2- datastringrequired
Base64-encoded image bytes.
- mimestringrequired
MIME type, e.g. `image/png`.
- typestringrequiredenum: image
variant 3- signaturestring
- textstringrequired
- typestringrequiredenum: thinking
variant 4- argumentsunknown
Model-produced arguments (JSON).
- function_idstringrequired
The iii function id to invoke.
- idstringrequired
Unique per call, echoed by the result.
- typestringrequiredenum: function_call
variant 5- contentunknown[]required
- function_call_idstringrequired
- is_errorboolean
- typestringrequiredenum: function_result
- detailsunknown
Opaque structured payload kept alongside the rendered content.
- function_call_idstringrequired
Echoes the `function_call` block id this result answers.
- function_idstringrequired
- is_errorboolean
- rolestringrequiredenum: function_result
- timestampinteger· int64required
Milliseconds since epoch.
variant 4- contentone of[]required
… expand 5 nestedcollapse
one of (5)variant 1- textstringrequired
- typestringrequiredenum: text
variant 2- datastringrequired
Base64-encoded image bytes.
- mimestringrequired
MIME type, e.g. `image/png`.
- typestringrequiredenum: image
variant 3- signaturestring
- textstringrequired
- typestringrequiredenum: thinking
variant 4- argumentsunknown
Model-produced arguments (JSON).
- function_idstringrequired
The iii function id to invoke.
- idstringrequired
Unique per call, echoed by the result.
- typestringrequiredenum: function_call
variant 5- contentunknown[]required
- function_call_idstringrequired
- is_errorboolean
- typestringrequiredenum: function_result
- custom_typestringrequired
App-defined discriminator.
- detailsunknown
- displaystring
- rolestringrequiredenum: custom
- timestampinteger· int64required
Milliseconds since epoch.
- model_resolvedstringrequiredenum: inline, router, fallback
How the model limits were resolved.
- system_promptstringrequired
- token_countinteger· uint64requiredmin 0
Estimated tokens of the returned context, including the system prompt, tools, and request overhead. Always at most `usable`.
- usableinteger· uint64requiredmin 0
The budget the context was fit into.