Graphorin API reference v0.1.0
Graphorin API reference / @graphorin/tools / / tool
Function: tool()
ts
function tool<TInput, TOutput, TDeps>(spec): Tool<TInput, TOutput, TDeps>;Defined in: packages/tools/src/builder/tool.ts:57
Build a Tool instance from a spec. Type inference flows from the inputSchema / outputSchema Zod types into the execute callback so authors do not have to repeat the input shape.
Type Parameters
| Type Parameter | Default type |
|---|---|
TInput | - |
TOutput | - |
TDeps | unknown |
Parameters
| Parameter | Type |
|---|---|
spec | ToolSpec<TInput, TOutput, TDeps> |
Returns
Tool<TInput, TOutput, TDeps>
Example
ts
const search = tool({
name: 'search-issues',
description: 'Search the project tracker for issues matching a query.',
inputSchema: z.object({ query: z.string() }),
outputSchema: z.object({ hits: z.array(z.object({ id: z.string(), title: z.string() })) }),
sideEffectClass: 'read-only',
async execute(input, ctx) {
// ...
},
});