ExAgent. UsageLimits. WrapUp
(ExAgent v3.0.0)
View Source
Use the next admissible request for a final answer when a run approaches a configured limit.
Stability — Candidate.
limits = %ExAgent.UsageLimits{request_limit: 4}
wrap_up = ExAgent.UsageLimits.WrapUp.new()
agent = ExAgent.new(model: model, usage_limits: limits, capabilities: [wrap_up])Add this capability after other request-shaping capabilities. It appends a host instruction to the outgoing messages and drops function tools. Any structured output tool remains available. The closing request goes through the usual model admission and output checks. The run stops if those checks would otherwise cause another model request.
The capability supports buffered, streamed and standalone C7 runs. A closing request in durable Composition or Flow hits the workflow's existing request-projection gate. C7 records the closing projection with the model intent. Authorized recovery uses that projection, with the usual C7 uncertainty rules. A retry needs another request slot, including when the lost closing request used the final slot.
A delegated child shares its ancestor's request limit. In a single
delegation chain, set :remaining_requests to one plus the number of
ancestors that still need a final request.
Summary
Functions
Set the headroom that triggers wrap-up. Each margin can be nil to ignore
that dimension. :remaining_requests defaults to 1 and accepts positive
integers. :remaining_tokens (128) and :remaining_tool_calls (0) accept
nonnegative integers. A token margin applies to each configured token bound.
:remaining_budget_cents (1) accepts nonnegative cents, and
:remaining_ms (1000) accepts nonnegative milliseconds before the deadline.
The optional :instruction is UTF-8 text of at most 1,024 bytes.
Return the limit that prompted a closing response retained in the result,
or nil. Telemetry reports selection of the closing request, even if
admission or output processing later fails. It emits
[:exagent, :usage_limits, :wrap_up] with :run_id and :reason.
Types
Functions
Set the headroom that triggers wrap-up. Each margin can be nil to ignore
that dimension. :remaining_requests defaults to 1 and accepts positive
integers. :remaining_tokens (128) and :remaining_tool_calls (0) accept
nonnegative integers. A token margin applies to each configured token bound.
:remaining_budget_cents (1) accepts nonnegative cents, and
:remaining_ms (1000) accepts nonnegative milliseconds before the deadline.
The optional :instruction is UTF-8 text of at most 1,024 bytes.
The capability uses the limits effective in the execution tree, including a tighter run override. A known subtotal can trigger an early finish. The regular hard limits still apply. A request that crosses a hard limit can fail before there is another opportunity to close.
@spec reason(ExAgent.Result.t()) :: reason() | nil
Return the limit that prompted a closing response retained in the result,
or nil. Telemetry reports selection of the closing request, even if
admission or output processing later fails. It emits
[:exagent, :usage_limits, :wrap_up] with :run_id and :reason.