feat: add AgentResult.text, AgentResult.__repr__, and Agent.clear()#1942
Open
Exploreunive wants to merge 1 commit intostrands-agents:mainfrom
Open
feat: add AgentResult.text, AgentResult.__repr__, and Agent.clear()#1942Exploreunive wants to merge 1 commit intostrands-agents:mainfrom
Exploreunive wants to merge 1 commit intostrands-agents:mainfrom
Conversation
…clear() - AgentResult.text: convenience property for extracting text content, equivalent to str(result) but more discoverable and Pythonic - AgentResult.__repr__: debug-friendly representation showing stop_reason and a truncated text preview - Agent.clear(): reset conversation history and event loop metrics in one call, useful for multi-turn testing and conversation restart scenarios
Exploreunive
pushed a commit
to Exploreunive/sdk-python
that referenced
this pull request
Mar 21, 2026
Addresses review feedback from strands-agents#1943: 1. **Clean split**: Only isError-related changes, no unrelated commits from AgentResult.text (PR strands-agents#1942) or other work. 2. **isError propagation**: MCPToolResult now exposes isError field: - True when MCP server reports CallToolResult.isError (application error) - True when a Python exception occurs during tool execution (protocol error) - False/absent on success Updated docstring clarifies both error sources. 3. **Exception propagation** (maintainer feedback from strands-agents#1670): MCPAgentTool.stream() now passes the original exception via ToolResultEvent(result, exception=e), matching the pattern used by decorated tools. Added _invoke_tool() helper that calls the MCP client internals directly to capture exceptions. Files changed: - mcp_types.py: Added isError: NotRequired[bool], updated docstring - mcp_client.py: Propagated isError in _handle_tool_result and _handle_tool_execution_error - mcp_agent_tool.py: Added _invoke_tool() for exception capture, stream() yields ToolResultEvent(result, exception=...) - Tests: Added isError assertions, exception propagation tests
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
Add three convenience features that improve the developer experience when working with the Strands SDK:
AgentResult.textproperty — A discoverable, Pythonic way to extract text content from agent results. Equivalent tostr(result)but more intuitive.AgentResult.__repr__— Debug-friendly representation showingstop_reasonand a truncated text preview, making agent output much easier to inspect in logs and REPLs.Agent.clear()— A single method to reset conversation history and event loop metrics, useful for multi-turn testing scenarios and conversation restarts.Changes
src/strands/agent/agent_result.py: Addedtextproperty and__repr__methodsrc/strands/agent/agent.py: Addedclear()methodtests/strands/agent/test_agent_result.py: 6 new tests fortextand__repr__tests/strands/agent/test_agent.py: 2 new tests forclear()Testing
All 27 tests pass (25 existing + 2 new for clear(), 6 new for text/repr on agent_result).