feat: Add conversation config
This commit is contained in:
@@ -67,7 +67,7 @@ class Agent:
|
|||||||
"""Expone el grafo para inspección en tests."""
|
"""Expone el grafo para inspección en tests."""
|
||||||
return self._build_agent()
|
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.
|
Ejecuta el agente con el estado inicial.
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ class Agent:
|
|||||||
if "messages" not in state:
|
if "messages" not in state:
|
||||||
raise ValueError("State must contain 'messages' key")
|
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):
|
def stream(self, state: dict):
|
||||||
"""Streaming de la ejecución para debugging."""
|
"""Streaming de la ejecución para debugging."""
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ async def webhook_chat(request: Request, agent = Depends(get_agent)):
|
|||||||
try:
|
try:
|
||||||
data = body.get("data", {})
|
data = body.get("data", {})
|
||||||
key = data.get("key", {})
|
key = data.get("key", {})
|
||||||
remote_jid = data.get("key", {}).get("remoteJid")
|
|
||||||
instance_name = body.get("instance")
|
instance_name = body.get("instance")
|
||||||
server_url = body.get("server_url")
|
server_url = body.get("server_url")
|
||||||
api_key = body.get("apikey")
|
api_key = body.get("apikey")
|
||||||
@@ -75,10 +74,7 @@ async def webhook_chat(request: Request, agent = Depends(get_agent)):
|
|||||||
|
|
||||||
messages = [HumanMessage(content=user_message)]
|
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}, config=config)
|
|
||||||
|
|
||||||
agent_response = agent.invoke({"messages": messages})
|
|
||||||
agent_response_content = agent_response["messages"][-1].content
|
agent_response_content = agent_response["messages"][-1].content
|
||||||
|
|
||||||
clean_jid = thread_id.split('@')[0]
|
clean_jid = thread_id.split('@')[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user