Repository navigation
fix: return literal text for unresolved session state variables instead of KeyError - #5711
zhoufengen wants to merge 2 commits into
Conversation
…ad of KeyError
inject_session_state raises KeyError when instruction text contains
literal {identifier} patterns (e.g., documentation describing
interpolation syntax like ${expression}). This crashes agents that
embed third-party tool descriptions, JSON schemas, or documentation
examples into instruction strings.
Fix by returning match.group() as-is when a valid identifier is not
found in session state, with a debug log. This matches the existing
behavior for invalid identifier names.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Hi @zhoufengen , Thank you for your contribution! It appears you haven't yet signed the Contributor License Agreement (CLA). Please visit https://cla.developers.google.com/ to complete the signing process. Once the CLA is signed, we'll be able to proceed with the review of your PR. Thank you! |
4099293 to
13cba14
Compare
|
Hi @zhoufengen , pls fix the mypy-diff tests. |
|
the crash is fixed on main in 0caecd2, by a narrower change: the pattern carries a negative lookbehind now, so ${expression} and escaped braces aren't treated as variables. i ran the a2ui case and it passes through as literal text. head keeps the KeyError for a bare {missing_var} on purpose, with a test asserting it. not in 2.9.1. open a new issue if you want us to look at it again. |
Summary
inject_session_state()raisesKeyErrorwhen instruction text containsliteral
{identifier}patterns — such as documentation describing interpolationsyntax like
${expression}. This crashes any agent that embeds third-partytool descriptions, JSON schemas, or documentation examples into its instruction
string.
This has already caused a downstream bug in the
A2UI project.
Changes
instructions_utils.py: Changed the missing-state branch from raisingKeyErrorto returning the literal match text with a debug log. Unresolvedidentifiers now pass through unchanged, matching the existing behavior for
invalid identifier names.
test_instructions_utils.py: Updated the existing KeyError test toexpect literal text preservation. Added a new regression test for
{expression}patterns in documentation text.Testing
Test suite passing on the fix branch:
Related Issues
Fixes #5706