pub struct RunLocals { /* private fields */ }Expand description
What a turn tells its tools about who it works for — set on
TurnOptions::locals, read back with
ToolContext::run_local
(ADR-0044). Re-exported under the rule stated on CancellationToken.
Values a host attaches to one run, for the tools that run calls to read.
The per-run sibling of Runtime::app_context.
An app context is the runtime’s, so every run on it reads the same value —
right for a client handle, wrong for who this run works for. A host that
serves many callers from one runtime and one toolset has exactly that
second kind of fact: a caller’s workspace, a tenant, a trace id. Without a
slot here it either opens a toolset per caller or keys a side table by
agent id; with one, it attaches the value to the run and the tool reads it
back through ToolContext::run_local.
Keyed by type, at most one value per type, as app_context is: a host
wraps a bare String in a newtype of its own so two hosts’ strings cannot
collide. Values are Arced and the map is copy-on-write, so cloning a
RunOptions — which the runner does freely — costs one reference count.
Inherited by RunOptions::child: a
delegated run works for the same caller as the run that delegated it, and
a tool the child calls has to see the same answer.
Implementations§
Source§impl RunLocals
impl RunLocals
pub fn new() -> RunLocals
Sourcepub fn with<T>(self, value: T) -> RunLocals
pub fn with<T>(self, value: T) -> RunLocals
Attaches value, replacing any value of the same type.
Sourcepub fn with_arc<T>(self, value: Arc<T>) -> RunLocals
pub fn with_arc<T>(self, value: Arc<T>) -> RunLocals
Attaches a value the host already shares, replacing any value of the same type.