From e56581d112d484b531793e77466ac03c625ab017 Mon Sep 17 00:00:00 2001 From: aserrador Date: Thu, 26 Feb 2026 20:47:28 -0500 Subject: [PATCH] feat: Add conversation config --- src/naliiabot/bot/agent/agent.py | 4 ++-- src/naliiabotapi/api/v1/webhooks/chat_hook.py | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/naliiabot/bot/agent/agent.py b/src/naliiabot/bot/agent/agent.py index 69bd77b..2b997a5 100644 --- a/src/naliiabot/bot/agent/agent.py +++ b/src/naliiabot/bot/agent/agent.py @@ -67,7 +67,7 @@ class Agent: """Expone el grafo para inspección en tests.""" return self._build_agent() - def invoke(self, state: dict) -> dict: + def invoke(self, state: dict, config: dict | None = None) -> dict: """ Ejecuta el agente con el estado inicial. @@ -81,7 +81,7 @@ class Agent: if "messages" not in state: raise ValueError("State must contain 'messages' key") - return self._compiled_agent.invoke(state) + return self._compiled_agent.invoke(state, config=config) def stream(self, state: dict): """Streaming de la ejecución para debugging.""" diff --git a/src/naliiabotapi/api/v1/webhooks/chat_hook.py b/src/naliiabotapi/api/v1/webhooks/chat_hook.py index 90905ef..ae30e53 100644 --- a/src/naliiabotapi/api/v1/webhooks/chat_hook.py +++ b/src/naliiabotapi/api/v1/webhooks/chat_hook.py @@ -52,7 +52,6 @@ async def webhook_chat(request: Request, agent = Depends(get_agent)): try: data = body.get("data", {}) key = data.get("key", {}) - remote_jid = data.get("key", {}).get("remoteJid") instance_name = body.get("instance") server_url = body.get("server_url") api_key = body.get("apikey") @@ -75,10 +74,7 @@ async def webhook_chat(request: Request, agent = Depends(get_agent)): messages = [HumanMessage(content=user_message)] - # Se pasa el config como un argumento separado, no dentro del estado - # agent_response = agent.invoke({"messages": messages}, config=config) - - agent_response = agent.invoke({"messages": messages}) + agent_response = agent.invoke({"messages": messages}, config=config) agent_response_content = agent_response["messages"][-1].content clean_jid = thread_id.split('@')[0]