Trait ToolSource
pub trait ToolSource:
Send
+ Sync
+ 'static {
Show 13 methods
// Required methods
fn specs<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<ToolSpec>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn call<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 ToolCtx,
name: &'life2 str,
args: Value,
) -> Pin<Box<dyn Future<Output = Option<Result<ToolOutput, ToolError>>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait;
// Provided methods
fn listing<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Listing> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn appended<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<ToolSpec>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn loaders<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<Loader>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn loaded_by_task<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<Loaded>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn loaded_tools<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Option<Vec<String>>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn instructions<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn appended_instructions<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn refine<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
specs: &'life2 mut [ToolSpec],
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait { ... }
fn withhold<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
tools: &'life2 [&'life3 str],
) -> Pin<Box<dyn Future<Output = Vec<Withheld>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait { ... }
fn access(&self, name: &str, args: &Value) -> ToolAccess { ... }
fn expects_repeat(&self, name: &str, taken: &[ToolSpec]) -> bool { ... }
}Expand description
A group of tools the agent learns about while it runs, not when it is built: what a caller says it can offer in the messages it sends (the endpoint for a thread’s tools, for instance), read again at every model turn.
A Tool has one fixed [ToolSpec]. A source lists its tools each time the
model is about to be called, and answers the calls the model makes to them, so the tools a
model sees can change from one turn to the next: a server attached to the conversation a moment
ago is offered on the next turn.
specsruns only when the model is really called. A turn whose model call is already in the journal (a replay after a crash) lists nothing and offers nothing: the recorded answer is used.callruns inside the journaled step of the call, as aTooldoes, so a recorded result is never computed again, and a call that dies before it is recorded runs again: a tool of a source must be safe to retry.- The agent’s own tools come first and win a name clash: a listed tool whose name an own tool
(or an earlier source) already has is left out, with a warning (at debug level when the source
expects the repeat). At most
MAX_SOURCE_TOOLSare offered. A source’s tools are sorted by name before that cap and those clashes, so the tools that survive the cap, and which of two same-named tools of one source is offered (the first in the listing), do not depend on the order the source lists in. - A tool of a source cannot wait on a task of another system
(
ToolError::AwaitRemote): the wait is answered with an error result, because the agent asks the tool that started it how it stands, and a source’s tool is not known by then. It can ask the person (ToolError::NeedsInput) and wait for a child run (ToolError::AwaitRun).
Sources are chosen when the binary is built (LlmAgentBuilder::tool_source),
never loaded at run time.
Required Methods§
fn specs<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<ToolSpec>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn specs<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<ToolSpec>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
The tools to offer on this model turn, besides the agent’s own. A source that cannot reach what it lists (no credential, a server that is down) offers none: a failure here must not stop the run, so there is no error to return. Say why in a log line, never with a credential in it.
fn call<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 ToolCtx,
name: &'life2 str,
args: Value,
) -> Pin<Box<dyn Future<Output = Option<Result<ToolOutput, ToolError>>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn call<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 ToolCtx,
name: &'life2 str,
args: Value,
) -> Pin<Box<dyn Future<Output = Option<Result<ToolOutput, ToolError>>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Run the tool name with args. None: this source does not offer a tool of that name,
and the next one is asked; the agent answers a name nobody owns with an error result.
A source that cannot tell whether a name is its own without asking the system behind it
(a remote list) may answer Some for any name it could have offered, with an error result
when the system refuses it; it then belongs last among the sources.
Provided Methods§
fn listing<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Listing> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn listing<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Listing> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
The tools to offer on this turn and what the source says about them (ToolNote): which
of its calls the system behind it reports as steps itself, and how long a call may run. The
agent calls this, not specs. The default is specs and no notes; a source
that has notes lists once, here, and answers specs from the same listing.
fn appended<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<ToolSpec>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn appended<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<ToolSpec>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
The tools this source’s system has given the run during itself, in the order it loaded
them, to be offered after every other tool of the turn: a load appends to the tools array
and never inserts into it, so the request before stays a byte prefix of the one after it
(ADR 0044, decision 1). A tool named here is taken out of the place it would have had (the
agent’s own list, or this source’s listing) and put at the end; the source must therefore
also stop withholding it from withhold. The order is the source’s and is
never sorted: the second load follows the first.
Read inside the journaled step of the model call, from the run’s state
(SourceCtx::loaded), so a replay offers the same array. The default is none,
which is what a source written before this method existed offers.
fn loaders<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<Loader>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn loaders<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<Loader>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
The loaders this source still offers on this turn, with what each holds: the run’s first
turn records them in Conversation::loaders, so a
compaction’s marker says what is left to load without asking the live source. Read inside
the journaled step of the model call, like appended. A loader the task
already loads is not here: it is loaded, not available. The default is none, which is what a
source written before loaders existed offers.
fn loaded_by_task<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<Loaded>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn loaded_by_task<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<Loaded>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
The groups the run’s task loaded, with what each holds: journaled on the run’s first
turn (Conversation::note_task_loaded), so a
compaction’s recap names them. They record no growth: their tools were never withheld. The
default is none, which is what a source written before groups existed offers.
fn loaded_tools<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Option<Vec<String>>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn loaded_tools<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Option<Vec<String>>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
The loaded tools this source still holds, as the source knows them: a group’s current
members, minus the journaled removals. The loop journals a loaded tool that is not here as
removed (the group shrank); a tool the access tier hides on this message is still here,
because the tier is per message. None, the default, says the source does not track its
loaded tools, and the loop falls back to what the request carried before a source withheld
any.
fn instructions<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn instructions<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Words to add to the agent’s instructions on this turn, when the run’s context calls for them
(the agents a person mentioned, for instance). None, the default, adds nothing. Like
specs it runs only when the model is really called, inside the journaled
step: text for the model to read, never what a call does. The agent appends what the
sources say, in their order, after its own instructions, each part set apart by a blank line.
fn appended_instructions<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn appended_instructions<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Words this source adds to the agent’s instructions during the run, after everything
instructions says: the words of a system the run loaded during
itself, which must follow the prompt and never be inserted into it, or the request before
would stop being a byte prefix of the one after (ADR 0044, decision 1). None, the default,
adds nothing, which is what a source written before this method existed offers.
fn refine<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
specs: &'life2 mut [ToolSpec],
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn refine<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
specs: &'life2 mut [ToolSpec],
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Change how the tools offered on this model turn are described, once every source has listed
its own: specs holds the agent’s own tools, then each source’s, as the model is about to be
shown them. A source that knows something the tool’s author could not (what the screen of this
conversation can draw, for the description of a tool that draws on it) rewrites the
description of that tool here.
Like specs it runs only when the model is really called, and a replay reads
nothing: it is for text the model reads, never for what a call does. Leave the names and
the schemas alone (the model’s calls are matched to the tools by name), and fail to
nothing: a source that cannot tell leaves the descriptions as they are. The default does.
fn withhold<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
tools: &'life2 [&'life3 str],
) -> Pin<Box<dyn Future<Output = Vec<Withheld>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn withhold<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
tools: &'life2 [&'life3 str],
) -> Pin<Box<dyn Future<Output = Vec<Withheld>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Which of tools this source holds back on this turn, whoever offers them: the agent’s
own, a source’s, one of an MCP server’s. tools are their names: all of those the model is
about to be shown, or the one it is calling. The agent leaves the ones named out of what the
model is shown, and again refuses a call to one of them at the moment it would run (the
model may name a tool it was not shown, or one it was shown a turn ago), with the
Withheld::reason as the call’s error result. For a limit the run’s context sets, such as
the access tier a person picked for a message: the prompt tells the model the limit, this
makes it hold. A source answers with names out of tools only.
Read from the run’s context at both moments (a limit that changes takes effect on the next turn and the next call), inside the journaled step, so a replay reads nothing. It has no error to return: a source that cannot tell holds nothing back. The default holds nothing back, so a source written before this method keeps working.
fn access(&self, name: &str, args: &Value) -> ToolAccess
fn access(&self, name: &str, args: &Value) -> ToolAccess
What a call to the tool name with args shares with the other calls of its model turn,
as Tool::access says for the agent’s own tools. Answer
ToolAccess::Independent or ToolAccess::Uses only for a tool this source offers
and ToolAccess::Alone for any other name: the agent takes the first source that answers
something else. The default is Alone, so a source written before this method existed keeps
its calls one at a time. A source that wraps another must forward it.
fn expects_repeat(&self, name: &str, taken: &[ToolSpec]) -> bool
fn expects_repeat(&self, name: &str, taken: &[ToolSpec]) -> bool
Whether name, a tool this source listed and the agent leaves out because taken (the
tools already offered on this turn) has it, is a repeat the source expects: it offers
whatever the system behind it has, among which the agent may already have a tool of its own
(a server the agent connects itself and a conversation attaches too). The agent logs such
a clash at debug level instead of warning at every model turn. The default, false, is a
clash nobody expected. The tool is left out either way.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
§impl ToolSource for Groups
impl ToolSource for Groups
§fn instructions<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Groups: 'async_trait,
fn instructions<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Groups: 'async_trait,
The notes of the groups the task loaded, in name order: the when behaviour, whose
instructions reached the prompt of a matching run. A group the run loads during itself is
not here: its note is in the load’s result, so the prompt does not grow mid-run.
§fn loaded_tools<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Option<Vec<String>>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Groups: 'async_trait,
fn loaded_tools<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Option<Vec<String>>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Groups: 'async_trait,
The loaded tools the groups still hold, minus the journaled removals: a member the group no longer has is a permanent removal; one the tier hides on this message is still here.
§fn loaded_by_task<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<Loaded>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Groups: 'async_trait,
fn loaded_by_task<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<Loaded>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Groups: 'async_trait,
The groups the task loaded, with their members and short notes: journaled on the run’s first turn, so a compaction’s recap names them. They record no growth: their tools were never withheld.
§fn appended<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<ToolSpec>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Groups: 'async_trait,
fn appended<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SourceCtx,
) -> Pin<Box<dyn Future<Output = Vec<ToolSpec>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Groups: 'async_trait,
The tools of the groups the run loaded, in the order it loaded them: a load appends to the
tools array, never inserts into it. A group the task loaded is not here: its tools were
never withheld, so they stand where the agent’s own list puts them, as mcp.json’s when
always did. A member a request did not carry earlier is not offered again.