Skip to content

fix(flows): inject artifact text, not the Part repr, into instructions - #7391

Closed
AtulJoshi1206 wants to merge 1 commit into
google:mainfrom
AtulJoshi1206:fix/instruction-artifact-text
Closed

AtulJoshi1206 wants to merge 1 commit into
google:mainfrom
AtulJoshi1206:fix/instruction-artifact-text

Conversation

@AtulJoshi1206

Copy link
Copy Markdown
Contributor

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 Jinja artifact() helper, render str(artifact) (_instructions_utils.py, regex and Jinja paths). Every artifact service returns a types.Part, and str(Part) is its pydantic field dump. The existing tests use a mock load_artifact that returns a plain str, so they don't catch this.

Impact:

Every agent whose instruction references an artifact sends the model the Part repr instead of the content.

Observed Behavior:

With InMemoryArtifactService and types.Part(text="Buy milk."), the instruction Notes: {artifact.notes.txt} renders as:

Notes: media_resolution=None code_execution_result=None executable_code=None file_data=None function_call=None function_response=None inline_data=None text='Buy milk.' thought=None ...

Expected Behavior: Notes: Buy milk.

Solution:

Add _artifact_to_text and use it on both paths:

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added test_inject_session_state_artifact_part_renders_as_text. It uses the real InMemoryArtifactService and is parametrized over the regex and Jinja paths and over text and text/plain inline-data parts. All 4 cases fail on main.

pytest tests/unittests/flows/llm_flows tests/unittests/utils   # 1505 passed

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules. (none)

🤖 Generated with Claude Code

{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
@adk-bot

adk-bot commented Oct 5, 2026

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged [Status] This PR is merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants