Files
zesdex/crates/zesdex-backend/src/app/subagent/tools.rs
T

36 lines
1.3 KiB
Rust
Raw Normal View History

//! Subagent tool filtering: maps a subagent's allowed tool names to
//! concrete Tool trait objects and OpenAI-style tool definitions.
//!
//! Flow: load `all_tools()` → if `allowed_tools` is empty, use all; else
//! filter by membership → derive `ToolDef`s for the LLM.
use crate::dto::provider::request::ToolDef;
use crate::tool::{all_tools, tool_defs};
/// Build the tool list for a subagent from its allowlist.
///
/// An empty allowlist means "no restriction" (matches
/// `build_subagent_context`'s default for non-reviewer roles).
///
/// Return: `(tool impls, schema defs)` for the subagent to use.
pub(crate) fn build_subagent_tools(
allowed_tools: &[String],
) -> (Vec<Box<dyn crate::tool::Tool>>, Vec<ToolDef>) {
let all = all_tools();
let filtered: Vec<Box<dyn crate::tool::Tool>> = if allowed_tools.is_empty() {
all.into_iter()
.filter(|t| t.name() != "hive_mind" && t.name() != "workflow_run")
.collect()
} else {
all.into_iter()
.filter(|t| {
allowed_tools.contains(&t.name().to_string())
&& t.name() != "hive_mind"
&& t.name() != "workflow_run"
})
.collect()
};
let defs = tool_defs(&filtered);
(filtered, defs)
}