Yolk SDK
Build guides

Add a tool

Define a typed tool with Effect Schema and pass it to an agent loop.

Tools let the model ask your app to do work.

Define the tool

import { Effect, Schema } from 'effect'
import { makeTool } from '@yolk-sdk/agent/tools'

const WeatherParams = Schema.Struct({
  city: Schema.String
})

const Weather = Schema.Struct({
  city: Schema.String,
  condition: Schema.String
})

export const weatherTool = makeTool({
  name: 'get_weather',
  description: 'Get the current weather for a city.',
  parameters: WeatherParams,
  output: Weather,
  access: 'read',
  // Optional: model-facing prose. Without it the model sees the compact JSON of the output.
  render: weather => `Weather in ${weather.city}: ${weather.condition}`,
  execute: ({ params }) => Effect.succeed({ output: { city: params.city, condition: 'sunny' } })
})

makeTool uses your Effect Schema to validate model input and generate the JSON Schema exposed to the model. The advertised document may add root type: "object" to typeless object-only anyOf/oneOf unions for strict upstreams; execution still validates against your original Schema.

With output, execute returns { output }: Yolk encodes it with the schema's JSON codec into structuredContent (what code mode scripts read) and shows the model render(value, files) or, by default, the compact JSON of the encoding. Tools without output return { content } (text, plus file parts). File fields are ToolFile (Typed outputs and file fields).

Resolve tools for a request

import { Effect } from 'effect'
import { resolveTools } from '@yolk-sdk/agent/tools'

const toolModule = {
  id: 'weather',
  tools: [weatherTool]
}

const toolSet = await Effect.runPromise(resolveTools([toolModule], requestContext))

Pass toolSet.tools into run or runRuntime. Use toolSet.execute inside your ToolExecutor layer.

Access levels

AccessUse for
readsearch, fetch, inspect
writecreate/update external state
destructiveshell commands, delete, send irreversible messages

The SDK records access. Your host decides whether to approve, deny, log, or hide a tool.

On this page