Files
zesdex/apps/infrastructure/src/tools/registry.rs
T
asepharyana eac0443c4c perf(agent): rombak alur AI agent — adaptif, hemat token, self-healing
Ganti explore phase MANDATORY (3 subagent tiap turn, boros) dengan
tool explore_codebase yang DIPUTUSKAN agent sendiri (lazy, token-aware):
- hapus ExploreService trait + with_explore + Phase 0 dari turn loop
- ExploreServiceImpl kini jadi tool 'explore_codebase' (1 context-scout
  subagent, read-only, cap output 4k chars)
- system prompt: instruksi TOKEN BUDGET (jawab langsung utk query simple,
  panggil explore_codebase sekali utk task kompleks)

Loop utama kini adaptif & self-healing:
- max_tokens adaptif (800/1600/4096 by request length) — bukan selalu 4096
- temperature 0.2 saat tool-calling, 0.7 utk final answer
- ErrorTracker: deteksi tool error berulang → inject recovery note,
  stop setelah 8 error total (bukan 50 iterasi sia-sia)
- auto-compact history > 60k chars sebelum LLM call
- tool output di-truncate ke 12k chars sebelum masuk konteks

Tambah 8 unit test (truncation, adaptive tokens, error tracker).
2026-08-27 23:06:37 +07:00

69 lines
3.0 KiB
Rust

//! Tool registry: the master list of all built-in tools, plus conversion
//! utilities for generating provider-facing tool definitions.
/// Construct one instance of every built-in tool.
pub fn all_tools() -> Vec<Box<dyn super::Tool>> {
vec![
Box::new(super::fs::read::Read),
Box::new(super::fs::write::Write),
Box::new(super::fs::edit::Edit),
Box::new(super::fs::delete::Delete),
Box::new(super::search::Grep),
Box::new(super::search::Glob),
Box::new(super::bash_tools::BashOutput),
Box::new(super::bash_tools::BashKill),
Box::new(super::shell::Bash),
Box::new(super::git::git_operator::GitOperator),
Box::new(super::git::git_worktree::GitWorktree),
Box::new(super::git::git_cred::GitCred),
Box::new(super::sequential_think::SeqThink),
Box::new(super::plan::PlanEnter),
Box::new(super::plan::PlanReady),
Box::new(super::workflow::WorkflowRun),
Box::new(super::workflow::NoteFinding),
Box::new(super::workflow::ReadFindings),
Box::new(super::workflow::HiveMind),
Box::new(super::spawn::SpawnAgents),
Box::new(super::spawn::SpawnPipeline),
Box::new(super::memory::remember::Remember),
Box::new(super::memory::forget::Forget),
Box::new(super::memory::recall::Recall),
Box::new(super::utility::cd::Cd),
Box::new(super::utility::dir_list::DirList),
Box::new(super::utility::dir_cache_update::DirCacheUpdate),
Box::new(super::utility::pong::Pong),
Box::new(super::utility::todowrite::Todowrite),
Box::new(super::utility::todofinish::Todofinish),
Box::new(super::web_search::WebSearch),
Box::new(super::semantic_search::SemanticSearch),
Box::new(super::semantic_search::RebuildIndex),
Box::new(super::semantic_search::ListSymbols),
Box::new(super::parallel_delegate::ParallelDelegate),
// ── Best-practice tools (built-in) ─────────────────────────
Box::new(super::best_practice::BestPractice),
Box::new(super::best_practice::CommitConvention),
Box::new(crate::best_practice::explore::ExploreCodebase),
]
}
/// Whether a tool by name can mutate the filesystem or run arbitrary shell
/// commands.
pub fn tool_is_risky(name: &str) -> bool {
matches!(name, "write" | "delete" | "edit" | "bash" | "git_operator")
}
/// Convert a list of tools into provider-facing `ToolDef` request schema.
pub fn tool_defs(tools: &[Box<dyn super::Tool>]) -> Vec<zesdex_domain::core::ToolDef> {
tools
.iter()
.map(|t| zesdex_domain::core::ToolDef {
type_: "function".to_string(),
function: zesdex_domain::core::ToolFunctionDef {
name: t.name().to_string(),
description: t.description().to_string(),
parameters: t.parameters(),
},
})
.collect()
}