Skip to content

fix: add ToolErrorMiddleware (backport #76)#81

Open
mergify[bot] wants to merge 1 commit into
developfrom
mergify/bp/develop/pr-76
Open

fix: add ToolErrorMiddleware (backport #76)#81
mergify[bot] wants to merge 1 commit into
developfrom
mergify/bp/develop/pr-76

Conversation

@mergify

@mergify mergify Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

This is an automatic backport of pull request #76 done by [Mergify](https://mergify.com).

(cherry picked from commit 0711bbd)
@mergify mergify Bot mentioned this pull request Jul 20, 2026
@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

The agent import and pre-middleware validation paths need fixes before merging.

  • The new type import can prevent the agent module from loading on a permitted dependency resolution.
  • Initialization validation errors now lose the configuration guidance users need.
  • Unexpected exception details are correctly hidden from user-facing responses.

ask_alyf/ask_alyf/agent.py and ask_alyf/ask_alyf/api.py

Fix All in Cursor

Reviews (1): Last reviewed commit: "fix: add ToolErrorMiddleware (#76)" | Re-trigger Greptile

from frappe import _
from langchain.agents import create_agent
from langchain.agents.middleware import ToolErrorMiddleware
from langchain.agents.middleware.types import ToolCallRequest

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.

P1 Internal Type Import Can Fail

This imports ToolCallRequest from an internal middleware module rather than its public LangChain location. If the permitted LangChain 1.3.x installation does not re-export that type here, importing the agent module raises ImportError and disables every agent entry point; the new tests use SimpleNamespace, so they do not cover this production import.

Fix in Cursor

Comment thread ask_alyf/ask_alyf/api.py
frappe.log_error("Ask ALYF Agent Error")
frappe.clear_messages()
response = str(error).strip() or _("I hit an error while processing that request. Please try again.")
response = _("I hit an error while processing that request. Please try again.")

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.

P1 Configuration Guidance Is Suppressed

Missing API-key or model settings raise actionable ValidationError messages while ask_alyfAgentRunner is being constructed, before tool middleware can handle them. This branch now replaces those messages with a generic response, so a misconfigured installation no longer tells the user what must be configured.

Suggested change
response = _("I hit an error while processing that request. Please try again.")
response = (
str(error).strip()
if isinstance(error, frappe.ValidationError | frappe.PermissionError)
else _("I hit an error while processing that request. Please try again.")
)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Cursor

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.

1 participant