import { Agent, tool, run }
from '@openai/agents';
import { z } from 'zod';
const getWeather = tool({
name: 'get_weather',
description: 'Get weather for a city.',
parameters: z.object({
city: z.string(),
}),
execute: async ({ city }) =>
`72F, Sunny in ${city}`,
});
const agent = new Agent({
name: 'weather_agent',
instructions: 'You are helpful.',
model: 'gpt-4o-mini',
tools: [getWeather],
});
const result = await run(
agent,
'What is the weather in SF?',
);
console.log(result.finalOutput);
|
import { Agent, tool, setTracingDisabled }
from '@openai/agents';
// ^^^ replace run() with setTracingDisabled
import { z } from 'zod';
import { AgentRuntime } from '@io-orkes/conductor-javascript/agents';
// ^^^ add agentspan import
const getWeather = tool({
name: 'get_weather',
description: 'Get weather for a city.',
parameters: z.object({
city: z.string(),
}),
execute: async ({ city }) =>
`72F, Sunny in ${city}`,
});
const agent = new Agent({
name: 'weather_agent',
instructions: 'You are helpful.',
model: 'gpt-4o-mini',
tools: [getWeather],
});
// ^^^ agent definition is identical
setTracingDisabled(true); // optional
const runtime = new AgentRuntime();
const result = await runtime.run(
// ^^^ runtime.run() instead of run()
agent,
'What is the weather in SF?',
);
result.printResult();
await runtime.shutdown();
|