Skip to content

Tools Specification

Scope

Owns the tool registry, tool implementations, and tool result types for the Robota SDK. This package provides both the infrastructure for defining and managing tools (ToolRegistry, FunctionTool, createZodFunctionTool) and a set of 8 built-in CLI tools (bash, read, write, edit, glob, grep, webFetch, webSearch) used by the agent CLI.

Boundaries

  • Does not own the abstract tool base class (AbstractTool) or tool interface contracts (IToolWithEventService, IToolResult, IToolExecutionContext). Those belong to @robota-sdk/agent-core.
  • Does not own permission evaluation or hook execution. Tool permission wrapping is performed by consumers (e.g., @robota-sdk/agent-sessions).
  • Does not own MCP tool protocol. MCP tools live in @robota-sdk/agent-tool-mcp.
  • Does not own provider-specific behavior. Tools are provider-agnostic.

Architecture Overview

registry/
  tool-registry.ts      -- ToolRegistry: central tool management and lookup
implementations/
  function-tool.ts      -- FunctionTool: JS function tool with Zod schema validation
  function-tool/
    index.ts            -- Re-exports FunctionTool, createFunctionTool, createZodFunctionTool
    schema-converter.ts -- zodToJsonSchema: converts Zod schemas to JSON Schema
    types.ts            -- FunctionTool-specific types
  openapi-tool.ts       -- OpenAPITool: tool generated from OpenAPI spec
types/
  tool-result.ts        -- TToolResult: result type for CLI tool invocations
builtins/
  index.ts              -- Re-exports all 8 built-in CLI tools
  bash-tool.ts          -- Bash: execute shell commands
  read-tool.ts          -- Read: read file contents with line numbers
  write-tool.ts         -- Write: write content to a file
  edit-tool.ts          -- Edit: replace a string in a file
  glob-tool.ts          -- Glob: find files matching a pattern (uses fast-glob)
  grep-tool.ts          -- Grep: search file contents with regex
  web-fetch-tool.ts     -- WebFetch: fetch URL content (HTML→text conversion)
  web-search-tool.ts    -- WebSearch: web search via Brave Search API

Design patterns used:

  • Registry -- ToolRegistry provides central tool registration, lookup, and schema management.
  • Factory -- createFunctionTool and createZodFunctionTool provide ergonomic tool construction.
  • Adapter -- zodToJsonSchema adapts Zod schemas into the JSON Schema format expected by AI providers.

Dependency direction: @robota-sdk/agent-tools has a peer dependency on @robota-sdk/agent-core. No reverse dependency exists.

Type Ownership

Types owned by this package (SSOT):

TypeKindFileDescription
TToolResultInterfacetypes/tool-result.tsResult shape for CLI tool invocations
IZodSchemaInterfaceimplementations/function-tool/types.tsZod schema shape for function tools
IZodParseResultInterfaceimplementations/function-tool/types.tsZod parse result shape
IZodSchemaDefInterfaceimplementations/function-tool/types.tsZod schema definition shape
IFunctionToolValidationOptionsInterfaceimplementations/function-tool/types.tsValidation options for function tools
ISchemaConversionOptionsInterfaceimplementations/function-tool/types.tsOptions for Zod-to-JSON-Schema conversion
IFunctionToolExecutionMetadataInterfaceimplementations/function-tool/types.tsMetadata returned by function tool execution
IFunctionToolResultInterfaceimplementations/function-tool/types.tsExtended result type for function tool execution

Public API Surface

Tool Infrastructure

ExportKindDescription
ToolRegistryClassCentral tool registration and schema lookup
FunctionToolClassJS function tool with Zod schema validation
createFunctionToolFunctionFactory for creating function tools
createZodFunctionToolFunctionFactory with Zod validation and conversion
OpenAPIToolClassTool generated from OpenAPI specification
createOpenAPIToolFunctionFactory for creating OpenAPI tools
zodToJsonSchemaFunctionConverts Zod schemas to JSON Schema format
TToolResultTypeResult shape for CLI tool invocations

Built-in CLI Tools

ExportKindTool NameDescription
bashToolObjectBashExecute shell commands via child_process.spawn
readToolObjectReadRead file contents with line numbers (cat -n)
writeToolObjectWriteWrite content to a file (creates parent dirs)
editToolObjectEditReplace a specific string in a file
globToolObjectGlobFind files matching a glob pattern (fast-glob)
grepToolObjectGrepSearch file contents with regex patterns
webFetchToolObjectWebFetchFetch URL content with HTML-to-text conversion
webSearchToolObjectWebSearchWeb search via Brave Search API

Each built-in tool is an IToolWithEventService-compatible object with getName(), getDescription(), getSchema(), and execute() methods.

TToolResult Shape

typescript
interface TToolResult {
  success: boolean;
  output: string;
  error?: string;
  exitCode?: number;
}

This is the inner result type used by built-in tools. It is serialized to JSON and placed inside the IToolResult.data field before being returned to the Robota execution loop.

Extension Points

  1. ToolRegistry -- Consumers register custom tools via ToolRegistry.register(). The registry manages name-based lookup and schema retrieval.

  2. FunctionTool / createZodFunctionTool -- Consumers create custom tools from plain functions with Zod schemas for parameter validation.

  3. OpenAPITool / createOpenAPITool -- Consumers create tools from OpenAPI specifications for API integration.

Error Taxonomy

This package does not define a custom error hierarchy. Built-in tools return errors via the TToolResult.error field rather than throwing. Schema conversion errors from zodToJsonSchema are thrown as standard Error instances.

Class Contract Registry

Interface Implementations

InterfaceImplementorKindLocation
IFunctionTool (agent-core)FunctionToolproductionsrc/implementations/function-tool.ts
ITool (agent-core)OpenAPIToolproductionsrc/implementations/openapi-tool.ts
IToolRegistry (agent-core)ToolRegistryproductionsrc/registry/tool-registry.ts

Inheritance Chains

None. FunctionTool and OpenAPITool implement their respective interfaces directly (implements IFunctionTool, implements ITool) without extending AbstractTool, to avoid circular runtime dependencies between agent-tools and agent-core.

Cross-Package Port Consumers

Port (Owner)ConsumerLocation
IFunctionTool (agent-core)FunctionToolsrc/implementations/function-tool.ts
ITool (agent-core)OpenAPIToolsrc/implementations/openapi-tool.ts
IToolWithEventService shapeBuilt-in CLI toolssrc/builtins/*.ts

Test Strategy

Current Test Coverage

FileScopeDescription
src/__tests__/function-tool.test.tsUnitFunctionTool creation, execution, schema validation
src/__tests__/schema-converter.test.tsUnitZod-to-JSON-Schema conversion
src/__tests__/tool-registry.test.tsUnitToolRegistry registration, lookup, listing

Gaps

  • Built-in tools -- No unit tests for bashTool, readTool, writeTool, editTool, globTool, or grepTool.
  • OpenAPITool -- No unit tests for OpenAPI tool creation or execution.
  • TToolResult -- No tests verifying the result shape contract.

Dependencies

Production (2)

  • fast-glob -- High-performance glob matching for the glob built-in tool
  • zod -- Schema validation for function tool parameters

Dev (notable)

  • openapi-types -- OpenAPI V3 type definitions used in OpenAPITool type imports. Listed as devDependency since only type-level imports are used, but consumers using OpenAPITool may need this installed for .d.ts resolution.

Peer (1)

  • @robota-sdk/agent-core -- Abstract tool base class, tool interfaces, event service types

Released under the MIT License.