Skip to content

Commit ce62f7c

Browse files
authored
Fix #117 workflowName, groupId, traceMetadata passed to Runner are not set (#121)
1 parent fb9ca4f commit ce62f7c

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

.changeset/swift-eyes-heal.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openai/agents-core': patch
3+
---
4+
5+
Fix #117 by adding groupId, metadata to trace data

examples/basic/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { z } from 'zod';
2-
import { Agent, run, tool } from '@openai/agents';
2+
import { Agent, Runner, tool } from '@openai/agents';
33

44
const getWeatherTool = tool({
55
name: 'get_weather',
@@ -24,7 +24,14 @@ const agent = new Agent({
2424
});
2525

2626
async function main() {
27-
const result = await run(agent, 'What is the weather in San Francisco?');
27+
const runner = new Runner({
28+
groupId: 'My group',
29+
traceMetadata: { user_id: '123' },
30+
});
31+
const result = await runner.run(
32+
agent,
33+
'What is the weather in San Francisco?',
34+
);
2835

2936
console.log(result.finalOutput);
3037
}

packages/agents-core/src/run.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export type RunConfig = {
127127
/**
128128
* An optional dictionary of additional metadata to include with the trace.
129129
*/
130-
traceMetadata?: Record<string, any>;
130+
traceMetadata?: Record<string, string>;
131131
};
132132

133133
type SharedRunOptions<TContext = undefined> = {
@@ -956,13 +956,21 @@ export class Runner extends RunHooks<any, AgentOutputType<unknown>> {
956956
});
957957
}
958958

959-
return getOrCreateTrace(async () => {
960-
if (options?.stream) {
961-
return this.#runIndividualStream(agent, input, options);
962-
} else {
963-
return this.#runIndividualNonStream(agent, input, options);
964-
}
965-
});
959+
return getOrCreateTrace(
960+
async () => {
961+
if (options?.stream) {
962+
return this.#runIndividualStream(agent, input, options);
963+
} else {
964+
return this.#runIndividualNonStream(agent, input, options);
965+
}
966+
},
967+
{
968+
traceId: this.config.traceId,
969+
name: this.config.workflowName,
970+
groupId: this.config.groupId,
971+
metadata: this.config.traceMetadata,
972+
},
973+
);
966974
}
967975
}
968976

0 commit comments

Comments
 (0)