This example demonstrates how to build an AI agent using the Vercel AI SDK with Galileo observability integration. The agent can retrieve weather information and perform temperature conversions using tool calling.
- Vercel AI SDK Agent: Uses the experimental Agent API from Vercel AI SDK
- Tool Calling: Implements custom tools for weather lookup and temperature conversion
- Galileo Observability: Integrated with OpenTelemetry to track agent execution, tool calls, and performance
- Type Safety: Leverages Zod schemas for type-safe tool definitions
- OpenAI Integration: Uses GPT-4-turbo model for intelligent agent responses
- Node.js 18+ installed
- OpenAI API key
- Galileo API key (sign up at https://app.galileo.ai)
- Clone the repository and navigate to this example:
cd typescript/agent/vercel-agent- Install dependencies:
npm install- Set up environment variables:
Create a .env file in the root directory with the following variables:
# OpenAI Configuration
OPENAI_API_KEY=your-openai-api-key
# Galileo Configuration
GALILEO_API_KEY=your-galileo-api-key
GALILEO_PROJECT=your-project-name
GALILEO_CONSOLE_URL=https://app.galileo.ai
GALILEO_LOG_STREAM=defaultnpm startnpm run devnpm run buildThe agent is configured with two custom tools:
- Weather Tool: Retrieves weather information for a given location (returns temperature in Fahrenheit)
- Temperature Converter: Converts temperature from Fahrenheit to Celsius
const weatherAgent = new Agent({
model: openai('gpt-4-turbo'),
tools: {
weather: tool({...}),
convertFahrenheitToCelsius: tool({...}),
},
stopWhen: stepCountIs(20),
experimental_telemetry: { isEnabled: true },
});The example uses OpenTelemetry to send traces to Galileo:
- Setup: The
setupOtel.tsfile configures the OpenTelemetry SDK with Galileo's OTLP endpoint - Automatic Tracing: When
experimental_telemetryis enabled, the Vercel AI SDK automatically generates telemetry data - Observability: View agent execution, tool calls, latencies, and errors in the Galileo dashboard
The agent handles complex queries like:
"What is the weather in San Francisco in celsius?"The agent will:
- Use the
weathertool to get the temperature in Fahrenheit - Use the
convertFahrenheitToCelsiustool to convert the temperature - Return a natural language response with the temperature in Celsius
vercel-agent/
├── src/
│ ├── index.ts # Main agent implementation
│ └── setupOtel.ts # OpenTelemetry configuration for Galileo
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # This file
- ai: Vercel AI SDK for building AI agents
- @ai-sdk/openai: OpenAI provider for Vercel AI SDK
- @vercel/otel: Vercel's OpenTelemetry package for optimized trace export
- @opentelemetry/sdk-node: OpenTelemetry SDK for Node.js
- zod: Type-safe schema validation for tool inputs
After running the agent:
- Log in to your Galileo account at https://app.galileo.ai
- Navigate to your project (specified in
GALILEO_PROJECT) - View the agent's execution traces, including:
- Agent steps and reasoning
- Tool calls with inputs and outputs
- Latency metrics
- Token usage
- Any errors or warnings
You can extend the agent with additional tools by adding them to the tools object:
tools: {
weather: tool({...}),
convertFahrenheitToCelsius: tool({...}),
yourNewTool: tool({
description: 'Description of what your tool does',
inputSchema: z.object({
param: z.string().describe('Parameter description'),
}),
execute: async ({ param }) => {
// Your tool logic here
return { result: 'value' };
},
}),
}Replace openai('gpt-4-turbo') with any supported model:
openai('gpt-4o') // Latest GPT-4 Omni
openai('gpt-4o-mini') // Smaller, faster GPT-4 Omni
openai('gpt-3.5-turbo') // GPT-3.5 TurboModify the stopWhen condition to control agent behavior:
stopWhen: stepCountIs(10) // Stop after 10 stepsIf traces aren't appearing in Galileo, enable debug logging in setupOtel.ts:
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);- Missing API Keys: Ensure all required environment variables are set
- Network Issues: Check that your application can reach Galileo's endpoint
- Telemetry Not Enabled: Verify
experimental_telemetry: { isEnabled: true }is set in the agent configuration