Skip to content
providerkit
GitHub

Agents quickstart

await assistant.run("List the tasks.");

The complete example defines assistant. A scripted provider asks a tool for two tasks, then returns the tool’s answer. It makes no model calls and needs no API key.

Install the released package and its matching Core peer in a new folder:

Terminal window
bun add @providerkit/[email protected] @providerkit/[email protected]
bun node_modules/@providerkit/agents/examples/basic.ts

Expected output:

["Write a release note", "Check the documentation link"]

Agents 0.4.3 accepts Core ^0.35.1 or ^0.36.0. The optional integrations have their own peer dependencies; the basic example does not need a server package, MCP, tracing or a code engine.

Pass a configured Core provider into your agent:

import { defineAgent } from "@providerkit/agents";
import type { Provider } from "@providerkit/core";
export function createWriter(provider: Provider) {
return defineAgent({
id: "writer",
version: "1",
instructions: "Explain technical topics in short sentences.",
provider,
});
}

The offline example is free to run. Replacing its scripted provider with a live one sends requests to that provider and may cost money.

const result = await writer.run("Explain database indexes.");
if (result.status === "completed") {
console.log(result.output);
} else {
console.log(result.status);
}

A run can also be suspended for approval, cancelled, limited or failed. Do not treat those as complete answers. A failed result includes an error with a code and message.

const analyst = defineAgent({ ...config, limits: { costUsd: 1.5 } });
await analyst.run(question, { host: { priceModelCall: ({ usage }) => costUsd(usage, rate) } });

Once the calls this run and its helpers made cost $1.50, no new call starts and the run ends limited with limit: "costUsd". Your host supplies the prices: Core’s costUsd turns token counts into dollars with your own rates. A tool that pays for something itself, such as a paid API, adds the amount with context.reportCost(usd), and the limit counts it. Calls that were already running can finish above the limit. With finish, reaching the limit buys one more call to give the answer, priced and counted like any other, so the limit is soft by that one call. The cost limit section covers helpers, workflows and resume.

Change the agent’s version when its instructions, tools or result contract change. A saved run from another version is refused rather than continued under new rules.

Next: specialist examples, the API reference and tools and permissions.