Sebelumnya loop utama mengeksekusi semua tool call satu-per-satu (sequential for loop). Seperti Claude Code, tool read-only yang independen dalam satu pesan assistant (read/grep/glob/semantic_search dsb.) kini dijalankan konkuren dengan bounded parallelism (max 8), mengurangi latensi per turn secara signifikan untuk beban coding. - feat(registry): tool_is_parallel_safe() — whitelist tool read-only yang aman dijalankan paralel; tool mutating/shell tetap sequential - feat(executor): is_parallel_safe() delegasi ke registry; ToolExecutor trait Default=false (konservatif) - fix(application): execute_tool_calls_in_parallel() — join_all + semaphore bounded 8, hasil dikumpulkan dalam URUTAN panggilan asli (kontrak OpenAI/Anthropic tool-result ordering) - loop utama: batch paralel hanya jika SEMUA tool parallel-safe; jika ada satu tool mutating, jatuh balik ke jalur sequential aman - test: +2 registry test, +2 application test (konkurensi & urutan, fallback batch mutating)
76 lines
2.5 KiB
Rust
76 lines
2.5 KiB
Rust
//! Tool trait, execution context, and the registry of all built-in tools.
|
|
//!
|
|
//! This module defines the core `Tool` trait that every agent-invocable tool
|
|
//! must implement, the shared `ToolCtx` execution context, and utility
|
|
//! functions for path resolution, command execution, argument extraction,
|
|
//! and graduated-check rules.
|
|
//!
|
|
//! # Organisation
|
|
//!
|
|
//! ```text
|
|
//! tools/
|
|
//! ├── mod.rs — Tool trait, re-exports
|
|
//! ├── context.rs — ToolCtx, ToolCtxBuilder
|
|
//! ├── registry.rs — all_tools(), tool_defs(), tool_is_risky()
|
|
//! ├── util.rs — arg_str(), execute_cmd(), resolve_path(),
|
|
//! │ log_write_edit_tool()
|
|
//! ├── graduated.rs — GraduatedCheck, check_graduated_checks()
|
|
//! ├── executor.rs — InfrastructureToolExecutor
|
|
//! ├── fs/ — read, write, edit, delete
|
|
//! ├── git/ — git_operator, git_worktree, git_cred
|
|
//! ├── memory/ — remember, forget, recall
|
|
//! ├── utility/ — cd, dir_list, pong, todowrite, todofinish, etc.
|
|
//! ├── shell.rs — Bash tool
|
|
//! ├── bash_tools.rs
|
|
//! ├── search.rs — Grep, Glob
|
|
//! ├── semantic_search.rs
|
|
//! ├── web_search.rs
|
|
//! ├── sequential_think.rs
|
|
//! ├── plan.rs, spawn.rs, workflow.rs
|
|
//! └── parallel_delegate.rs
|
|
//! ```
|
|
|
|
use anyhow::Result;
|
|
use serde_json::Value;
|
|
|
|
pub mod bash_tools;
|
|
pub mod best_practice;
|
|
pub mod context;
|
|
pub mod executor;
|
|
pub mod fs;
|
|
pub mod git;
|
|
pub mod graduated;
|
|
pub mod memory;
|
|
pub mod parallel_delegate;
|
|
pub mod plan;
|
|
pub mod registry;
|
|
pub mod search;
|
|
pub mod semantic_search;
|
|
pub mod sequential_think;
|
|
pub mod shell;
|
|
pub mod shell_filter;
|
|
pub mod spawn;
|
|
pub mod util;
|
|
pub mod utility;
|
|
pub mod web_search;
|
|
pub mod workflow;
|
|
|
|
// Re-export commonly used items at the `tools` root so existing imports
|
|
// like `crate::tools::{Tool, ToolCtx}` continue to work.
|
|
pub use context::{ToolCtx, ToolCtxBuilder};
|
|
pub use graduated::{check_graduated_checks, GraduatedCheck};
|
|
pub use registry::{all_tools, tool_defs, tool_is_parallel_safe, tool_is_risky};
|
|
pub use util::{arg_str, execute_cmd, log_write_edit_tool, resolve_path};
|
|
|
|
/// Common interface every agent-invocable tool implements.
|
|
pub trait Tool: Send + Sync {
|
|
fn name(&self) -> &'static str;
|
|
fn description(&self) -> &'static str;
|
|
fn parameters(&self) -> Value;
|
|
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String>;
|
|
}
|
|
|
|
pub use git::git_cred;
|
|
pub use git::git_operator;
|
|
pub use git::git_worktree;
|