fix: return literal text for unresolved session state variables instead of KeyError#5711
Open
zhoufengen wants to merge 1 commit into
Open
fix: return literal text for unresolved session state variables instead of KeyError#5711zhoufengen wants to merge 1 commit into
zhoufengen wants to merge 1 commit 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
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