feat(multiagent): Add __str__ support for MultiAgentResult and NodeResult#1998
Open
dosvk wants to merge 2 commits intostrands-agents:mainfrom
Open
feat(multiagent): Add __str__ support for MultiAgentResult and NodeResult#1998dosvk wants to merge 2 commits intostrands-agents:mainfrom
dosvk wants to merge 2 commits intostrands-agents:mainfrom
Conversation
…sult Add human-readable string representations to MultiAgentResult and NodeResult, consistent with the existing AgentResult.__str__ behavior. NodeResult.__str__ delegates to its inner result (AgentResult, MultiAgentResult, or Exception). MultiAgentResult.__str__ prioritizes interrupts, then outputs each node's text prefixed with its name. This makes print(result) produce clean output instead of the default dataclass repr. Closes strands-agents#1561
Contributor
|
/strands review |
|
Assessment: Approve Clean implementation that follows the established Review Details
Suggestion for improved test coverage: Consider adding tests for:
Example tests: def test_multi_agent_result_str_multiple_nodes():
"""Test MultiAgentResult.__str__ with multiple nodes."""
ar1 = AgentResult(
message={"role": "assistant", "content": [{"text": "Response 1"}]},
stop_reason="end_turn", state={}, metrics={},
)
ar2 = AgentResult(
message={"role": "assistant", "content": [{"text": "Response 2"}]},
stop_reason="end_turn", state={}, metrics={},
)
result = MultiAgentResult(
status=Status.COMPLETED,
results={"node1": NodeResult(result=ar1), "node2": NodeResult(result=ar2)},
)
output = str(result)
assert "node1: Response 1" in output
assert "node2: Response 2" in output
assert "\n" in output
def test_node_result_str_with_nested_multiagent():
"""Test NodeResult.__str__ with nested MultiAgentResult."""
inner_ar = AgentResult(
message={"role": "assistant", "content": [{"text": "Nested response"}]},
stop_reason="end_turn", state={}, metrics={},
)
inner_mar = MultiAgentResult(
status=Status.COMPLETED,
results={"inner_node": NodeResult(result=inner_ar)},
)
outer_node = NodeResult(result=inner_mar)
assert "inner_node: Nested response" in str(outer_node) |
…esult Add two additional tests addressing review feedback: - Multiple nodes: verifies for loop and newline joining - Nested MultiAgentResult: verifies recursive delegation in NodeResult
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.
Add
__str__methods toMultiAgentResultandNodeResultfor human-readablestring output, consistent with the existing
AgentResult.__str__behavior.NodeResult.__str__delegates to its inner result —AgentResult, nestedMultiAgentResult, orException.MultiAgentResult.__str__follows the same priority order asAgentResult.__str__:This addresses the review feedback from #1568 regarding matching the priority
order from
AgentResult.__str__.Related Issues
Closes #1561
Type of Change
New feature
Testing
Exception delegation, node iteration, interrupt priority, and empty results
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.