Fix ChainAgent raising raw string instead of Exception object#450
Open
gavksingh wants to merge 2 commits intoawslabs:mainfrom
Open
Fix ChainAgent raising raw string instead of Exception object#450gavksingh wants to merge 2 commits intoawslabs:mainfrom
gavksingh wants to merge 2 commits intoawslabs:mainfrom
Conversation
The process_request() method was raising a raw f-string on error, which raises a TypeError instead of the intended exception message. Wrap the f-string in Exception() so it properly raises with the correct error message and traceback chain. Fixes awslabs#248
Tests verify that ChainAgent properly raises Exception (not TypeError) when an agent in the chain fails, along with chaining behavior, streaming, default responses, and error propagation.
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
ChainAgent.process_request()where a raw f-string was raised instead of anExceptionobject on errorTypeError: exceptions must derive from BaseExceptioninstead of the intended error message being propagatedChainAgentDetails
In
python/src/agent_squad/agents/chain_agent.pyline 65, the error handling code was:This raises a
TypeErrorbecause strings are not valid exception types in Python. The fix wraps the f-string inException():Tests added
New file:
python/src/tests/agents/test_chain_agent.py(9 tests)test_chain_agent_requires_at_least_one_agent— validates empty agents list raises ValueErrortest_chain_agent_single_agent_success— single agent returns expected ConversationMessagetest_chain_agent_multi_agent_chaining— output of agent N feeds into agent N+1test_chain_agent_raises_exception_not_type_error— the bug fix test: verifies Exception is raised, not TypeErrortest_chain_agent_error_propagation— error in 2nd agent references 2nd agent's nametest_chain_agent_default_response_on_empty_content— empty content triggers default responsetest_chain_agent_streaming_last_agent— last agent async iterable passes throughtest_chain_agent_streaming_intermediate_blocked— intermediate streaming returns default responsetest_chain_agent_custom_default_output— custom default_output text propagatesTest plan
Exceptionobjectpytest -v)Exceptionis raised, notTypeErrorFixes #248