Skip to content

Commit 0565bf1

Browse files
Add providerData to model responses (#104)
* feat(core): expose model response via details * Create shaggy-teachers-worry.md
1 parent 59e75c2 commit 0565bf1

File tree

8 files changed

+28
-0
lines changed

8 files changed

+28
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@openai/agents-core": patch
3+
"@openai/agents-extensions": patch
4+
"@openai/agents-openai": patch
5+
"@openai/agents-realtime": patch
6+
---
7+
8+
Add details to output guardrail execution

packages/agents-core/src/guardrail.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ModelItem } from './types/protocol';
22
import { Agent, AgentOutputType } from './agent';
33
import { RunContext } from './runContext';
44
import { ResolvedAgentOutput, TextOutput, UnknownContext } from './types';
5+
import type { ModelResponse } from './model';
56

67
/**
78
* Definition of input/output guardrails; SDK users usually do not need to create this.
@@ -149,6 +150,13 @@ export interface OutputGuardrailFunctionArgs<
149150
agent: Agent<any, any>;
150151
agentOutput: ResolvedAgentOutput<TOutput>;
151152
context: RunContext<TContext>;
153+
/**
154+
* Additional details about the agent output.
155+
*/
156+
details?: {
157+
/** Model response associated with the output if available. */
158+
modelResponse?: ModelResponse;
159+
};
152160
}
153161
/**
154162
* The result of an output guardrail execution.

packages/agents-core/src/model.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ export type ModelResponse = {
221221
* model. Not supported by all model providers.
222222
*/
223223
responseId?: string;
224+
225+
/**
226+
* Raw response data from the underlying model provider.
227+
*/
228+
providerData?: Record<string, any>;
224229
};
225230

226231
/**

packages/agents-core/src/run.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ export class Runner extends RunHooks<any, AgentOutputType<unknown>> {
543543
agent: state._currentAgent,
544544
agentOutput,
545545
context: state._context,
546+
details: { modelResponse: state._lastTurnResponse },
546547
};
547548
try {
548549
const results = await Promise.all(

packages/agents-core/src/runState.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const modelResponseSchema = z.object({
8282
usage: usageSchema,
8383
output: z.array(protocol.OutputModelItem),
8484
responseId: z.string().optional(),
85+
providerData: z.record(z.string(), z.any()).optional(),
8586
});
8687

8788
const itemSchema = z.discriminatedUnion('type', [
@@ -388,6 +389,7 @@ export class RunState<TContext, TAgent extends Agent<any, any>> {
388389
},
389390
output: response.output as any,
390391
responseId: response.responseId,
392+
providerData: response.providerData,
391393
};
392394
}),
393395
context: this._context.toJSON(),
@@ -635,6 +637,7 @@ export function deserializeModelResponse(
635637
protocol.OutputModelItem.parse(item),
636638
),
637639
responseId: serializedModelResponse.responseId,
640+
providerData: serializedModelResponse.providerData,
638641
};
639642
}
640643

packages/agents-extensions/src/aiSdk.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ export class AiSdkModel implements Model {
449449
result.usage.promptTokens + result.usage.completionTokens,
450450
}),
451451
output,
452+
providerData: result,
452453
};
453454
} catch (error) {
454455
if (error instanceof Error) {

packages/agents-openai/src/openaiChatCompletionsModel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export class OpenAIChatCompletionsModel implements Model {
141141
: new Usage(),
142142
output,
143143
responseId: response.id,
144+
providerData: response,
144145
};
145146

146147
return modelResponse;

packages/agents-openai/src/openaiResponsesModel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ export class OpenAIResponsesModel implements Model {
856856
}),
857857
output: convertToOutputItem(response.output),
858858
responseId: response.id,
859+
providerData: response,
859860
};
860861

861862
return output;

0 commit comments

Comments
 (0)