fix: pass customer_id directly to tools instead of state
- Avoids JSON serialization errors with HumanMessage objects - schedule_appointment now receives customer_id as direct parameter
This commit is contained in:
@@ -228,7 +228,9 @@ class Agent:
|
||||
tool_results: list[BaseMessage] = []
|
||||
|
||||
for tool_call in last_message.tool_calls:
|
||||
result = self._execute_tool(tool_call, state)
|
||||
result = self._execute_tool(
|
||||
tool_call, state.get("customer_id"), state.get("customer_name")
|
||||
)
|
||||
tool_results.append(result)
|
||||
|
||||
if self._post_tool_hook:
|
||||
@@ -236,7 +238,9 @@ class Agent:
|
||||
|
||||
return {"messages": state["messages"] + tool_results}
|
||||
|
||||
def _execute_tool(self, tool_call: dict, state: MessagesState) -> ToolMessage:
|
||||
def _execute_tool(
|
||||
self, tool_call: dict, customer_id=None, customer_name=None
|
||||
) -> ToolMessage:
|
||||
"""
|
||||
Ejecuta una herramienta individual con manejo de errores.
|
||||
"""
|
||||
@@ -253,7 +257,10 @@ class Agent:
|
||||
|
||||
try:
|
||||
tool = self._tools_by_name[tool_name]
|
||||
tool_args["state"] = state
|
||||
if customer_id is not None:
|
||||
tool_args["customer_id"] = customer_id
|
||||
if customer_name is not None:
|
||||
tool_args["customer_name"] = customer_name
|
||||
observation = tool.invoke(tool_args)
|
||||
|
||||
return ToolMessage(
|
||||
|
||||
Reference in New Issue
Block a user