Yolk SDK

Quickstart

Run a complete Yolk agent loop with a typed tool and fake provider.

This guide runs one complete agent turn locally: user message → model tool call → host tool execution → final assistant message.

It uses the fake provider, so you do not need provider credentials yet.

Install

pnpm add @yolk-sdk/agent@canary effect@4.2.0

Create index.ts

import { Effect, Layer, Stream } from 'effect'
import * as Schema from 'effect/Schema'
import { ContextTransformer, LoopConfig, run } from '@yolk-sdk/agent/loop'
import { FauxProvider, Reply } from '@yolk-sdk/agent/loop/testing'
import { assistantContent, UserMessage } from '@yolk-sdk/agent/protocol'
import { makeTool, makeToolExecutorLayer, resolveTools } from '@yolk-sdk/agent/tools'

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

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

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

const toolSet = await Effect.runPromise(resolveTools([{ id: 'weather', tools: [weatherTool] }], {}))

const AppAgentLayer = Layer.mergeAll(
  FauxProvider.layer(
    Reply.toolCall({
      id: 'call_weather_1',
      name: 'get_weather',
      params: { city: 'Barcelona' }
    }),
    Reply.text('It is sunny in Barcelona.')
  ),
  makeToolExecutorLayer(toolSet),
  LoopConfig.defaultLayer,
  ContextTransformer.identity
)

const events = Array.from(
  await Effect.runPromise(
    run({
      messages: [UserMessage.make({ content: 'What is the weather in Barcelona?' })],
      systemPrompt: 'Use tools when useful. Be concise.',
      tools: toolSet.tools,
      model: 'test-model'
    }).pipe(Stream.runCollect, Effect.provide(AppAgentLayer))
  )
)

console.log(events.map(event => event._tag).join(' -> '))

const assistant = events.find(event => event._tag === 'AssistantMessage')

if (assistant !== undefined) {
  console.log(assistantContent(assistant.message))
}

Run it

pnpm dlx tsx index.ts

You should see an event sequence ending in AgentEnd, plus the assistant answer:

AgentStart -> TurnStart -> ... -> ToolExecutionCompleted -> ... -> AgentEnd
It is sunny in Barcelona.

What happened

  1. makeTool built a schema-backed tool definition and executor; its typed output is encoded into the result (render turns it into the text the model reads).
  2. resolveTools produced the model-visible ToolDef list and host executor.
  3. FauxProvider simulated a model calling get_weather, then answering.
  4. run streamed protocol events for model output, tool execution, assistant messages, and terminal state.

Move to your host app

In a real app you replace only the boundaries:

BoundaryReplace fake quickstart part with
ProvidermakeOpenAiProviderLayer, makeVercelAiGatewayProviderLayer, makeOpenAiCodexProviderLayer, makeAnthropicClaudeProviderLayer, or makeXAiGrokProviderLayer
Tool executorapp-owned tools, connector tools, MCP tools, knowledge search, sandbox tool
TransportNext route, Worker, Durable Object, CLI, or Workflow stream
Storagedatabase/session event log owned by your app
UIReact client helpers or app-owned chat state

Runtime choices

APIUse for
rununit tests, direct loop control, custom runtimes
runRuntime with Transcriptstateless HTTP route where client sends the transcript
runRuntime with AppendInputdurable session log, Worker/Durable Object, database-backed chat
@yolk-sdk/vercel-workflowslong-lived Vercel Workflow runs

Next steps:

On this page