Repository navigation
fix(flows): inject artifact text, not the Part repr, into instructions - #7391
Closed
AtulJoshi1206 wants to merge 1 commit into
Closed
AtulJoshi1206 wants to merge 1 commit into
AtulJoshi1206 wants to merge 1 commit into
Conversation
{artifact.name} placeholders and the Jinja artifact() helper returned
str(artifact). Artifact services return a types.Part, whose str() is its
pydantic field dump, so the model received "media_resolution=None ...
text='...'" instead of the artifact content. Text parts now render as
their text, and text/* inline data is decoded as UTF-8. Other parts keep
the previous str() rendering.
copybara-service Bot
pushed a commit
that referenced
this pull request
Oct 5, 2026
Merge #7391 `{artifact.<name>}` and Jinja2 `artifact("<name>")` in instructions now convert `types.Part` artifacts via `load_artifacts_tool.as_safe_part_for_llm` instead of rendering `str(Part)`. PiperOrigin-RevId: 993763912
Collaborator
|
Thank you @AtulJoshi1206 for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit cd5814e. Closing this PR as the changes are now in the main branch. |
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
No existing issue; described below following the bug-report structure.
Describe the Bug:
{artifact.<name>}placeholders in instructions, and the Jinjaartifact()helper, renderstr(artifact)(_instructions_utils.py, regex and Jinja paths). Every artifact service returns atypes.Part, andstr(Part)is its pydantic field dump. The existing tests use a mockload_artifactthat returns a plainstr, so they don't catch this.Impact:
Every agent whose instruction references an artifact sends the model the
Partrepr instead of the content.Observed Behavior:
With
InMemoryArtifactServiceandtypes.Part(text="Buy milk."), the instructionNotes: {artifact.notes.txt}renders as:Expected Behavior:
Notes: Buy milk.Solution:
Add
_artifact_to_textand use it on both paths:Partwithtextrenders as that text;text/*inline_datais decoded as UTF-8;str()rendering. Sending non-text artifacts as real parts is a separate feature (Images that are included into instructions via {artifact.<name>} syntax should allow a underlying LLM for image processing/interpeting. #4674).Testing Plan
Unit Tests:
Added
test_inject_session_state_artifact_part_renders_as_text. It uses the realInMemoryArtifactServiceand is parametrized over the regex and Jinja paths and over text andtext/plaininline-data parts. All 4 cases fail onmain.Checklist
🤖 Generated with Claude Code