Agents in TypeScript, typed from tool to stream

Kikoyu is a small SDK for backend engineers. Define tools with Zod, hand off between agents, keep session memory, and stream every step of a run as a typed event.

Get started
eventsstreaming

input

I need a refund for invoice #INV-9921

0.412s handoff_occurred: Triage Router → Billing Specialist. 0.968s tool_call_started: process_refund { invoiceId: "INV-9921" }. 0.971s tool_approval_requested: process_refund · approved: true. 1.204s tool_call_finished: { status: "REFUNDED", amount: "$49.00" }. 1.388s text_delta: "Refunded $49.00 for INV-9921.". 1.902s run_complete: agent: Billing Specialist
Typed stream events
9
One union, from text_delta to run_complete
Model providers
3
OpenAI, Anthropic and Gemini, chained with FallbackProvider
Memory stores
4
In-memory, file, Redis and Mem0
Vitest cases
38
Across core and the HTTP API package

Six primitives and one Runner

Each one is a documented export of @kikoyu/core. Use the ones a run needs and leave the rest out.

createTool()

Write the schema once

Tool parameters are a Zod schema. Kikoyu turns it into the JSON Schema the model sees, then checks the model’s arguments against the same schema before execute runs.

Tools guide
refund.tsyou write
parameters: z.object({  invoiceId: z.string().regex(/^INV-\d{4}$/),  reason: z.enum(['duplicate', 'damaged', 'not_received']),}),
zodToJsonSchema(parameters)the model receives
{  "type": "object",  "properties": {    "invoiceId": { "type": "string", "pattern": "^INV-\\d{4}$" },    "reason": {      "type": "string",      "enum": ["duplicate", "damaged", "not_received"]    }  },  "required": ["invoiceId", "reason"],  "additionalProperties": false}

From install to a first run in three steps

The quickstart uses the same calls as the tests in packages/core/test, so the snippets you copy are the ones under test.

  1. 01

    Install the package

    Zod is a peer dependency, so your schemas stay in your own codebase.

    $ pnpm add @kikoyu/core zod
  2. 02

    Build an agent

    Name, instructions, tools and model settings all live on one builder.

    const agent = Agent.builder()  .setName('Assistant')  .setInstructions('Be brief.')  .addTool(getStockPrice)  .build();
  3. 03

    Run it

    runner.run() returns the final text and the agent that wrote it.

    const runner = new Runner();const result = await runner.run(  agent,  'What is AAPL trading at?',);
    console.log(result.text);

How a run moves through the SDK

Each stage names the events it can emit, so whatever reads the stream knows what to expect and when.

Input

Your app passes a message to the runner, with an optional session and context. Input guardrails run here, one after another, before the first model call.

Call

runner.stream(agent, input, { session, context })

Events

  • guardrail_triggered
  • run_failed

Only when a guardrail blocks the input

Patterns from the docs

Each pattern has a guide in the docs and a runnable script in the examples package.

  • Single agent with tools

    A financial agent with Zod-typed tools for stock price and trading volume.

    Read the guide
    const result = await runner.run(  financialAgent,  'What is the current stock price and trading volume of AAPL?',);
  • Multi-agent handoff

    A triage router that hands coding questions to a code specialist and math to a math specialist.

    Read the guide
    const result = await runner.run(  triageRouter,  'Write a TypeScript function that checks for a palindrome',);
    result.agent.name; // 'Code Specialist'
  • Session memory

    Two turns that share one session, so the second answer remembers the first.

    Read the guide
    const session = new Session({ sessionId: 'session_usr_1042', store });
    await runner.run(agent, 'My usual order is an iced oat latte.', { session });await runner.run(agent, 'What should I order today?', { session });
  • Streaming

    Write text to stdout as it arrives and log every tool the model calls.

    Read the guide
    for await (const event of runner.stream(agent, input)) {  if (event.type === 'text_delta') process.stdout.write(event.delta);  if (event.type === 'tool_call_started') log(event.toolCall.name);}

Read the source before you adopt it

Kikoyu is MIT licensed and published on npm. The API reference is generated from the TypeScript source, so the docs list exactly what the package exports.

Version
0.1.13
License
MIT
Modules
ESM and CommonJS

Found something the docs get wrong? Open an issue