enhance: auto-identify customers and add new tools
- Agent now auto-calls find_customer_by_identifier when user provides identifier - Added register_customer and check_mcp_connection tools - Refactored chat_hook to resume existing conversations from state - Reduced default max_iterations (100) and timeout (15s)
This commit is contained in:
@@ -24,12 +24,32 @@ class NaliiaTools:
|
||||
return [
|
||||
self.get_current_datetime,
|
||||
self.get_tomorrow_date,
|
||||
self.register_customer,
|
||||
self.schedule_appointment,
|
||||
self.find_service_centers,
|
||||
self.find_products_and_services,
|
||||
self.find_customer_by_identifier,
|
||||
self.check_mcp_connection,
|
||||
]
|
||||
|
||||
@tool
|
||||
def check_mcp_connection(self) -> str:
|
||||
"""
|
||||
Verifica la conexión con el servidor MCP.
|
||||
|
||||
Returns:
|
||||
str: "connected" si el servidor está disponible, "disconnected" si no hay conexión.
|
||||
"""
|
||||
|
||||
async def call_tool():
|
||||
async with _MCP_CLIENT:
|
||||
result = await _MCP_CLIENT.ping()
|
||||
logger.info(f"MCP connection status: {result}")
|
||||
return True
|
||||
|
||||
is_connected = asyncio.run(call_tool())
|
||||
return "connected" if is_connected else "disconnected"
|
||||
|
||||
@tool
|
||||
def get_tomorrow_date() -> str:
|
||||
"""
|
||||
@@ -43,7 +63,6 @@ class NaliiaTools:
|
||||
- No se aceptan fechas en el pasado con respecto a esta fecha.
|
||||
- Utiliza la zona horaria de Colombia (America/Bogota, UTC-5).
|
||||
"""
|
||||
|
||||
td = timedelta(days=1)
|
||||
tomorrow = datetime.now().date() + td
|
||||
tomorrow_date_formated = tomorrow.isoformat()
|
||||
@@ -73,6 +92,41 @@ class NaliiaTools:
|
||||
|
||||
return today_date_formated
|
||||
|
||||
@tool
|
||||
def register_customer(name: str, cellphone: str, email: str = None) -> bool:
|
||||
"""
|
||||
Registra un nuevo cliente
|
||||
|
||||
Args:
|
||||
name: Nombre Completo del Cliente.
|
||||
cellphone: Numero de Celular o Contacto.
|
||||
|
||||
Returns:
|
||||
list: En caso del cliente fuese creado exitosamente se obtendra una lista con el id del cliente en la base de datos.
|
||||
Ejemplo: [1]
|
||||
"""
|
||||
|
||||
identifiers = {
|
||||
"type": "mobile",
|
||||
"code": cellphone
|
||||
}
|
||||
|
||||
async def call_tool():
|
||||
async with _MCP_CLIENT:
|
||||
result = await _MCP_CLIENT.call_tool(
|
||||
'create_customer', {
|
||||
"name": name,
|
||||
"identifiers": identifiers
|
||||
})
|
||||
|
||||
logger.info(result.content[0].text)
|
||||
|
||||
return result
|
||||
|
||||
result = asyncio.run(call_tool())
|
||||
|
||||
return result.content[0].text
|
||||
|
||||
@tool
|
||||
def find_customer_by_identifier(identifier: str) -> str:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user