Expand description
SCV’s provider-independent agent loop and the traits it is built from.
AgentRuntime::run_turn runs one user turn: it selects the history the
model sees, asks the Provider for a response, runs the requested
Tools in order through the ApprovalGate, and repeats until the model
answers without tool calls, reporting everything to an EventSink.
ContextPolicy decides what history fits. This crate knows no concrete
provider, tool, transport, or user interface; those live in the crates
that depend on it.
Structs§
- Agent
Config - Settings of an
AgentRuntime. - Agent
Runtime - Runs user turns against one provider, tool registry, and context policy.
- Approval
Request - Assistant
Response - The model’s complete answer to one request.
- Budget
Context Policy - Keeps the newest whole turns that fit
ContextConfig’s budget and replaces older history with one bounded summary note. - Context
Config - The token budget of
BudgetContextPolicy. Tokens are estimated from serialized bytes, not counted by a tokenizer. - Context
Error - Why no selection fits: the budget is too small even for the newest turn, or for the system prompt and tool schemas alone.
- Context
Selection - The messages chosen for one model request, and what compaction cost.
- History
Limits - Image
Input - An image file shown to the model with a user message.
- Progress
Sink - Where a running tool reports short status lines, such as a delegated agent’s commands. Each report becomes one bounded line; the runtime forwards the pending lines to the client at most twice a second and never adds them to the model’s history. The default sink discards reports, so a tool may always report.
- Provider
Error - Provider
Request - One model request: the system prompt, the selected history, and the tools.
- Tool
Approvals - The session’s approval gate as seen by one running tool call. A tool that drives a nested agent (such as another SCV) asks it on the nested agent’s behalf, so the session’s policy and its user decide every nested side effect too. Without a gate, every request is denied.
- Tool
Call - Tool
Context - What a running tool call gets besides its arguments.
- Tool
Error - A tool call that could not run, such as invalid arguments. The runtime
turns it into a failed
ToolOutputwhose content ismessage. - Tool
Output - A tool’s result as the model sees it. A failure is still a result: the model reads it and can react.
- Tool
Registry - The tools of one session, by unique name.
- Tool
Spec - What the model is told about a tool: its name, what it does, and the JSON Schema of its arguments.
- Turn
Input - The user’s side of a turn: text, and images for a model that accepts them.
- Turn
Outcome - How a completed turn went: model requests made, and tokens used.
- Usage
- Token counts a provider reported;
Nonewhen it reported none.
Enums§
- Agent
Error - Why a turn failed. The server maps each variant to a stable wire code.
- Core
Event - Message
- Provider
Error Kind - What kind of failure a
ProviderErroris; the runtime maps each to anAgentError. - Tool
Failure - Why a tool call failed. The model reads the call’s output either way; this tells the session’s clients what happened without reading the text.
- Tool
Risk - How much a tool call can affect; the approval policy decides per risk.
Constants§
- MAX_
PROGRESS_ EVENT_ BYTES - Largest progress event: the newest lines reported since the previous event, with older ones dropped first.
- MAX_
PROGRESS_ LINE_ BYTES - Longest progress line a tool can report; longer lines are cut.
Traits§
- Approval
Gate - Context
Policy - Decides which history messages go into each model request.
- Event
Sink - Provider
- A model backend.
completesends one request, streams text deltas todeltas, and returns the full answer with any tool calls. It must stop promptly whencancellationfires. - Text
Delta Sink - Where a provider streams answer text as it arrives. An error from
pushmeans stop: the turn was cancelled or hit a limit. - Tool
- Something the model can call. The runtime asks for the call’s
riskandapproval_summaryfirst, so both must validate the arguments without side effects; only an approved call reachesexecute.