Skip to main content

AgentDef

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

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

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>

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>

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 name(&self) -> &str

The root agent’s name.

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>

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>

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>

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

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

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

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

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

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

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

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

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

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)>

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>

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

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

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

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

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

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

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>

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>

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}} that vars does 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 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

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§

§

impl Clone for AgentDef

§

fn clone(&self) -> AgentDef

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for AgentDef

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more