Skip to main content

synwire_agent/tools/
mod.rs

1//! Pre-built tool providers for common coding agent patterns.
2//!
3//! Compose these with [`CompositeToolProvider`] to assemble a full tool suite.
4//! Each sub-module builds a `StaticToolProvider` containing namespaced tools
5//! for a specific domain.
6//!
7//! # Provider composition
8//!
9//! VFS, LSP, and DAP tool providers live in their respective crates
10//! (`synwire-core::vfs`, `synwire-lsp`, `synwire-dap`) because they require
11//! runtime dependencies (VFS instance, LSP client, DAP client). The
12//! [`default_tool_provider`] assembles only the providers that need no external
13//! runtime state; consumers add VFS/LSP/DAP providers at startup.
14//!
15//! ```rust,no_run
16//! use synwire_agent::tools::{DefaultToolConfig, default_tool_provider};
17//!
18//! let provider = default_tool_provider(DefaultToolConfig::new().with_meta());
19//! ```
20
21pub mod code;
22pub mod index;
23pub mod meta;
24
25use synwire_core::tools::CompositeToolProvider;
26
27/// Configuration for [`default_tool_provider`].
28#[derive(Debug, Clone, Copy, Default)]
29#[non_exhaustive]
30pub struct DefaultToolConfig {
31    /// Whether to include `meta.*` tools (tool search and listing).
32    pub include_meta: bool,
33}
34
35impl DefaultToolConfig {
36    /// Create a new configuration with default settings.
37    #[must_use]
38    pub const fn new() -> Self {
39        Self {
40            include_meta: false,
41        }
42    }
43
44    /// Enable `meta.*` tools (tool search and listing).
45    #[must_use]
46    pub const fn with_meta(mut self) -> Self {
47        self.include_meta = true;
48        self
49    }
50}
51
52/// Assemble the default tool suite for a coding agent.
53///
54/// Includes `code.*` and `index.*` tool providers. Optionally includes
55/// `meta.*` tools when [`DefaultToolConfig::include_meta`] is set.
56///
57/// VFS, LSP, and DAP providers are **not** included because they require
58/// runtime dependencies. Add them via [`CompositeToolProvider`] at startup.
59///
60/// # Errors
61///
62/// Returns [`synwire_core::error::SynwireError`] if any tool fails validation.
63pub fn default_tool_provider(
64    config: DefaultToolConfig,
65) -> Result<CompositeToolProvider, synwire_core::error::SynwireError> {
66    let mut providers: Vec<Box<dyn synwire_core::tools::ToolProvider>> =
67        vec![code::code_tool_provider()?, index::index_tool_provider()?];
68    if config.include_meta {
69        providers.push(meta::meta_tool_provider()?);
70    }
71    Ok(CompositeToolProvider::with_keep_first(providers))
72}