Skip to main content

deepseek/agent/
tool.rs

1//! `Tool` trait and `ToolDefinition` schema — verbatim from the original
2//! `agent.rs`, extended with [`Tool::read_only_hint`] used by the loop's
3//! parallel-dispatch and permission logic.
4
5use async_trait::async_trait;
6use serde_json::Value;
7
8/// JSON-schema description of a tool, sent to the model in the request.
9pub struct ToolDefinition {
10    pub name: String,
11    pub description: String,
12    pub parameters: Value,
13}
14
15/// Tool callable from the agent loop.
16///
17/// `read_only_hint()` defaults to `false`. Tools that don't mutate the host
18/// system (Read, Glob, Grep, Web*) should override it to `true` so the loop
19/// runs them in parallel and so `PermissionMode::Plan` allows them.
20#[async_trait]
21pub trait Tool: Send + Sync {
22    fn name(&self) -> &str;
23    fn definition(&self) -> ToolDefinition;
24    async fn call_json(&self, args: Value) -> std::result::Result<String, String>;
25
26    /// Hint to the loop that this tool is safe to execute concurrently with
27    /// other read-only tools and is allowed under `PermissionMode::Plan`.
28    fn read_only_hint(&self) -> bool {
29        false
30    }
31}