Skip to main content

a2a_protocol_server/tool_loop/
skills.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Tom F. <[email protected]> (https://github.com/tomtom215)
3
4//! [`ToolLoopExecutor::with_skills`]: Agent Skills in the tool loop (ADR 0035;
5//! feature `skills`). The module is the whole of the executor's side of the
6//! feature; what a skill is and how it is read is `crate::skills`.
7
8use super::executor::ToolLoopExecutor;
9use super::tool::DuplicateTool;
10use crate::skills::SkillCatalog;
11
12impl ToolLoopExecutor {
13    /// Gives the loop the skills in `catalog`: the catalog goes at the end of
14    /// the system prompt, and the model gets `activate_skill` (its `name` a
15    /// JSON Schema enum of the skills' names) and, when some skill bundles
16    /// files, `read_skill_file`. A call to either is a tool call like any
17    /// other: traced as an `execute_tool` span, counted among the run's tool
18    /// calls and bounded by the turn limit and the caller's budget. No script
19    /// is run, and no skill adds a tool or approves one.
20    ///
21    /// A catalog with no skills changes nothing: an empty catalog and a tool
22    /// with no valid argument would only confuse the model.
23    ///
24    /// The prompt is appended to the loop's own preamble, after a blank line,
25    /// so this is called on an executor whose loop already has its preamble
26    /// (the executor has no way to set one afterwards).
27    ///
28    /// # Errors
29    ///
30    /// [`DuplicateTool`] when the loop's tools already include one named
31    /// `activate_skill` or `read_skill_file`. The executor is consumed.
32    pub fn with_skills(mut self, catalog: &SkillCatalog) -> Result<Self, DuplicateTool> {
33        for tool in catalog.tools() {
34            self.tool_loop.tools.add_arc(tool)?;
35        }
36        if let Some(prompt) = catalog.prompt() {
37            let preamble = &mut self.tool_loop.preamble;
38            if !preamble.is_empty() {
39                preamble.push_str("\n\n");
40            }
41            preamble.push_str(&prompt);
42        }
43        Ok(self)
44    }
45}
46
47#[cfg(test)]
48#[path = "skills_tests.rs"]
49mod tests;