fix: add ToolErrorMiddleware (backport #76)#81
Conversation
(cherry picked from commit 0711bbd)
Confidence Score: 4/5The agent import and pre-middleware validation paths need fixes before merging.
ask_alyf/ask_alyf/agent.py and ask_alyf/ask_alyf/api.py 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 |
There was a problem hiding this comment.
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.
| 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.") |
There was a problem hiding this comment.
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.
| 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!
This is an automatic backport of pull request #76 done by [Mergify](https://mergify.com).