Skip to content

Conversation

@steven10a
Copy link
Collaborator

Fixes reported bug from rcatoen:

TypeError: GuardrailAgent.__new__() missing 1 required positional argument: 'instructions' when using prompt instead of instructions

Fix:

  • Typing for instruction was too strict required it to be a string
  • Functionality was already supported as we are simply a wrapper around Agent SDK

Also added support for users adding their own input and output guardrails via the Agent SDK.

  • These were silently suppressed and only guardrails via the config were run
  • We now merge the lists and run all of them

Added tests

Some Prettier format changes

@steven10a steven10a requested review from Copilot and gabor-openai and removed request for Copilot October 30, 2025 15:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the GuardrailAgent.create() method to support optional instructions (including callable instructions) and allows merging user-provided guardrails with config-based guardrails.

Key changes:

  • Made the instructions parameter optional and added support for callable/dynamic instructions
  • Added support for merging user-provided input/output guardrails from agentKwargs with config-based guardrails
  • Added comprehensive test coverage for the new functionality including edge cases

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/agents.ts Updated GuardrailAgent.create() to make instructions optional, support callable instructions, and merge user-provided guardrails with config guardrails by extracting them from agentKwargs
src/tests/unit/agents.test.ts Added extensive test coverage for optional instructions, callable instructions, guardrail merging, and updated MockAgent interface to reflect new signature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

// Merge with user-provided input guardrails (config ones run first, then user ones)
if (userInputGuardrails && Array.isArray(userInputGuardrails)) {
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The Array.isArray() check is redundant since TypeScript already types userInputGuardrails as InputGuardrail[] | undefined. If the value is not an array at runtime, this indicates a type mismatch that should be caught elsewhere. Consider simplifying to just if (userInputGuardrails) for consistency with line 421.

Suggested change
if (userInputGuardrails && Array.isArray(userInputGuardrails)) {
if (userInputGuardrails) {

Copilot uses AI. Check for mistakes.
Comment on lines +421 to +423
if (userOutputGuardrails && Array.isArray(userOutputGuardrails)) {
outputGuardrails.push(...userOutputGuardrails);
}
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The Array.isArray() check is redundant since TypeScript already types userOutputGuardrails as OutputGuardrail[] | undefined. If the value is not an array at runtime, this indicates a type mismatch that should be caught elsewhere. Consider simplifying to just if (userOutputGuardrails) for consistency.

Copilot uses AI. Check for mistakes.
@gabor-openai gabor-openai changed the title support prompt use Support using prompt param with GuardrailAgent Oct 30, 2025
@gabor-openai gabor-openai merged commit c8cae92 into main Oct 30, 2025
13 checks passed
@steven10a steven10a deleted the dev/steven/agents_bug branch October 30, 2025 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants