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:
2026-03-11 00:29:03 -05:00
parent e92cb969e9
commit 8d20656a37
2 changed files with 16 additions and 8 deletions

View File

@@ -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(