phi_core/tools/mod.rs
1//! Built-in agent tools.
2/*
3ARCHITECTURE: tools/ — the standard toolkit for coding agents
4
5This module provides 6 built-in tools that together cover the core operations
6of a coding agent:
7 `BashTool` — run shell commands (most powerful; the agent's hands)
8 `ReadFileTool` — read file contents
9 `WriteFileTool` — write or overwrite a file
10 `EditFileTool` — precise text replacement within a file
11 `ListFilesTool` — list directory contents
12 `SearchTool` — grep / content search across files
13
14`default_tools()` returns all six in a `Vec<Arc<dyn AgentTool>>` — the canonical
15"batteries included" tool set. Callers that want a subset can build their own Vec.
16
17RUST QUIRK: `pub mod` vs `pub use`
18
19`pub mod bash;` — declares the `bash` submodule and makes it publicly accessible.
20 This loads `tools/bash.rs` and exposes it as `tools::bash::*`.
21
22`pub use bash::BashTool;` — re-exports `BashTool` at this module's level.
23 Without this re-export, callers would write `tools::bash::BashTool`.
24 With it, they write `tools::BashTool` — cleaner public API.
25
26RUST QUIRK: `Vec<Arc<dyn AgentTool>>` — shared heterogeneous tool collection
27
28All 6 tools are different concrete types, but they share the `AgentTool` trait.
29To put different types in one `Vec`, we need "type erasure" via trait objects:
30 `Arc<dyn AgentTool>` — reference-counted, vtable-dispatched, concrete type erased
31
32`Arc::new(BashTool::default())` — allocates `BashTool` on the heap behind an Arc.
33Arc allows tools to be shared across parallel agent branches (evaluational parallelism)
34without copying — each branch gets a cheap reference-count increment.
35Python analogy: a list of objects that all implement an abstract base class.
36*/
37
38pub mod bash;
39pub mod edit;
40pub mod file;
41pub mod list;
42pub mod prun;
43pub mod registry;
44pub mod revert;
45pub mod search;
46
47pub use bash::BashTool;
48pub use edit::EditFileTool;
49pub use file::{ReadFileTool, WriteFileTool};
50pub use list::ListFilesTool;
51pub use prun::{PrunRecord, PrunRequest, PrunTool, PrunVariant};
52pub use registry::ToolRegistry;
53pub use revert::{RevertRecord, RevertRequest, RevertTool};
54pub use search::SearchTool;
55
56use crate::types::AgentTool;
57use std::sync::Arc;
58
59/// Get the standard set of coding agent tools.
60///
61/// Returns all 6 built-in tools ready for use with `Agent::with_tools()` or
62/// `AgentLoopConfig`. Each tool is heap-allocated behind an `Arc<dyn AgentTool>`,
63/// which allows them to be shared across parallel agent branches at zero copy cost.
64pub fn default_tools() -> Vec<Arc<dyn AgentTool>> {
65 vec![
66 Arc::new(BashTool::default()),
67 Arc::new(ReadFileTool::default()),
68 Arc::new(WriteFileTool::new()),
69 Arc::new(EditFileTool::new()),
70 Arc::new(ListFilesTool::default()),
71 Arc::new(SearchTool::default()),
72 ]
73}