From 61e8a07314d4f77c81793052d63fe0adf9d34c49 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Wed, 6 May 2026 14:59:48 -0700 Subject: [PATCH] feat(agent-sdk): add basic usage example --- sdks/typescript-agent-sdk/examples/basic.ts | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sdks/typescript-agent-sdk/examples/basic.ts diff --git a/sdks/typescript-agent-sdk/examples/basic.ts b/sdks/typescript-agent-sdk/examples/basic.ts new file mode 100644 index 00000000000..06ff9b668bc --- /dev/null +++ b/sdks/typescript-agent-sdk/examples/basic.ts @@ -0,0 +1,42 @@ +/** + * Basic example — Agent.create -> session.send -> stream -> wait. + * + * Run with: + * LITELLM_API_KEY=sk-... LITELLM_BASE_URL=http://localhost:4000 \ + * npx tsx examples/basic.ts + */ + +import { Agent } from "../src/index.js"; + +async function main(): Promise { + const agent = await Agent.create({ + apiKey: process.env.LITELLM_API_KEY, + baseUrl: process.env.LITELLM_BASE_URL, + name: "basic-example", + model: { id: "claude-4.6-sonnet" }, + systemPrompt: "You are a helpful assistant.", + }); + + console.log("agent created:", agent.id); + + const session = await agent.createSession(); + console.log("session created:", session.id); + + const run = await session.send("Say hi in one short sentence."); + console.log("run started:", run.id); + + for await (const event of run.stream()) { + console.log(`[${event.seq}] ${event.type}`, event.data); + } + + const result = await run.wait(); + console.log("final status:", result.status); + console.log("result:", result.result); + + await session.delete(); +} + +main().catch((err) => { + console.error(err); + process.exit(1); +});