Ajustes no agente de contas

This commit is contained in:
2026-08-31 14:13:51 -03:00
parent 00ac7f0c83
commit 87a0b77dae
137 changed files with 715 additions and 8 deletions

View File

@@ -7,6 +7,7 @@ from agent_framework.guardrails.rail_action import RailAction
from agent_framework.guardrails.rail_result import RailResult
from agent_framework.judges.judge import JudgePipeline
from agent_framework.routing.enterprise_router import EnterpriseRouter
from app.domain.contas.conversation_policy import evaluate as evaluate_contas_conversation_policy
from agent_framework.supervisor.supervisor import Supervisor
from agent_framework.observability.workflow_events import WorkflowTelemetry
from agent_framework.observability.guardrail_events import GuardrailTelemetry
@@ -292,6 +293,8 @@ class AgentWorkflow:
builder.add_node("input_guardrails", self._node("input_guardrails", self.input_guardrails))
builder.add_node("load_long_term_memory", self._node("load_long_term_memory", self.load_long_term_memory))
builder.add_node("routing_decision", self._node("routing_decision", self.routing_decision))
builder.add_node("conversation_policy", self._node("conversation_policy", self.conversation_policy))
builder.add_node("conversation_policy_response", self._node("conversation_policy_response", self.conversation_policy_response))
builder.add_node("faturas_agent", self._node("faturas_agent", self.faturas_agent))
builder.add_node("vas_agent", self._node("vas_agent", self.vas_agent))
builder.add_node("contestacao_agent", self._node("contestacao_agent", self.contestacao_agent))
@@ -316,8 +319,9 @@ class AgentWorkflow:
{"blocked": "output_guardrails", "continue": "load_long_term_memory"},
)
builder.add_edge("load_long_term_memory", "routing_decision")
builder.add_edge("routing_decision", "conversation_policy")
builder.add_conditional_edges(
"routing_decision",
"conversation_policy",
lambda s: s.get("route", "faturas_agent"),
{
"faturas_agent": "faturas_agent",
@@ -328,6 +332,7 @@ class AgentWorkflow:
"human_handoff": "human_handoff",
"end_session": "end_session",
"supervisor_agent": "supervisor_agent",
"conversation_policy_response": "conversation_policy_response",
},
)
builder.add_edge("faturas_agent", "output_supervisor")
@@ -338,6 +343,7 @@ class AgentWorkflow:
builder.add_edge("human_handoff", "output_supervisor")
builder.add_edge("end_session", "output_supervisor")
builder.add_edge("supervisor_agent", "output_supervisor")
builder.add_edge("conversation_policy_response", "output_supervisor")
builder.add_edge("output_supervisor", "output_guardrails")
builder.add_conditional_edges(
"output_guardrails",
@@ -676,6 +682,26 @@ class AgentWorkflow:
} if decision.method == "continuity" else {},
}
async def conversation_policy(self, state):
decision = evaluate_contas_conversation_policy(state)
if decision is None:
return {}
patch = dict(decision.patch or {})
route_metadata_patch = patch.pop("_route_metadata", {}) if isinstance(patch.get("_route_metadata", {}), dict) else {}
if decision.route:
patch["route"] = decision.route
if decision.intent:
patch["intent"] = decision.intent
if decision.answer is not None:
patch["answer"] = decision.answer
if decision.reason:
current = state.get("route_decision") if isinstance(state.get("route_decision"), dict) else {}
patch["route_decision"] = {**current, "route": patch.get("route", state.get("route")), "intent": patch.get("intent", state.get("intent")), "reason": decision.reason, "metadata": {**(current.get("metadata") or {}), **route_metadata_patch, "contas_conversation_policy": decision.reason}}
return patch
async def conversation_policy_response(self, state):
return {"answer": str(state.get("answer") or ""), "next_state": state.get("next_state") or "CONVERSATION_POLICY"}
async def faturas_agent(self, state):
async with self.telemetry.span(
"workflow.agent.billing",
@@ -820,13 +846,13 @@ class AgentWorkflow:
runtime_context = (state.get("context") or {}).get("business_context") or {}
await self.tool_router.call(
"finalizar_atendimento",
{"status": "resolvido", "summary": "Encerramento solicitado pelo agent_framework_oci", "confirmed": True},
{"status": str(state.get("terminal_status") or "resolvido"), "summary": "Encerramento solicitado pelo agent_framework_oci", "confirmed": True},
business_context=runtime_context,
original_context=state.get("context") or {},
)
except Exception:
pass
answer = str(getattr(self.settings, "END_SESSION_MESSAGE", "Atendimento encerrado. Obrigado pelo contato."))
answer = str(state.get("conversation_terminal_message") or getattr(self.settings, "END_SESSION_MESSAGE", "Atendimento encerrado. Obrigado pelo contato."))
await self.telemetry.event(
"session.end.requested",
{
@@ -840,7 +866,7 @@ class AgentWorkflow:
"answer": answer,
"session_control": "END_SESSION",
"session_ended": True,
"terminal_status": "resolvido",
"terminal_status": str(state.get("terminal_status") or "resolvido"),
"human_handoff_requested": False,
"next_state": "SESSION_ENDED",
}