Struct AgentDef
pub struct AgentDef { /* private fields */ }Expand description
An agent as its files describe it, before it is tied to tools, state and a model.
Made from a manifest with from_manifest (the embedded one from
adam::include_agent!(), or the one a directory loads: the same code path), it takes the
values the code supplies for {{placeholders}}, and bind checks it against
the registered tools:
let package = Dir::new(&root).load()?.into_package(Strictness::Lenient)?;
let def = AgentDef::from_manifest(package.agents[0].clone())?
.var("tone", "formal")
.bind(ToolSet::new())?;Implementations§
§impl AgentDef
impl AgentDef
pub fn card(
&self,
url: Url,
version: impl Into<String>,
) -> Result<AgentCardConfig, Error>
pub fn card( &self, url: Url, version: impl Into<String>, ) -> Result<AgentCardConfig, Error>
The card of this definition’s root agent, before any tool, state or model is bound.
The card is a fact about the files, not about the running agent, so a process that only
serves A2A (a control plane: no model, no tools, no credentials) can advertise the same
card as the workers that step the runs. It is exactly what
Assembly::card returns for the assembled agent.
§Errors
Error::MissingCardDescription when neither the card nor the agent has a description.
§impl AgentDef
impl AgentDef
pub fn from_manifest(manifest: impl IntoManifest) -> Result<AgentDef, Error>
pub fn from_manifest(manifest: impl IntoManifest) -> Result<AgentDef, Error>
A definition from a manifest: &AGENT from adam::include_agent!(), or an
[AgentManifest] from a directory.
§Errors
Error::Manifest when an embedded manifest cannot be decoded.
pub fn resources_from(
self,
source: &impl ManifestSource,
) -> Result<AgentDef, Error>
pub fn resources_from( self, source: &impl ManifestSource, ) -> Result<AgentDef, Error>
Read the files the skills bundle (references/, scripts/, assets/) from source,
the source the manifest came from, so that read_skill_file can serve them. Only a
manifest made without its source needs this: an embedded agent brings its files, and
from_source calls this itself.
The files are read now, once, so that a missing one is a startup error and a run never touches the disk.
§Errors
Error::Manifest when a file cannot be read, and Error::SkillTooLarge for a skill
whose files are over SKILL_RESOURCE_LIMIT.
pub fn from_source(
source: &impl ManifestSource,
strictness: Strictness,
) -> Result<Vec<AgentDef>, Error>
pub fn from_source( source: &impl ManifestSource, strictness: Strictness, ) -> Result<Vec<AgentDef>, Error>
One definition per agent of a source: one for an agent/ package, one per directory of
an agents/ package. strictness decides whether warnings fail the load, as they do for
a build script (Strictness::Strict is build("agent").strict()).
§Errors
Error::Manifest when the source cannot be read or has errors.
pub fn manifest(&self) -> &AgentManifest
pub fn manifest(&self) -> &AgentManifest
The manifest this definition was made from.
pub fn with_extra_mcp(
self,
extra: McpConfig,
file: &Path,
) -> Result<AgentDef, Error>
pub fn with_extra_mcp( self, extra: McpConfig, file: &Path, ) -> Result<AgentDef, Error>
Add the MCP servers of extra to the root agent’s own (mcp.json), so that
connect_mcp (feature mcp) connects both and bind checks the sum. The servers of
subagents are untouched. A name that both have is an error and nothing is added: a file
that is added over an agent can never replace one of its servers. file names where
extra came from, for the diagnostic.
§Errors
Error::Manifest with an Invalid error that names file
and every clashing server.
pub fn with_extra_mcp_file(
self,
file: &Path,
) -> Result<(AgentDef, Vec<Diagnostic>), Error>
pub fn with_extra_mcp_file( self, file: &Path, ) -> Result<(AgentDef, Vec<Diagnostic>), Error>
Read the file file (the mcpServers shape of mcp.json, parsed by the same loader) and
add its servers with with_extra_mcp. Returns the definition and
what the loader warned about (an unknown key, a literal credential), for the caller to log.
§Errors
Error::Manifest: the file cannot be read (Io), has errors
(invalid JSON, a bad server: every finding, as path:line: error: ...), or names a server
the agent already has.
pub fn mcp_env_references(&self) -> BTreeSet<String>
pub fn mcp_env_references(&self) -> BTreeSet<String>
The names of the environment variables the MCP servers of this definition (every local
agent’s, extra servers included) refer to as ${NAME} or ${NAME:-default}, sorted: what
a deployment hides from the processes the agent starts and registers with its redactor.
Names only, never values.
pub fn var(self, name: impl Into<String>, value: impl ToString) -> AgentDef
pub fn var(self, name: impl Into<String>, value: impl ToString) -> AgentDef
Supply the value of a var of the root agent. It overrides the default under vars, and
is the only way to give a value to a var declared without one (vars: { repo: }).
pub fn agent_var(
self,
agent: impl Into<String>,
name: impl Into<String>,
value: impl ToString,
) -> AgentDef
pub fn agent_var( self, agent: impl Into<String>, name: impl Into<String>, value: impl ToString, ) -> AgentDef
Supply the value of a var of another agent, by the name it is registered under
(coder/reviewer). Naming an agent the definition does not contain fails at
bind.
pub fn env(self, name: impl Into<String>, value: impl Into<String>) -> AgentDef
pub fn env(self, name: impl Into<String>, value: impl Into<String>) -> AgentDef
Give an environment variable a value here, in code, for the agent files that read one:
auth: bearer:BILLING_TOKEN on a remote subagent reads BILLING_TOKEN. A value given here
wins over the secrets source (the process environment by default), so a composition root that fetches its secrets from a
vault (or a test) does not have to put them in the environment. The value is held as a
secret: it is not shown by Debug, and no error carries it.
pub fn secrets(self, source: Arc<dyn SecretSource>) -> AgentDef
pub fn secrets(self, source: Arc<dyn SecretSource>) -> AgentDef
Where a variable that agent files name and env does not give is asked: the
process environment by default, which is a server’s. An application that embeds adam gives
its own source, or NoSecrets, which refuses every name (ADR 0047,
decision 5). It serves the bearer tokens of remote subagents (asked at bind)
and the ${VAR} of the mcp.json files (asked at connect_mcp, so call this first).
pub fn allow_insecure_remotes(self, allow: bool) -> AgentDef
pub fn allow_insecure_remotes(self, allow: bool) -> AgentDef
Allow remote subagents at plain http URLs that are not this machine: for development, or
a service of the same cluster (A2A_ALLOW_INSECURE_REMOTES in adam-agent). The messages
and the bearer token cross the network in clear text, so the network must be trusted on
its own (a NetworkPolicy that admits only the caller, or a mesh with mTLS). Even then a card
cannot widen it: an https card is never answered with a plain-http interface, and plain
http goes only to the card’s own host. Off by default: bind refuses such a URL with
Error::RemoteUrl, and the client refuses an agent card that offers such an interface.
localhost, *.localhost and loopback addresses never need it.
pub fn session_limits(self, limits: SessionLimits) -> AgentDef
pub fn session_limits(self, limits: SessionLimits) -> AgentDef
What the deployment allows of the sessions of one conversation (ADR 0045 decision 5): the
most open, the most working and the most rounds a session may have (default 16, 4 and 20).
The root’s file may lower each with limits.max_open_sessions,
limits.max_working_sessions and limits.max_session_rounds, never raise it: a larger
value is the deployment’s, with a warning. A subagent’s file has no say.
pub fn session_max_parallel(self, n: usize) -> AgentDef
pub fn session_max_parallel(self, n: usize) -> AgentDef
The deployment’s MAX_PARALLEL_TOOL_CALLS (1 to 32), for the bounds of the sessions
(session_bounds, ADR 0054 decision 2). Every role that serves A2A
gives it, so the control plane of a split deployment, which binds no agent, admits the same
start.config the workers’ session tools do. bind takes it as the agents’
own limit too, unless BoundDef::max_parallel says another:
a worker sets the one value in both places. Unset: the loop’s default, 10.
pub fn reasoning_effort(self, effort: Option<ReasoningEffort>) -> AgentDef
pub fn reasoning_effort(self, effort: Option<ReasoningEffort>) -> AgentDef
The root’s reasoning level when its file sets none (ADR 0063 decision 8): an embedded
engine’s host gives the level its folder would, and the root’s own reasoning_effort wins
over it. It is the root’s only: it never applies to a subagent, which has its own file.
It wins over the agent’s model_preset and the profile. It is checked against the root
model’s profile at BoundDef::model — not at
bind, which does not know the model — and the refusal reports the value as
reasoning_effort on the agent’s file even when this setter supplied it
(EffortSource::Folder): the setting is the file’s, whether
a file or the host gave it, so the message names the agent and its file. A level the profile
does not take is Error::ReasoningEffort. None (the default) sets nothing.
pub fn effective_session_limits(&self) -> SessionLimits
pub fn effective_session_limits(&self) -> SessionLimits
The limits the sessions of the root agent run under: the deployment’s
(session_limits) lowered by the root’s file. Pure, and the same
on every process role, so a control plane that serves the card without binding the agent
(its maxOpen) reads what the workers that run it enforce.
pub fn session_bounds(&self) -> Vec<(String, SessionBounds)>
pub fn session_bounds(&self) -> Vec<(String, SessionBounds)>
What a person’s start.config on a helper of the root is held to (ADR 0054 decision 2),
as (name, bounds) in the order the card lists the helpers: the very bounds
Assembly::session_bounds gives the session tools of a
worker, without binding the agent. max_parallel_tool_calls is the deployment’s
MAX_PARALLEL_TOOL_CALLS (session_max_parallel; the loop’s
10 when unset), lowered by the helper’s file; the rounds are
effective_session_limits’s. Give the definition the
deployment’s session_limits and session_max_parallel first, as a
worker does.
Both roles call one function (bounds_of), so a control plane that answers A2A and a worker
that runs the rounds admit the same start.config. Give both roles the same
MAX_PARALLEL_TOOL_CALLS and SESSION_MAX_ROUNDS: a control plane with a larger value
would admit what a worker then narrows at run time, never the reverse. The model’s window is
a fact of the model, which neither role knows here: context_window is None, admit
applies only its floor and the run takes the minimum with the model’s window.
pub fn child_sessions(&self) -> Option<ChildSessions>
pub fn child_sessions(&self) -> Option<ChildSessions>
What the root’s A2A front serves child-sessions/v1 for: each subagent of the root, local
and remote, in the order of the manifest, with the time limit of its rounds, and the
effective limits (effective_session_limits). None
when the root has no subagent: it has no session tools either. The same function on every
process role and made without binding, so a control plane that never builds the agent
serves the card and the sessions a worker’s tools agree with.
Only with the feature sessions (which a2a turns on).
pub fn session_starters(&self, builder: RuntimeBuilder) -> RuntimeBuilder
pub fn session_starters(&self, builder: RuntimeBuilder) -> RuntimeBuilder
Register, on a process that serves the A2A front but does not step the root’s helpers, the
starters of each of them, local and remote, under <root>/<name>: what a person’s session
round needs to be started there. A worker with the full agents
(Assembly::register) steps them. An agent with no subagent
registers nothing. Do not call it on a runtime that also registers the assembly: a second
registration under a name replaces the first.
A process that registers only starters holds no endpoint, so it cannot send the
CancelTask of a remote round it cancels. The front follows a cancel of a round, or an idle expiry, of a session
on a remote helper with a closing round (adam_a2a_runtime::ChildSessionAgent::remote),
which a worker steps and whose RemoteRoundAgent cancels the task. Without the feature
remote a remote subagent gets no starter: bind refuses it
(Error::RemoteNotEnabled).
pub fn remote_timeout(self, max_wait: Duration) -> AgentDef
pub fn remote_timeout(self, max_wait: Duration) -> AgentDef
How long a parent waits for the task of a remote subagent before the call is answered with an error result (default one hour; the remote task is left where it is). A zero is raised to one millisecond.
pub fn run_skills(self, skills: Arc<dyn RunSkills>) -> AgentDef
pub fn run_skills(self, skills: Arc<dyn RunSkills>) -> AgentDef
Let the root agent load skills that its run finds on the way (the skills of a
repository it prepared), through skills: a name with a / (<source>/<skill>) goes to
it, a name without never does. With it set the root always has load_skill and
read_skill_file, and its prompt gets one fixed sentence about them (also when the folder
has no skill of its own), so what a run finds is a tool result and never changes the
system prompt or the tool list. Subagents get none. skills: [] in the root’s
frontmatter turns skills off altogether: no tool, no sentence, and skills is never called.
Calling this again replaces it.
pub fn mcp_tools(self, agent: impl Into<String>, tools: ToolSet) -> AgentDef
pub fn mcp_tools(self, agent: impl Into<String>, tools: ToolSet) -> AgentDef
Give an agent the tools of its MCP servers, made by code of your own: a client other than
adam-mcp, or a test double. agent is the name the agent is registered under (coder,
coder/researcher); each tool must be named <server>__<tool> after a server of that
agent’s own mcp.json. An agent whose mcp.json lists servers must be given tools here
or by connect_mcp (feature mcp), or bind refuses it. Calling this again
for the same agent replaces the tools.
Checked at bind: Error::McpForeignTool, Error::McpToolClash,
Error::McpUnknownAgent.
pub fn plugin(
self,
name: impl Into<String>,
plugin: Arc<dyn Plugin>,
) -> AgentDef
pub fn plugin( self, name: impl Into<String>, plugin: Arc<dyn Plugin>, ) -> AgentDef
Register a compiled plugin under name, so that an agent file may list it in plugins:
(ADR 0050, slice H6). A subagent runs the plugins of its parent. Registering a name again
replaces it. Only compiled plugins are named: an agent file never declares a program.
The same plugin serves every agent that names it; use plugin_with
when the options of the file matter.
Checked at bind: Error::UnknownPlugin for a name nobody registered.
pub fn plugin_with(
self,
name: impl Into<String>,
make: impl Fn(&BTreeMap<String, String>) -> Arc<dyn Plugin> + Send + Sync + 'static,
) -> AgentDef
pub fn plugin_with( self, name: impl Into<String>, make: impl Fn(&BTreeMap<String, String>) -> Arc<dyn Plugin> + Send + Sync + 'static, ) -> AgentDef
Like plugin, made from the options the agent file gives (empty for a
bare name).
pub async fn connect_mcp(self, policy: &McpPolicy) -> Result<AgentDef, Error>
pub async fn connect_mcp(self, policy: &McpPolicy) -> Result<AgentDef, Error>
Connect to the MCP servers of the root agent’s mcp.json and of each local subagent’s, and
keep their tools for bind. Only with the feature mcp.
Each agent gets its own connections: two directories that both name a server linear
connect twice, with their own headers. ${VAR} in the files is expanded from
env first and then from the secrets source (the process
environment by default), so a token given in code reaches a server the same way it reaches
a remote subagent. Everything that can be wrong
(an unset variable, type: sse, a local process the policy does not allow, a server that
is down, an allow-list that names a tool the server lacks) is an error here, at startup:
see adam_mcp::McpServers::connect.
The connections live as long as the tools do: as long as the Assembly
built from this definition. Call it after the env and
secrets calls it should see, and once: it connects again each time. A
secrets called later reaches the remote subagents at bind, not these servers.
§Errors
Error::Mcp, naming the agent and its mcp.json, for the first server that fails.
pub fn bind(self, tools: ToolSet) -> Result<BoundDef, Error>
pub fn bind(self, tools: ToolSet) -> Result<BoundDef, Error>
Check the definition against the registered tools and render the prompts.
Everything that can be wrong with the files, given these tools, is found here, at startup, and not in the middle of a run:
- a name in
tools:that no tool has (Error::UnknownTool, with a “did you mean”), or a pattern (linear__*) that matches none; - a
{{placeholder}}thatvarsdoes not declare, a var that is declared and never used, a var with no value, a value supplied for an undeclared var, or a{{that is not a placeholder; - a value supplied for an agent the definition does not contain;
- a
retry:name that is not one of the agent’s tools once they are all bound (Error::UnknownRetryTool, with a “did you mean”; a tool of a declared MCP server that gave no tools is skipped with a warning), or an entry that is no policy (Error::InvalidRetry).
The root agent gets every registered tool when it has no tools:; a subagent gets none
(decision D3 of docs/reference/agent-files.md), whatever its parent has. Each agent then gets a
tool per local subagent, named after it ([SubagentTool]), after its own tools and its
skills’ tools. Two more things are refused here:
- a subagent tool whose name is already a tool of the parent, or another subagent’s
(
Error::SubagentToolClash);
A remote subagent (a2a:) gets a tool of the same shape and the same name checks, and is
checked here too: its URL must be https (or local, unless
allow_insecure_remotes) and carry no credentials
(Error::RemoteUrl), and the variable of its auth: bearer:VAR must hold a token
(Error::RemoteAuth). The token is read now and kept in memory, and the network is not
touched until the first call. Without the feature remote (on by default) there is no A2A
client: the subagent is refused after the name checks and before any secret is read
(Error::RemoteNotEnabled).
An agent’s MCP tools (mcp.json) come from its own directory only, and are part of the
catalog tools: selects from, next to the registered tools (tools: ['linear__*']
selects a server’s tools; a subagent that lists none gets none). An agent whose mcp.json
lists servers must have been given tools (connect_mcp, feature mcp, or
mcp_tools): Error::McpNotConnected otherwise (fail closed). An
empty set given for such an agent binds, with a warning naming the agent and its servers. The
tools must come from the same mcp.json (Error::McpChanged), be named after its
servers (Error::McpForeignTool) and not share a name with a registered tool
(Error::McpToolClash).
Nothing is built yet: the model and the state come next (BoundDef).
§Errors
The first problem found, in the order above; see Error.
§impl AgentDef
impl AgentDef
pub fn from_dir(path: impl Into<PathBuf>) -> Result<Vec<AgentDef>, Error>
pub fn from_dir(path: impl Into<PathBuf>) -> Result<Vec<AgentDef>, Error>
One definition per agent found in a directory: from_source over a
[Dir], with [Strictness::Lenient].
path is the directory that holds agent/ (or agents/), or that directory itself. The
environment variable AGENT_DIR_ENV replaces it when set. A process that serves one
agent and wants the warnings and the digest too uses AgentFolder::load.
§Errors
Error::Manifest when the directory cannot be read or has errors.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for AgentDef
impl !UnwindSafe for AgentDef
impl Freeze for AgentDef
impl Send for AgentDef
impl Sync for AgentDef
impl Unpin for AgentDef
impl UnsafeUnpin for AgentDef
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].