-
Notifications
You must be signed in to change notification settings - Fork 5
feat(agents): Support for OpenAI Agents #508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b1afe2e
feat(agents): Initial implementation.
Murike 906a007
feat(agents): Tests for initial implementation.
Murike 9016c3a
feat(agents): Rebased to integrate new sdkLogger.
Murike 3b8995e
fix(agents): Updated galileo-generated version, fixed parseUsage read…
Murike b69d4ae
fix(agents): Added support to log orphaned spans on onSpanStart.
Murike a82115a
fix(agents): Improved support for agent spans.
Murike 98eb59c
fix(agents): firstInput refactored to feed first input data to span.
Murike 2aa8c8b
fix(agents): Moved import test to inside constructor, to avoid promti…
Murike ed8290a
fix(agents): Added processing of custom galileoSpan.
Murike a0f4289
fix(agents): Added statusCode propagation for workflow spans.
Murike cf052ca
feature(examples): Added example for openai-agents.
Murike 1597d88
fix(workflow): Refactored agent span processing to mirror current Pyt…
Murike feb0a11
feature(serialization): Updated serialization method (to toStringReco…
Murike d5ca5e1
feature(serialization): Centralized serialization of input and output…
Murike 10d99df
fix(tools): Assigning tools to correct field, instead of serializing …
Murike c14a126
feat(custom): Refactored process to manage custom (galileo) spans, fo…
Murike 151496d
feat(error): Refactored support for status code and error.
Murike e55124b
feat(error): Refactored support for status code and error (2).
Murike 0555828
feat(lastOutput): Adjusted rule to recover value for _lastOutput.
Murike 02d0965
chore(organization): Refactored code adding new functions for reusing…
Murike f8111bc
chore(parseUsage): Refactored repeated use of parseUsage.
Murike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import dotenv from 'dotenv'; | ||
| import { z } from 'zod'; | ||
| import { Agent, run } from '@openai/agents'; | ||
| import { | ||
| init, | ||
| flush, | ||
| registerGalileoTraceProcessor | ||
| } from '../../dist/index.js'; | ||
|
|
||
| dotenv.config(); | ||
|
|
||
| await init({ | ||
| projectName: 'openai-agents-example' | ||
| }); | ||
|
|
||
| await registerGalileoTraceProcessor(); | ||
|
|
||
| const triageAgent = new Agent({ | ||
| name: 'Triage Agent', | ||
| instructions: | ||
| 'You determine which agent should handle the user request. ' + | ||
| 'If the question is about weather, hand off to the Weather Agent. ' + | ||
| 'Otherwise, answer the question yourself.', | ||
| handoffs: [] // populated below after declaring weatherAgent | ||
| }); | ||
|
|
||
| const weatherAgent = new Agent({ | ||
| name: 'Weather Agent', | ||
| instructions: | ||
| 'You provide weather information. ' + | ||
| 'Given a city name, respond with a short, friendly weather summary. ' + | ||
| 'Make up plausible weather data for demonstration purposes.', | ||
| tools: [ | ||
| tool({ | ||
| name: 'get_weather', | ||
| description: 'Get the current weather for a city', | ||
| parameters: z.object({ | ||
| city: z.string().describe('The city to get weather for') | ||
| }), | ||
| execute: async (params) => { | ||
| const { city } = params; | ||
| const temps = { london: 14, tokyo: 22, 'new york': 18, paris: 16 }; | ||
| const temp = | ||
| temps[city.toLowerCase()] ?? Math.floor(Math.random() * 30); | ||
| return JSON.stringify({ | ||
| city, | ||
| temperature_c: temp, | ||
| condition: temp > 20 ? 'Sunny' : 'Partly cloudy' | ||
| }); | ||
| } | ||
| }) | ||
| ] | ||
| }); | ||
|
|
||
| triageAgent.handoffs.push(weatherAgent); | ||
|
|
||
| async function main() { | ||
| console.log('=== OpenAI Agents SDK + Galileo Tracing ===\n'); | ||
|
|
||
| console.log('--- Simple single-agent run ---'); | ||
| const simpleResult = await run(triageAgent, 'What is 2 + 2?'); | ||
| console.log('Response:', simpleResult.finalOutput, '\n'); | ||
|
|
||
| console.log('--- Handoff + tool call run ---'); | ||
| const weatherResult = await run(triageAgent, "What's the weather in Tokyo?"); | ||
| console.log('Response:', weatherResult.finalOutput, '\n'); | ||
|
|
||
| await flush(); | ||
| console.log('Done — traces flushed to Galileo.'); | ||
| } | ||
|
|
||
| main().catch((err) => { | ||
| console.error('Unhandled error:', err); | ||
| process.exit(1); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
|
||
| /** | ||
| * Duck-typed interface describing the expected shape of a Galileo span object | ||
| * that can be injected into the OpenAI Agents tracing flow. | ||
| * | ||
| * Mirrors the fields extracted by galileo-python's GalileoCustomSpan handler: | ||
| * input, output, metadata (user_metadata), tags, status_code, and type. | ||
| */ | ||
| export interface GalileoSpanLike { | ||
| type?: string; | ||
| input?: unknown; | ||
| output?: unknown; | ||
| name?: string; | ||
| metadata?: Record<string, string>; | ||
| tags?: string[]; | ||
| statusCode?: number; | ||
| } | ||
|
|
||
| /** | ||
| * A lightweight subtype of CustomSpanData that carries a reference to a | ||
| * pre-configured GalileoSpan so it can be injected into the agent tracing flow. | ||
| * | ||
| * The __galileoCustom flag is used by mapSpanType() to distinguish this from | ||
| * ordinary CustomSpanData objects. | ||
| */ | ||
| export interface GalileoCustomSpanData { | ||
| /** Always 'custom' to satisfy the SDK's SpanData union discriminant. */ | ||
| type: 'custom'; | ||
| /** (Optional) Display name for the span. */ | ||
| name?: string; | ||
| /** Arbitrary data payload, must contain a 'galileoSpan' key with the GalileoSpan reference. */ | ||
| data: Record<string, unknown> & { galileoSpan: GalileoSpanLike }; | ||
| /** Sentinel flag used internally by mapSpanType() to identify this type. */ | ||
| __galileoCustom: true; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a GalileoCustomSpanData object that wraps an existing Galileo span. | ||
| * @param galileoSpan - The Galileo span object to embed. | ||
| * @param name - (Optional) Display name for the span. | ||
| * @param extraData - (Optional) Additional data to include in the span data payload. | ||
| * @returns A GalileoCustomSpanData object. | ||
| */ | ||
| export function createGalileoCustomSpanData( | ||
| galileoSpan: GalileoSpanLike, | ||
| name?: string, | ||
| extraData?: Record<string, unknown> | ||
| ): GalileoCustomSpanData { | ||
| return { | ||
| type: 'custom', | ||
| name, | ||
| data: { | ||
| ...extraData, | ||
| galileoSpan | ||
| }, | ||
| __galileoCustom: true | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Type guard that checks whether a span data object is a GalileoCustomSpanData. | ||
| * @param spanData - The span data to check. | ||
| * @returns True if the span data is a GalileoCustomSpanData. | ||
| */ | ||
| export function isGalileoCustomSpanData( | ||
| spanData: unknown | ||
| ): spanData is GalileoCustomSpanData { | ||
| return ( | ||
| typeof spanData === 'object' && | ||
| spanData !== null && | ||
| (spanData as any).__galileoCustom === true | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.