Tools

Tools extend LLM capabilities by allowing models to execute actions and retrieve information.

Built-in Tools

The SDK includes 6 built-in tools for common operations:

import { getBuiltinTools } from '@agentic-work/sdk/tools';

const tools = getBuiltinTools();
// [shellTool, readFileTool, writeFileTool, listFilesTool, deleteFileTool, searchTool]

Shell Tool

Execute shell commands:

import { shellTool } from '@agentic-work/sdk/tools';

// Tool definition
// name: 'shell'
// args: { command: string, workDir?: string }
// returns: stdout/stderr output

Read File Tool

Read file contents:

Write File Tool

Write or create files:

List Files Tool

List directory contents:

Delete File Tool

Delete files:

Search Tool

Search files with regex:

Creating Custom Tools

With Zod Schema

With JSON Schema

Tool Interface

Tool Context

The execution context provides useful utilities:

Using Context

MCP Tools from Platform

Access platform MCP tools:

Tool Result Format

Tools should return strings. For structured data, use JSON:

Error Handling in Tools

Return errors as structured responses:

Or throw errors to be caught by the agent:

Best Practices

  1. Clear descriptions - Help the LLM understand when to use the tool

  2. Typed schemas - Use Zod for runtime validation

  3. Descriptive parameters - Add .describe() to Zod fields

  4. Handle cancellation - Check context.signal.aborted for long tasks

  5. Report progress - Use context.onProgress for visibility

  6. Return JSON - Structure outputs for easy parsing

  7. Handle errors gracefully - Return meaningful error messages

Last updated