Agent Tool
import { agentTool } from "@swenyai/providers/agent-tool";Interface
Section titled “Interface”interface AgentTool<T extends ZodRawShape = ZodRawShape> { name: string; description: string; schema: T; execute(args: Record<string, unknown>): Promise<ToolResult>;}
interface ToolResult { content: { type: "text"; text: string }[]; isError?: boolean;}Factory
Section titled “Factory”Creates a typed tool with a Zod schema for argument validation:
import { z } from "zod";
const greetTool = agentTool( "greet", "Greet a user by name", { name: z.string() }, async (args) => ({ content: [{ type: "text", text: `Hello, ${args.name}!` }], }),);The agentTool factory accepts four arguments:
| Argument | Type | Description |
|---|---|---|
name | string | Unique tool name |
description | string | Human-readable description |
schema | ZodRawShape | Zod schema defining accepted args |
execute | (args: Record<string, unknown>) => Promise<ToolResult> | Function that runs the tool |
Return a ToolResult with isError: true to signal a failure without throwing.