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(
|
||||
|
||||
@@ -160,7 +160,7 @@ class NaliiaTools:
|
||||
service_center=11,
|
||||
customer=None,
|
||||
professional=6,
|
||||
state=None,
|
||||
customer_id=None,
|
||||
) -> bool:
|
||||
"""
|
||||
Permite agendar una cita para un cliente en un centro de servicio específico.
|
||||
@@ -170,8 +170,9 @@ class NaliiaTools:
|
||||
schedule_time: Hora de la cita en formato HH:MM:SS.
|
||||
description (str): Descripción o motivo de la cita.
|
||||
service_center (int, optional): ID del centro de servicio. Por defecto es 11.
|
||||
customer (int, optional): ID del cliente. Si no se proporciona, se obtiene del estado.
|
||||
customer (int, optional): ID del cliente. Si no se proporciona, se usa customer_id.
|
||||
professional (int, optional): ID del profesional. Por defecto es 6.
|
||||
customer_id (int, optional): ID del cliente obtenido del estado.
|
||||
|
||||
Returns:
|
||||
bool: True si la cita fue agendada exitosamente, False en caso contrario.
|
||||
@@ -186,9 +187,9 @@ class NaliiaTools:
|
||||
if not schedule_date and schedule_time:
|
||||
return False
|
||||
|
||||
if customer is None and state is not None:
|
||||
customer = state.get("customer_id", 0)
|
||||
logger.info(f"Customer ID obtained from state: {customer}")
|
||||
if customer is None and customer_id is not None:
|
||||
customer = customer_id
|
||||
logger.info(f"Customer ID obtained from agent state: {customer}")
|
||||
|
||||
if customer is None or customer == 0:
|
||||
logger.warning("No se pudo obtener el ID del cliente")
|
||||
|
||||
Reference in New Issue
Block a user