LCORE-3228: Wire Shields into build_agent#2215
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
asimurka
left a comment
There was a problem hiding this comment.
LGTM, just some nits ;)
bb79a94 to
d0203b1
Compare
|
So I am debating either leaving this PR as is with passing a |
Description
Wires the previously-added
shieldsconfiguration intobuild_agentso configured guardrail shields (question validity and PII redaction) are attached as pydantic-ai capabilities on every agent run._shield_capability()translates eachShieldConfigurationentry into its concrete capability instance —QuestionValiditywhen the config is aQuestionValidityConfig,PiiRedactionCapabilitywhen it's aRedactionConfig— raisingValueErrorfor any unrecognized config type._agent_capabilities()andbuild_agent()now accept an optionalshieldslist and prepend the resulting shield capabilities ahead of the skills capability.configuration.shieldsis threaded into all three call sites that build an agent: the non-streaming query flow (utils/agents/query.py), the streaming query flow (utils/agents/streaming.py), and the A2A executor (app/endpoints/a2a.py).Also changed
QuestionValidity's capability base fromAbstractCapability[None]toAbstractCapability[Any]to match theAny-typed pattern already used byPiiRedactionCapabilityandSkillsCapability— this avoids a pyright contravariance conflict when mixing both shield types into the same capability list, without needing to loosen_agent_capabilities's own type annotations.Type of change
Tools used to create PR
Related Tickets & Documents
Checklist before requesting a review
Testing
tests/unit/utils/test_pydantic_ai.pywith coverage for_shield_capability(both shield types plus an unsupported-config-type error case),_agent_capabilities(shields alone, and shields combined with skills), andbuild_agent(agent includes/excludes shield capabilities based on configuration).black,ruff,pylint,pyright, andpydocstyleagainst all touched files — all clean.tests/unit/utils/test_pydantic_ai.pysuite (20 tests) — all passing.tests/unit/utils/agents/test_query.py,test_streaming.py, andtests/unit/app/endpoints/test_a2a.pycurrently fail to collect due to a pre-existing, unrelated environment issue (ImportError: cannot import name 'Shield' from 'ogx_client.types'), confirmed present before these changes too.