import { Agent, openai } from "@agentium/core";const agent = new Agent({ name: "assistant", model: openai("gpt-4o"), instructions: "You are a helpful assistant.",});const result = await agent.run("What is TypeScript?");console.log(result.text);
Run it:
npx tsx index.ts
You now have a working agent that responds to user input.
Extend your agent with function calling. Define tools with Zod schemas for type-safe parameters:
weather-agent.ts
import { Agent, openai, defineTool } from "@agentium/core";import { z } from "zod";const weatherTool = defineTool({ name: "get_weather", description: "Get current weather for a city", parameters: z.object({ city: z.string().describe("City name"), }), execute: async ({ city }) => `Weather in ${city}: 72°F, sunny`,});const agent = new Agent({ name: "weather-bot", model: openai("gpt-4o"), instructions: "You help users check the weather.", tools: [weatherTool],});const result = await agent.run("What's the weather in Tokyo?");console.log(result.text);
The agent will call get_weather when needed and incorporate the result into its response.
import { Agent, openai } from "@agentium/core";const agent = new Agent({ name: "assistant", model: openai("gpt-4o"), instructions: "You are a helpful assistant.",});for await (const chunk of agent.stream("Tell me a joke")) { if (chunk.type === "text") { process.stdout.write(chunk.text); }}
Streaming supports both text and tool-call chunks. Handle each chunk.type as needed for your use case.