Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/shaggy-teachers-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@openai/agents-core": patch
"@openai/agents-extensions": patch
"@openai/agents-openai": patch
"@openai/agents-realtime": patch
---

Add details to output guardrail execution
8 changes: 8 additions & 0 deletions packages/agents-core/src/guardrail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ModelItem } from './types/protocol';
import { Agent, AgentOutputType } from './agent';
import { RunContext } from './runContext';
import { ResolvedAgentOutput, TextOutput, UnknownContext } from './types';
import type { ModelResponse } from './model';

/**
* Definition of input/output guardrails; SDK users usually do not need to create this.
Expand Down Expand Up @@ -149,6 +150,13 @@ export interface OutputGuardrailFunctionArgs<
agent: Agent<any, any>;
agentOutput: ResolvedAgentOutput<TOutput>;
context: RunContext<TContext>;
/**
* Additional details about the agent output.
*/
details?: {
/** Model response associated with the output if available. */
modelResponse?: ModelResponse;
};
}
/**
* The result of an output guardrail execution.
Expand Down
5 changes: 5 additions & 0 deletions packages/agents-core/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ export type ModelResponse = {
* model. Not supported by all model providers.
*/
responseId?: string;

/**
* Raw response data from the underlying model provider.
*/
providerData?: Record<string, any>;
};

/**
Expand Down
1 change: 1 addition & 0 deletions packages/agents-core/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ export class Runner extends RunHooks<any, AgentOutputType<unknown>> {
agent: state._currentAgent,
agentOutput,
context: state._context,
details: { modelResponse: state._lastTurnResponse },
};
try {
const results = await Promise.all(
Expand Down
3 changes: 3 additions & 0 deletions packages/agents-core/src/runState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const modelResponseSchema = z.object({
usage: usageSchema,
output: z.array(protocol.OutputModelItem),
responseId: z.string().optional(),
providerData: z.record(z.string(), z.any()).optional(),
});

const itemSchema = z.discriminatedUnion('type', [
Expand Down Expand Up @@ -388,6 +389,7 @@ export class RunState<TContext, TAgent extends Agent<any, any>> {
},
output: response.output as any,
responseId: response.responseId,
providerData: response.providerData,
};
}),
context: this._context.toJSON(),
Expand Down Expand Up @@ -635,6 +637,7 @@ export function deserializeModelResponse(
protocol.OutputModelItem.parse(item),
),
responseId: serializedModelResponse.responseId,
providerData: serializedModelResponse.providerData,
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/agents-extensions/src/aiSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ export class AiSdkModel implements Model {
result.usage.promptTokens + result.usage.completionTokens,
}),
output,
providerData: result,
};
} catch (error) {
if (error instanceof Error) {
Expand Down
1 change: 1 addition & 0 deletions packages/agents-openai/src/openaiChatCompletionsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export class OpenAIChatCompletionsModel implements Model {
: new Usage(),
output,
responseId: response.id,
providerData: response,
};

return modelResponse;
Expand Down
1 change: 1 addition & 0 deletions packages/agents-openai/src/openaiResponsesModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ export class OpenAIResponsesModel implements Model {
}),
output: convertToOutputItem(response.output),
responseId: response.id,
providerData: response,
};

return output;
Expand Down