Support behavioral context in Risk Agent and enhance guardrail decorators #300
+135
−31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for
source_contextwithin the guardrail system to provide the Risk Agent with behavioral information about the specific agent or tool being evaluated. It also introduces a debug mode for the Risk Agent to log the exact messages being sent to the LLM during criteria generation.Details
source_contextto theGuardrailInputschema to allow passing specific constraints or behavioral expectations of the content source._get_source_contextin the decorators module. This helper extracts context from classes or instances with a priority order: explicit overrides, thedescriptionattribute (if it is a string), and finally the docstring.guardraildecorator andapply_guardrailsfunction to accept and process thesource_context.RiskAgentto inject "Source (Agent) Behaviour" into the system prompt whensource_contextis provided. This ensures the LLM has enough context to generate more accurate risk criteria.RiskAgentthat prints the full list of messages sent to the LLM. This is useful for verifying prompt injection and behavioral context during development.Checks