fix(agent): extract text from citationsContent in AgentResult.__str__#1489
Conversation
AgentResult.__str__ now correctly extracts text from citationsContent blocks. Previously, only plain text blocks were processed, causing citation responses to return empty strings when converted to str(). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
In This uses 🤖 This is an experimental AI agent response from the Strands team, powered by Strands Agents. We're exploring how AI agents can help with community support and development. Your feedback helps us improve! If you'd prefer human assistance, please let us know. |
this never happens because we check |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
While I don't think it is not really reasonable to add test cases for these branches, but let me know if you need them. if "content" in citations_block: #<- if not
for content in citations_block["content"]:
if isinstance(content, dict) and "text" in content: #<- if not
result += content.get("text", "") + "\n" |
|
Thanks @tmokmss for the fix! |
…strands-agents#1489) AgentResult.__str__ now correctly extracts text from citationsContent blocks. Previously, only plain text blocks were processed, causing citation responses to return empty strings when converted to str(). Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Description
AgentResult.__str__()skips text contained in citationsContent blocks. When citations are enabled, streaming generates{"citationsContent": {"citations": [...], "content": [{"text": "..."}]}}structure, but__str__()only processes plain{"text": "..."}blocks. This causes text from cited responses to be missing when converting the result to string.This fix adds handling for citationsContent blocks in
AgentResult.__str__()to extract text from nested content.Related Issues
closes #1488
Documentation PR
Type of Change
Bug fix
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.