Troupekit and Mastra
Mastra is a TypeScript framework for agents and workflows. We compared @mastra/core at 1.86.0, checked on 2026-11-28. Of the TypeScript frameworks we looked at, Mastra overlaps with troupekit the most: durable runs, a USD cap, local tracing and evals are all there.
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 Mastra
The agent and its tool, from the tools page (tools.mdx); __GATEWAY_OPENAI_MODEL__ is filled in by their docs build:
import { createTool } from '@mastra/core/tools'
import { z } from 'zod'
export const weatherTool = createTool({
id: 'weather-tool',
description: 'Fetches weather for a location',
inputSchema: z.object({
location: z.string(),
}),
outputSchema: z.object({
location: z.string(),
temperatureCelsius: z.number(),
conditions: z.string(),
}),
execute: async ({ location }, { abortSignal }) => {
const response = await fetch(`https://wttr.in/${location}?format=j1`, {
signal: abortSignal,
})
const data = await response.json()
return {
location,
temperatureCelsius: Number(data.current_condition[0].temp_C),
conditions: data.current_condition[0].weatherDesc[0].value,
}
},
})
import { Agent } from '@mastra/core/agent'
import { weatherTool } from '../tools/weather-tool'
export const weatherAgent = new Agent({
id: 'weather-agent',
name: 'Weather Agent',
instructions: `
You are a helpful weather assistant.
Use the weatherTool to fetch current weather data.`,
model: '__GATEWAY_OPENAI_MODEL__',
tools: { weatherTool },
})
Durability lives in workflows. A run's snapshots go to the storage adapter on the Mastra instance, libSQL by default (snapshots.mdx), and "restarting a workflow run will resume execution from the last active step" (overview.mdx). An agent gets the same by being wrapped as a durable agent, which runs its loop inside a workflow (durable-agents.mdx). From the restart reference (restart.mdx):
const run = await workflow.createRun()
const result = await run.start({ inputData: { value: 'initial data' } })
const restartedResult = await run.restart()
The cap is the TokenCostControl processor, with maxCost in US dollars (token-cost-control.mdx).
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
| Mastra 1.86.0 | Troupekit 0.4 | |
|---|---|---|
| Durability | Workflow snapshots in libSQL, PostgreSQL, Upstash or OracleDB; the server restarts active runs on boot, and a restarted run repeats the interrupted step, so steps with side effects must be idempotent (overview.mdx) | Checkpoint after every step once checkpoints use Storage::sqlite; a replayed tool call carries the same idempotency key |
| Spend limits | TokenCostControl in USD; the docs say to "treat maxCost as an approximate threshold that fast-running agents may exceed" (token-cost-control.mdx) | USD per call, per run and per period, when you set them; checked before each call on an estimate that counts the full max_tokens of output but only approximates input as a quarter of the request's JSON bytes |
| Tracing | Built in, stored in Mastra storage and viewed in Studio, with Langfuse, Datadog and OpenTelemetry exporters (observability) | Built-in tracer, JSONL and an HTML viewer |
| Evals | Built-in scorers, datasets and experiments (evals) | Evals on the persona, checked on every run |
| Offline and on-device | Ollama and LM Studio as servers (ollama.mdx); no in-process model found | llama.cpp in process, Ollama, and a route policy per call |
| Mobile | No React Native, iOS or Android docs found | Builds for iOS and Android in CI; Swift and Kotlin bindings since 0.4, built from source |
| Single binary | Needs Node 22.13 or newer (package.json) | Compiles into your program |
Where Mastra is better
Studio, a local UI for building, testing and managing agents and workflows (studio), and breadth: more than 300 provider pages in its docs at this tag, five storage back ends, and MCP as client and server. Troupekit has no visual tool and plans MCP for 0.6.
Where troupekit is different
The checkpointing is per step of any agent, not only inside a workflow, and a cap you set is checked before the call rather than as an approximate threshold. It is not exact either: input tokens are estimated, and a run's hold on a shared period cap counts only inside its own process, so the cap is not enforced across processes. The model can run in the same process, and the same core builds for phones.