Quickstart
Run your first agent with runAgent, StaticModel, and a custom tool — no API key required.
The fastest way to see the agent loop is runAgent with a deterministic StaticModel and one tool(). This mirrors packages/agents/examples/quickstart.ts.
Define a tool
import { tool } from "@maniac-ai/agents";
const lookupOrder = tool({
name: "lookup_order",
description: "Look up an order by id.",
inputSchema: {
type: "object",
properties: {
order_id: { type: "string" }
},
required: ["order_id"]
},
handler: ({ order_id }) => ({ order_id, status: "in_transit" })
});tool() validates arguments against inputSchema, invokes handler, and returns a typed ToolResult ({ ok: true, value } or { ok: false, error }).
Script the model
StaticModel replays a fixed sequence of InferenceResponse objects — useful for tests and offline demos:
import { StaticModel } from "@maniac-ai/agents";
const model = new StaticModel([
{
content: "",
usage: { prompt: 1, completion: 1 },
finish_reason: "stop",
tool_calls: [
{
id: "call_1",
name: "lookup_order",
arguments: { order_id: "ord_123" }
}
]
},
{
content: "Your order is in transit.",
usage: { prompt: 1, completion: 4 },
finish_reason: "stop",
tool_calls: []
}
]);Run the agent
import { runAgent } from "@maniac-ai/agents";
const result = await runAgent(
{
id: "support",
instructions: "You are a concise support agent.",
model,
tools: [lookupOrder]
},
"Where is my order?"
);
console.log(result.final);
// => "Your order is in transit."runAgent returns an AgentResult with status, final, messages, usage, and a trace event log.
Live provider
Swap StaticModel for a real adapter when you have an API key:
import { OpenAICompatibleModel, runAgent } from "@maniac-ai/agents";
const model = new OpenAICompatibleModel({
slug: "gpt-4o-mini"
});
const result = await runAgent(
{ id: "assistant", instructions: "Be concise.", model },
"Summarize the release checks."
);OpenAICompatibleModel reads OPENAI_API_KEY by default. Set OPENAI_BASE_URL for local or proxy OpenAI-compatible endpoints. See Inference adapters for OpenRouter, Vercel Gateway, and Anthropic.