fix(core): Fix AgentCancel propagation for LangChain and smolagents #897
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
_unwrap_agent_cancel()helper to traverse exception chains and find wrappedAgentCancelinstances. This fixes smolagents (which usesraise ... from e) and acts as a defensive catch-all for any future frameworks that follow the same pattern.raise_error=Trueon LangChain callback handler to propagate exceptions instead of swallowing them. LangChain defaults to logging warnings and continuing execution, which silently broke the circuit-breaker pattern for callback exceptions.Fixes integration test failures on main for
test_agent_cancel_not_wrapped[LANGCHAIN]andtest_agent_cancel_not_wrapped[SMOLAGENTS].Tests can be checked using:
uv run pytest tests/integration/frameworks/test_error_handling.py::test_agent_cancel_not_wrapped -k "LANGCHAIN or SMOLAGENTS" -v