Documentation
Examples
Copy these as starting points. Replace key with process.env.OPENAI_API_KEY!. Repo files: examples/basic.ts, examples/graph.ts.
Copy these as starting points. Replace key with process.env.OPENAI_API_KEY!. Repo files: examples/basic.ts, examples/graph.ts.
terminal
npx tsx examples/basic.ts1. Support bot (tools + session + memory)
Use: a help-center chat that can search docs and remembers the customer across turns.
support.ts
import { Agent, tool } from "shirube-ai";
import { z } from "zod";
const search = tool({
name: "search_docs",
description: "Search the help center for policies and how-tos.",
parameters: z.object({ query: z.string() }),
execute: async ({ input }) => docs.search(input.query),
});
const agent = Agent.builder()
.name("support")
.instructions("Help customers. Search docs before guessing. Be brief.")
.apiKey(key)
.tools([search])
.memory({ provider: "in-memory" })
.build();
await agent.run("How do I reset my password?", {
userId: "cus_ada",
sessionId: "chat_1",
});2. Knowledge graph (remember people and projects)
Use: the next ticket should already know Ada works on Shirube.
graph-example.ts
import { Agent, graph } from "shirube-ai";
graph.start();
const agent = Agent.builder()
.name("ops")
.instructions("Use graph facts about this user. Do not invent projects.")
.apiKey(key)
.graph(true)
.build();
await agent.run("I'm Ada, working on Project Shirube using TypeScript.", {
userId: "ada",
});
await graph.flush();
await agent.run("What stack do I use on Shirube?", { userId: "ada" });3. Triage → billing handoff
Use: one public bot, specialists behind it.
handoff-example.ts
const billing = Agent.builder()
.name("billing")
.instructions("Invoices and charges only.")
.apiKey(key)
.build();
const triage = Agent.builder()
.name("triage")
.instructions("If this is about money or invoices, transfer to billing.")
.apiKey(key)
.handoffs([billing])
.build();
await triage.run("Why was I charged twice?");4. Ticket classifier (structured JSON)
Use: Slack → agent → insert row in tickets.
classifier-example.ts
const schema = z.object({
label: z.enum(["bug", "billing", "other"]),
confidence: z.number(),
summary: z.string(),
});
const agent = Agent.builder()
.name("classifier")
.instructions("Classify the message.")
.apiKey(key)
.output(schema)
.build();
const { outputParsed } = await agent.run(slackMessage);5. Streaming UI
Use: token-by-token (or chunked) display plus tool spinners.
stream-example.ts
for await (const event of agent.runStream(prompt, { userId })) {
if (event.type === "text.streamed") appendToBubble(event.data?.delta);
if (event.type === "tool.started") setSpinner(event.data?.name);
}6. MCP ops agent
Use: company GitHub tools + your refund in one process; also expose refund to Cursor.
mcp-example.ts
mcp.configure({
internal: [refund],
external: [{ name: "github", command: "npx", args: ["-y", "@modelcontextprotocol/server-github"] }],
});
Agent.builder().name("ops").instructions("Use GitHub when asked.").mcp().build();
await mcp.serve({ transport: "stdio" });