Skip to content

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 ParameterDefault type
TInput-
TOutput-
TDepsunknown

Parameters

ParameterType
specToolSpec&lt;TInput, TOutput, TDeps&gt;

Returns

Tool&lt;TInput, TOutput, TDeps&gt;

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) {
    // ...
  },
});

Stable