bugfix: aofertas
This commit is contained in:
@@ -148,6 +148,34 @@ class AgentWorkflow:
|
||||
enxergar evidências MCP. O domínio não implementa rails, apenas devolve dados.
|
||||
"""
|
||||
ctx = dict(state.get("context", {}) or {})
|
||||
|
||||
# Guardrails de saída (especialmente AOFERTA) precisam saber o que o
|
||||
# cliente efetivamente pediu. Sem o histórico, uma confirmação legítima
|
||||
# como "Você confirma cancelar ...?" parece uma oferta proativa isolada.
|
||||
# O estado do Contas mantém history como lista de dicts; preservamos esse
|
||||
# formato e acrescentamos o user_text corrente quando ele ainda não foi
|
||||
# persistido no histórico.
|
||||
history = list(state.get("history") or [])
|
||||
user_text = str(state.get("user_text") or state.get("sanitized_input") or "").strip()
|
||||
if user_text:
|
||||
last_user_text = ""
|
||||
for item in reversed(history):
|
||||
if isinstance(item, dict) and str(item.get("role", "")).lower() in {"user", "human"}:
|
||||
last_user_text = str(item.get("content") or "").strip()
|
||||
break
|
||||
if type(item).__name__ == "HumanMessage":
|
||||
last_user_text = str(getattr(item, "content", "") or "").strip()
|
||||
break
|
||||
if last_user_text != user_text:
|
||||
history.append({"role": "user", "content": user_text})
|
||||
if history:
|
||||
ctx["conversation_history"] = history
|
||||
ctx["history_texts"] = [
|
||||
str(item.get("content") or "") if isinstance(item, dict)
|
||||
else str(getattr(item, "content", "") or "")
|
||||
for item in history
|
||||
]
|
||||
|
||||
mcp_results = state.get("mcp_results") or []
|
||||
ctx["evidence"] = mcp_results or ctx.get("evidence")
|
||||
ctx["tool_result"] = mcp_results or ctx.get("tool_result")
|
||||
|
||||
Reference in New Issue
Block a user