use super::*;
impl BuiltinTools {
pub fn tool_defs(&self) -> Vec<Tool> {
let mut defs = vec![
Tool {
name: "read_file".to_string(),
description: "Read the complete contents of a file. Use this to examine existing code, configurations, or data files before making changes.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Path to the file, relative to the working directory"
}
},
"required": ["path"]
}),
},
Tool {
name: "write_file".to_string(),
description: "Write content to a file, creating it (and any parent directories) if necessary. Use this to create new files or completely replace existing file content.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Path to the file, relative to the working directory"
},
"content": {
"type": "string",
"description": "The full content to write to the file"
}
},
"required": ["path", "content"]
}),
},
Tool {
name: "edit_file".to_string(),
description: "Replace an exact string in an existing file. The old_str must appear exactly once in the file. Use this for targeted edits rather than rewriting entire files.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Path to the file, relative to the working directory"
},
"old_str": {
"type": "string",
"description": "The exact string to replace. Must appear exactly once in the file."
},
"new_str": {
"type": "string",
"description": "The string to replace old_str with"
}
},
"required": ["path", "old_str", "new_str"]
}),
},
Tool {
name: "list_dir".to_string(),
description: "List the contents of a directory. Use this to explore the file structure before reading or writing files.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Path to the directory, relative to the working directory. Defaults to the working directory root if omitted."
}
},
"required": []
}),
},
Tool {
name: "read_files".to_string(),
description: "Read multiple files at once. Returns the contents of all requested files in a single response, separated by file path headers. More efficient than calling read_file repeatedly. Use this when you need to read several files (e.g. after list_dir).".to_string(),
parameters: json!({
"type": "object",
"properties": {
"paths": {
"type": "array",
"items": { "type": "string" },
"description": "Array of file paths relative to the working directory"
}
},
"required": ["paths"]
}),
},
Tool {
name: "shell".to_string(),
description: "Execute a shell command in the working directory. Uses the system shell (bash/zsh on Unix, cmd on Windows). Use this for build commands, running tests, installing dependencies, or other shell operations. Has a 60-second timeout.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"command": {
"type": "string",
"description": "The shell command to execute"
}
},
"required": ["command"]
}),
},
Tool {
name: "present_for_review".to_string(),
description: "Present a document, plan, or report to the user for review. The agent run will pause and the dashboard will display the document prominently. Use this when you want the user to read and approve something before you continue - for example, a technical design, an implementation plan, or a summary report. The user can provide feedback or simply acknowledge to continue.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "Short title for the review prompt shown to the user (e.g. 'Implementation Plan Ready for Review')"
},
"markdown": {
"type": "string",
"description": "The markdown document to present to the user. Supports headings, lists, code blocks, and mermaid diagrams."
}
},
"required": ["title", "markdown"]
}),
},
Tool {
name: "ask_user_text".to_string(),
description: "Ask the user a free-form question and wait for their written answer. The run pauses until they respond. Use this when you need clarification, missing information, or a specific detail only the user knows - decide for yourself when this is necessary; don't ask about things you can figure out on your own.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"prompt": {
"type": "string",
"description": "The question to ask the user"
}
},
"required": ["prompt"]
}),
},
Tool {
name: "ask_user_choice".to_string(),
description: "Ask the user to pick one option from a list and wait for their answer. The run pauses until they respond. Use this when you have a small number of distinct paths forward and want the user to decide which one, rather than guessing yourself.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"prompt": {
"type": "string",
"description": "The question to ask the user"
},
"options": {
"type": "array",
"items": { "type": "string" },
"description": "At least two options for the user to choose from"
}
},
"required": ["prompt", "options"]
}),
},
Tool {
name: "ask_user_confirm".to_string(),
description: "Ask the user a yes/no question and wait for their answer. The run pauses until they respond. Use this for a quick go/no-go decision before doing something significant or hard to undo.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"prompt": {
"type": "string",
"description": "The yes/no question to ask the user"
}
},
"required": ["prompt"]
}),
},
Tool {
name: "edit_document".to_string(),
description: "Present a document to the user in an editable field pre-filled with its current text, and wait for them to edit it directly. The run pauses until they submit. Use this when the user wants to modify content themselves (e.g. tweak a plan or draft) rather than describe changes for you to make. Pass the current full text as `content`; the returned text is the user's edited version, which you should adopt as authoritative.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"content": {
"type": "string",
"description": "The current full document text to present for editing"
},
"prompt": {
"type": "string",
"description": "Optional instruction shown above the editable field"
}
},
"required": ["content"]
}),
},
Tool {
name: "context_write".to_string(),
description: "Store or update content in a named section of your context window. This content will be included in your system prompt on subsequent turns, making it available for reference. Use this to save analysis, plans, notes, or structured information. If a key is provided and an entry with that key already exists, it will be replaced with the new content.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"region": {
"type": "string",
"description": "Name of the context window section (e.g. 'architecture', 'plan')"
},
"key": {
"type": "string",
"description": "Key for the entry. Replaces existing entry with the same key."
},
"content": {
"type": "string",
"description": "Content to store"
}
},
"required": ["region", "content"]
}),
},
Tool {
name: "context_append".to_string(),
description: "Add content to an existing section of your context window without replacing what's already there.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"region": {
"type": "string",
"description": "Name of the context window section"
},
"key": {
"type": "string",
"description": "Key for the entry"
},
"content": {
"type": "string",
"description": "Content to append"
}
},
"required": ["region", "content"]
}),
},
Tool {
name: "context_read".to_string(),
description: "Read what's currently stored in a section of your context window. If no key is specified and the section contains keyed entries, returns a summary of all keys and their sizes.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"region": {
"type": "string",
"description": "Name of the context window section to read"
},
"key": {
"type": "string",
"description": "Key of a specific entry to read"
}
},
"required": ["region"]
}),
},
Tool {
name: "context_delete".to_string(),
description: "Remove a specific keyed entry from a section of your context window.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"region": {
"type": "string",
"description": "Name of the context window section"
},
"key": {
"type": "string",
"description": "Key of the entry to remove"
}
},
"required": ["region", "key"]
}),
},
Tool {
name: "context_list".to_string(),
description: "List available sections of your context window with their current usage - section names, token counts, and number of entries. Use this to see what's available and what you've already stored.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"region": {
"type": "string",
"description": "Optional region name to list keys for"
}
},
"required": []
}),
},
];
defs.retain(|t| self.available(&t.name));
defs
}
pub fn subagent_tool_defs() -> Vec<Tool> {
vec![
Tool {
name: "spawn_agent".to_string(),
description: "Spawn a sub-agent from a blueprint to work on a task. Returns the new agent's ID. If wait=true, blocks until the sub-agent completes and returns its result.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"blueprint": {
"type": "string",
"description": "Name of the agent blueprint to spawn"
},
"task": {
"type": "string",
"description": "Task prompt for the sub-agent"
},
"wait": {
"type": "boolean",
"description": "If true, block until the sub-agent completes and return its result. Default: false",
"default": false
},
"seed_context": {
"type": "string",
"description": "Optional initial context to inject into the sub-agent's first Pinned region"
},
"max_child_depth": {
"type": "integer",
"description": "Optional max depth for the sub-agent's own children"
}
},
"required": ["blueprint", "task"]
}),
},
Tool {
name: "check_agent".to_string(),
description: "Check the status of a sub-agent. Returns its current status and result if complete. Non-blocking.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"agent_id": {
"type": "string",
"description": "ID of the agent to check"
}
},
"required": ["agent_id"]
}),
},
Tool {
name: "wait_for_agent".to_string(),
description: "Block until a sub-agent completes, then return its final result.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"agent_id": {
"type": "string",
"description": "ID of the agent to wait for"
}
},
"required": ["agent_id"]
}),
},
Tool {
name: "send_to_agent".to_string(),
description: "Send a message to a running sub-agent's context window.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"agent_id": {
"type": "string",
"description": "ID of the target agent"
},
"message": {
"type": "string",
"description": "Message content to send"
},
"target_region": {
"type": "string",
"description": "Context region to deliver to (default: conversation)"
}
},
"required": ["agent_id", "message"]
}),
},
Tool {
name: "kill_agent".to_string(),
description: "Kill a sub-agent and all its descendants. Sets their cancellation tokens and marks them as cancelled.".to_string(),
parameters: json!({
"type": "object",
"properties": {
"agent_id": {
"type": "string",
"description": "ID of the agent to kill"
}
},
"required": ["agent_id"]
}),
},
]
}
pub fn subagent_tool_names() -> Vec<String> {
vec![
"spawn_agent".to_string(),
"check_agent".to_string(),
"wait_for_agent".to_string(),
"send_to_agent".to_string(),
"kill_agent".to_string(),
]
}
pub fn names(&self) -> Vec<String> {
let mut names: Vec<String> = [
"read_file",
"read_files",
"write_file",
"edit_file",
"list_dir",
"shell",
"present_for_review",
"ask_user_text",
"ask_user_choice",
"ask_user_confirm",
"edit_document",
"context_write",
"context_append",
"context_read",
"context_delete",
"context_list",
]
.iter()
.filter(|n| self.available(n))
.map(|s| s.to_string())
.collect();
names.extend(
TOOL_ALIASES
.iter()
.filter(|(_, canonical)| self.available(canonical))
.map(|(alias, _)| alias.to_string()),
);
names
}
}