Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Troupekit and the AI SDK

The AI SDK from Vercel is a TypeScript toolkit for model calls, agents and chat UIs. We compared the ai package at 7.0.184, checked on 2026-11-28.

The same agent

The test agent is small on purpose: a persona, one tool, a run that is killed and resumed, and a spend cap.

In the AI SDK

The docs show instructions and a tool in two separate examples (building-agents.mdx); __PROVIDER_IMPORT__ and __MODEL__ are filled in by their docs build:

import { ToolLoopAgent } from 'ai';
__PROVIDER_IMPORT__;

const agent = new ToolLoopAgent({
  model: __MODEL__,
  instructions: 'You are an expert software engineer.',
});
import { ToolLoopAgent, tool } from 'ai';
__PROVIDER_IMPORT__;
import { z } from 'zod';

const codeAgent = new ToolLoopAgent({
  model: __MODEL__,
  tools: {
    runCode: tool({
      description: 'Execute Python code',
      inputSchema: z.object({
        code: z.string(),
      }),
      execute: async ({ code }) => {
        // Execute code and return result
        return { output: 'Code executed successfully' };
      },
    }),
  },
});

A ToolLoopAgent does not survive a kill: its docs say a standard ToolLoopAgent runs entirely in memory, and if the process crashes, all progress is lost (workflow-agent.mdx). For that you add @ai-sdk/workflow and the Workflow DevKit runtime, workflow@5, and mark each tool's execute with 'use step'; tools without it run without durability (workflow-agent.mdx). Outside Vercel the default store is a local one meant for development; to self-host you use its Postgres back end or write your own (worlds.mdx).

There is no built-in spend cap. The loop-control docs show a stop condition you write yourself, with prices typed in (loop-control.mdx):

  const costEstimate =
    (totalUsage.inputTokens * 0.01 + totalUsage.outputTokens * 0.03) / 1000;
  return costEstimate > 0.5; // Stop if cost exceeds $0.50

In troupekit

The persona is the doc comment and the tool is a #[tool] function. This is the tool_agent example:

#![allow(unused)]
fn main() {
/// Adds numbers with the add tool.
#[agent(model = "openai/gpt-6-luna", tools = [add])]
fn calc() {}
}

A role, a goal, evals, a spend cap of 5 000 millionths of a dollar per run and the checkpoint store are keys on the same macro. This one is from a test of the kit:

#![allow(unused)]
fn main() {
#[agent(
    model = "fake/m",
    role = "Checks facts.",
    goal = "A short answer.",
    display_name = "Fact Checker",
    evals = ["min_items(items, 1)"],
    limits = Limits { run: Some(5_000), ..Limits::default() },
    checkpoints = Storage::memory(),
    max_turns = 3,
    max_tokens = 256,
    retries = 1,
    laws = "tests/fixtures/rules.bend",
    auto_laws = false,
)]
}

In 0.4 the laws key is validated at build and not enforced by the run (Proofs and laws). With the SQLite store as checkpoints, a new process resumes a killed run by its id. This is the kill_model_call example, which is killed in the middle of a local model call:

#![allow(unused)]
fn main() {
("resume", Some(id)) => {
    let run_id: RunId = serde_json::from_str(&format!("\"{id}\""))?;
    let text = built.resume(run_id).await?;
    println!("RESUMED {}", text.len());
}
}

Nothing else is needed: no server, no second process to run the engine, no Python. Durable runs and Spend limits say what each part guarantees.

Side by side

AI SDK 7.0.184Troupekit 0.4
DurabilitySeparate @ai-sdk/workflow and workflow packages, tools marked 'use step', and a store: local for development, Postgres or your own to self-hostBuilt in, opt-in: checkpoint after every step once checkpoints use Storage::sqlite; the default in-memory store is lost when the process exits
Spend limitsNone built in; step caps, 20 steps by default (loop-control.mdx)USD per call, per run and per period, when you set them; checked before each call
TracingOpenTelemetry through @ai-sdk/otel, and DevTools for local development (telemetry.mdx)Built-in tracer, JSONL and an HTML viewer
EvalsNone found in the docsEvals on the persona, checked on every run
Offline and on-deviceCommunity providers: llama.cpp in Node (llama-cpp.mdx), Ollama, and Apple's on-device models from iOS 26 through React Native (react-native-apple.mdx)llama.cpp in process, Ollama, and a route policy per call; Apple and Android on-device models through the Swift and Kotlin bindings since 0.4
MobileAn Expo quickstart whose model call runs in a server route (expo.mdx), plus the community provider aboveBuilds for iOS and Android in CI; Swift and Kotlin bindings since 0.4, built from source
Single binaryNeeds Node 22 or newer (package.json)Compiles into your program

Where the AI SDK is better

Web apps. Its UI hooks, useChat, useCompletion and useObject, stream answers into React, Svelte, Vue and more (ui overview), and it has 51 first-party and 63 community provider pages, MCP tools and per-tool approval today. Troupekit has no TypeScript binding at all, and pauses for a person only at a workflow's human node.

Where troupekit is different

Durability and a money cap are part of the agent, not extra packages or code you write. It has graph workflows built in, where the AI SDK documents workflow patterns as plain code (workflows.mdx).