Skip to content

Conversation

@gabor-openai
Copy link
Collaborator

Via bug report:

One minor thing, it seems like your Guardrail Agent isn't a 1:1 drop in for the Agents SDK, using a remote prompt gives me an error.

TypeError: GuardrailAgent.__new__() missing 1 required positional argument: 'instructions'

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 adds support for a prompt parameter to GuardrailAgent to make it a 1:1 drop-in replacement for the Agents SDK. Previously, GuardrailAgent required an instructions parameter, but the Agents SDK allows using a prompt parameter instead.

  • Added _resolve_agent_instructions helper function to derive instructions from either explicit instructions or prompt parameters
  • Modified GuardrailAgent.__new__ to accept optional instructions and handle prompt parameter via agent_kwargs
  • Added validation to ensure either instructions or prompt is provided during initialization

Reviewed Changes

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

File Description
src/guardrails/agents.py Added prompt parameter support and instruction resolution logic to GuardrailAgent
tests/unit/test_agents.py Added test cases for prompt parameter functionality and updated Agent stub

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

prompt_arg: Any | None = agent_kwargs.get("prompt")
resolved_instructions = _resolve_agent_instructions(instructions, prompt_arg)

if resolved_instructions is None and prompt_arg is None:
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The validation logic is incorrect. The condition should check if resolved_instructions is None, not both resolved_instructions is None and prompt_arg is None. If a prompt is provided but doesn't yield valid instructions (e.g., an object without the expected attributes), the agent should still fail to initialize.

Suggested change
if resolved_instructions is None and prompt_arg is None:
if resolved_instructions is None:

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +17
guardrails_pkg = types.ModuleType("guardrails")
guardrails_pkg.__path__ = [str(Path(__file__).resolve().parents[2] / "src" / "guardrails")]
sys.modules.setdefault("guardrails", guardrails_pkg)
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

This module setup code should be moved to a test fixture or conftest.py rather than being placed at module level. Module-level sys.modules manipulation can cause issues with test isolation and make debugging more difficult.

Copilot uses AI. Check for mistakes.
@gabor-openai gabor-openai requested a review from Copilot October 29, 2025 20:08
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

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


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

Copy link
Collaborator

@steven10a steven10a left a comment

Choose a reason for hiding this comment

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

Suggest closing in favor of PR 34

@gabor-openai
Copy link
Collaborator Author

gabor-openai commented Oct 30, 2025

Closing in favor of #34

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