Skip to content

feat(advanced): return tool execution errors to the model - #1138

Open
radu-mocanu wants to merge 1 commit into
mainfrom
feat/advanced-tool-errors
Open

radu-mocanu wants to merge 1 commit into
mainfrom
feat/advanced-tool-errors

Conversation

@radu-mocanu

Copy link
Copy Markdown
Collaborator

Summary

  • a tool that raises during an advanced agent run (autonomous or conversational, main agent or subagent) now returns an error ToolMessage to the model instead of faulting the job, so the model can recover
  • AgentStartupError and AgentRuntimeError termination codes (AGENT_RUNTIME.TERMINATION_*, e.g. a rejected escalation) still end the run
  • built on langchain's ToolErrorMiddleware, no retries are added

Why

a single transient tool failure faulted the whole advanced agent run, while the model could have retried or worked around it.

Copilot AI balanced review requested due to automatic review settings October 7, 2026 15:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Regression coverage must distinguish subagent recovery from parent recovery and verify interrupt/resume behavior with the new middleware.

2 open findings
What changed in this PR

Advanced agents now return recoverable tool errors to the model rather than faulting the run.

Changes:

  • Adds shared error middleware for main agents and subagents while preserving startup and termination failures.
  • Adds regression tests and updates middleware expectations.
  • Bumps the package version to 0.18.31.
File Description
uv.lock Updates the locked package version.
tests/​agent/​advanced/​test_tool_errors.py Tests tool-error recovery and fatal-error propagation.
tests/​agent/​advanced/​test_payload_handler_middleware.py Updates expected middleware composition.
src/​uipath_langchain/​agent/​advanced/​agent.py Adds shared tool-error handling.
pyproject.toml Bumps the package version.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/uipath_langchain/agent/advanced/agent.py
Comment thread tests/agent/advanced/test_tool_errors.py Outdated
@radu-mocanu
radu-mocanu force-pushed the feat/advanced-tool-errors branch from bc8bcdc to f0d669f Compare October 7, 2026 15:43
@sonarqubecloud

sonarqubecloud Bot commented Oct 7, 2026

Copy link
Copy Markdown

Comment on lines +226 to +231
if isinstance(exc, AgentStartupError):
return None
if isinstance(exc, AgentRuntimeError) and exc.error_info.code.startswith(
"AGENT_RUNTIME.TERMINATION_"
):
return None

@andreiancuta-uipath andreiancuta-uipath Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this would be done nicer using a marker type for termination errors. But it would require extracting the termination error codes out of AgentRuntimeError into a separate AgentTerminatingError type.

# exceptions.py
class RunTerminatingError(Exception):
    """Ends the agent run immediately."""

class AgentStartupError(UiPathBaseRuntimeError, RunTerminatingError): ...

class AgentTerminatingError(AgentRuntimeError, RunTerminatingError): ...
def _tool_error_content(exc: Exception, request: ToolCallRequest) -> str | None:
    return None if isinstance(exc, RunTerminatingError) else str(exc)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants