new feature: Multi-Intent
This commit is contained in:
@@ -369,7 +369,7 @@ MCP_TOOL_CACHE_TTL_SECONDS=60
|
|||||||
# kbdb = KBDB enterprise via PKG_KB_SERVING.SEARCH_KNOWLEDGE_BASE
|
# kbdb = KBDB enterprise via PKG_KB_SERVING.SEARCH_KNOWLEDGE_BASE
|
||||||
RAG_PROVIDER=kbdb
|
RAG_PROVIDER=kbdb
|
||||||
|
|
||||||
# Somente usados quando RAG_PROVIDER=kbdb. Se vazios, credenciais caem para ADB_*.
|
# Somente usados quando RAG_PROVIDER=kbdb; não há fallback para as credenciais ADB_*.
|
||||||
KBDB_DB_USER=<DB_USER>
|
KBDB_DB_USER=<DB_USER>
|
||||||
KBDB_DB_PASSWORD=<DB_PASSWORD>
|
KBDB_DB_PASSWORD=<DB_PASSWORD>
|
||||||
KBDB_DB_DSN=db_dsn_high
|
KBDB_DB_DSN=db_dsn_high
|
||||||
@@ -383,3 +383,6 @@ KBDB_MAX_CROSS_REF_HOPS=1
|
|||||||
KBDB_DOCUMENT_TYPE=customer_safe
|
KBDB_DOCUMENT_TYPE=customer_safe
|
||||||
KBDB_METADATA_JSON=
|
KBDB_METADATA_JSON=
|
||||||
KBDB_MIN_SCORE=0.5
|
KBDB_MIN_SCORE=0.5
|
||||||
|
KBDB_IDENTIFY_DOCUMENT=true
|
||||||
|
KBDB_STORE_QUERY=true
|
||||||
|
KBDB_IDENTIFY_TOP_N=3
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class BillingAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "BILLING_ACTIVE",
|
"next_state": "BILLING_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class OrdersAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "ORDER_ACTIVE",
|
"next_state": "ORDER_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class ProductAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "PRODUCT_ACTIVE",
|
"next_state": "PRODUCT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class SupportAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "SUPPORT_ACTIVE",
|
"next_state": "SUPPORT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -372,6 +372,7 @@ async def _process_gateway_message(req: GatewayRequest, emit_sse: bool = False)
|
|||||||
"domain": result.get("domain"),
|
"domain": result.get("domain"),
|
||||||
"mcp_tools": result.get("mcp_tools"),
|
"mcp_tools": result.get("mcp_tools"),
|
||||||
"mcp_results": result.get("mcp_results"),
|
"mcp_results": result.get("mcp_results"),
|
||||||
|
"rag_results": result.get("rag_results"),
|
||||||
"business_context": business_context.model_dump(),
|
"business_context": business_context.model_dump(),
|
||||||
"identity_missing": missing_identity_keys,
|
"identity_missing": missing_identity_keys,
|
||||||
"judges": result.get("judge_results"),
|
"judges": result.get("judge_results"),
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class AgentState(TypedDict, total=False):
|
|||||||
domain: str
|
domain: str
|
||||||
mcp_tools: list[str]
|
mcp_tools: list[str]
|
||||||
mcp_results: list[dict[str, Any]]
|
mcp_results: list[dict[str, Any]]
|
||||||
|
rag_results: list[dict[str, Any]]
|
||||||
available_mcp_tools: list[str]
|
available_mcp_tools: list[str]
|
||||||
selected_tool_call: dict[str, Any]
|
selected_tool_call: dict[str, Any]
|
||||||
pending_tool_call: dict[str, Any]
|
pending_tool_call: dict[str, Any]
|
||||||
|
|||||||
@@ -570,6 +570,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"output_guardrails_already_applied": False,
|
"output_guardrails_already_applied": False,
|
||||||
"supervisor_action": "disabled",
|
"supervisor_action": "disabled",
|
||||||
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
||||||
@@ -577,7 +578,11 @@ class AgentWorkflow:
|
|||||||
|
|
||||||
context = {
|
context = {
|
||||||
**(state.get("context") or {}),
|
**(state.get("context") or {}),
|
||||||
"evidence": drained.mcp_results or (state.get("context") or {}).get("evidence"),
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
|
"mcp_results": drained.mcp_results,
|
||||||
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
@@ -650,6 +655,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"guardrail_decisions": state.get("guardrail_decisions", [])
|
"guardrail_decisions": state.get("guardrail_decisions", [])
|
||||||
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
||||||
}
|
}
|
||||||
@@ -876,6 +882,7 @@ class AgentWorkflow:
|
|||||||
"judges": state.get("judge_results", []),
|
"judges": state.get("judge_results", []),
|
||||||
"mcp_tools": state.get("mcp_tools", []),
|
"mcp_tools": state.get("mcp_tools", []),
|
||||||
"mcp_results": state.get("mcp_results", []),
|
"mcp_results": state.get("mcp_results", []),
|
||||||
|
"rag_results": state.get("rag_results", []),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class BillingAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "BILLING_ACTIVE",
|
"next_state": "BILLING_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class OrdersAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "ORDER_ACTIVE",
|
"next_state": "ORDER_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class ProductAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "PRODUCT_ACTIVE",
|
"next_state": "PRODUCT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class SupportAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "SUPPORT_ACTIVE",
|
"next_state": "SUPPORT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -366,6 +366,7 @@ async def _process_gateway_message(req: GatewayRequest, emit_sse: bool = False)
|
|||||||
"domain": result.get("domain"),
|
"domain": result.get("domain"),
|
||||||
"mcp_tools": result.get("mcp_tools"),
|
"mcp_tools": result.get("mcp_tools"),
|
||||||
"mcp_results": result.get("mcp_results"),
|
"mcp_results": result.get("mcp_results"),
|
||||||
|
"rag_results": result.get("rag_results"),
|
||||||
"business_context": business_context.model_dump(),
|
"business_context": business_context.model_dump(),
|
||||||
"identity_missing": missing_identity_keys,
|
"identity_missing": missing_identity_keys,
|
||||||
"judges": result.get("judge_results"),
|
"judges": result.get("judge_results"),
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class AgentState(TypedDict, total=False):
|
|||||||
domain: str
|
domain: str
|
||||||
mcp_tools: list[str]
|
mcp_tools: list[str]
|
||||||
mcp_results: list[dict[str, Any]]
|
mcp_results: list[dict[str, Any]]
|
||||||
|
rag_results: list[dict[str, Any]]
|
||||||
available_mcp_tools: list[str]
|
available_mcp_tools: list[str]
|
||||||
selected_tool_call: dict[str, Any]
|
selected_tool_call: dict[str, Any]
|
||||||
pending_tool_call: dict[str, Any]
|
pending_tool_call: dict[str, Any]
|
||||||
|
|||||||
@@ -570,6 +570,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"output_guardrails_already_applied": False,
|
"output_guardrails_already_applied": False,
|
||||||
"supervisor_action": "disabled",
|
"supervisor_action": "disabled",
|
||||||
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
||||||
@@ -577,7 +578,11 @@ class AgentWorkflow:
|
|||||||
|
|
||||||
context = {
|
context = {
|
||||||
**(state.get("context") or {}),
|
**(state.get("context") or {}),
|
||||||
"evidence": drained.mcp_results or (state.get("context") or {}).get("evidence"),
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
|
"mcp_results": drained.mcp_results,
|
||||||
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
@@ -650,6 +655,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"guardrail_decisions": state.get("guardrail_decisions", [])
|
"guardrail_decisions": state.get("guardrail_decisions", [])
|
||||||
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
||||||
}
|
}
|
||||||
@@ -876,6 +882,7 @@ class AgentWorkflow:
|
|||||||
"judges": state.get("judge_results", []),
|
"judges": state.get("judge_results", []),
|
||||||
"mcp_tools": state.get("mcp_tools", []),
|
"mcp_tools": state.get("mcp_tools", []),
|
||||||
"mcp_results": state.get("mcp_results", []),
|
"mcp_results": state.get("mcp_results", []),
|
||||||
|
"rag_results": state.get("rag_results", []),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class BillingAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "BILLING_ACTIVE",
|
"next_state": "BILLING_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class OrdersAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "ORDER_ACTIVE",
|
"next_state": "ORDER_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class ProductAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "PRODUCT_ACTIVE",
|
"next_state": "PRODUCT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class SupportAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "SUPPORT_ACTIVE",
|
"next_state": "SUPPORT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -361,6 +361,7 @@ async def _process_gateway_message(req: GatewayRequest, emit_sse: bool = False)
|
|||||||
"domain": result.get("domain"),
|
"domain": result.get("domain"),
|
||||||
"mcp_tools": result.get("mcp_tools"),
|
"mcp_tools": result.get("mcp_tools"),
|
||||||
"mcp_results": result.get("mcp_results"),
|
"mcp_results": result.get("mcp_results"),
|
||||||
|
"rag_results": result.get("rag_results"),
|
||||||
"business_context": business_context.model_dump(),
|
"business_context": business_context.model_dump(),
|
||||||
"identity_missing": missing_identity_keys,
|
"identity_missing": missing_identity_keys,
|
||||||
"judges": result.get("judge_results"),
|
"judges": result.get("judge_results"),
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class AgentState(TypedDict, total=False):
|
|||||||
domain: str
|
domain: str
|
||||||
mcp_tools: list[str]
|
mcp_tools: list[str]
|
||||||
mcp_results: list[dict[str, Any]]
|
mcp_results: list[dict[str, Any]]
|
||||||
|
rag_results: list[dict[str, Any]]
|
||||||
available_mcp_tools: list[str]
|
available_mcp_tools: list[str]
|
||||||
selected_tool_call: dict[str, Any]
|
selected_tool_call: dict[str, Any]
|
||||||
pending_tool_call: dict[str, Any]
|
pending_tool_call: dict[str, Any]
|
||||||
|
|||||||
@@ -568,6 +568,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"output_guardrails_already_applied": False,
|
"output_guardrails_already_applied": False,
|
||||||
"supervisor_action": "disabled",
|
"supervisor_action": "disabled",
|
||||||
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
||||||
@@ -575,7 +576,11 @@ class AgentWorkflow:
|
|||||||
|
|
||||||
context = {
|
context = {
|
||||||
**(state.get("context") or {}),
|
**(state.get("context") or {}),
|
||||||
"evidence": drained.mcp_results or (state.get("context") or {}).get("evidence"),
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
|
"mcp_results": drained.mcp_results,
|
||||||
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
@@ -648,6 +653,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"guardrail_decisions": state.get("guardrail_decisions", [])
|
"guardrail_decisions": state.get("guardrail_decisions", [])
|
||||||
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
||||||
}
|
}
|
||||||
@@ -805,6 +811,7 @@ class AgentWorkflow:
|
|||||||
"judges": state.get("judge_results", []),
|
"judges": state.get("judge_results", []),
|
||||||
"mcp_tools": state.get("mcp_tools", []),
|
"mcp_tools": state.get("mcp_tools", []),
|
||||||
"mcp_results": state.get("mcp_results", []),
|
"mcp_results": state.get("mcp_results", []),
|
||||||
|
"rag_results": state.get("rag_results", []),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class BillingAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "BILLING_ACTIVE",
|
"next_state": "BILLING_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class OrdersAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "ORDER_ACTIVE",
|
"next_state": "ORDER_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class ProductAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "PRODUCT_ACTIVE",
|
"next_state": "PRODUCT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class SupportAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "SUPPORT_ACTIVE",
|
"next_state": "SUPPORT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -366,6 +366,7 @@ async def _process_gateway_message(req: GatewayRequest, emit_sse: bool = False)
|
|||||||
"domain": result.get("domain"),
|
"domain": result.get("domain"),
|
||||||
"mcp_tools": result.get("mcp_tools"),
|
"mcp_tools": result.get("mcp_tools"),
|
||||||
"mcp_results": result.get("mcp_results"),
|
"mcp_results": result.get("mcp_results"),
|
||||||
|
"rag_results": result.get("rag_results"),
|
||||||
"business_context": business_context.model_dump(),
|
"business_context": business_context.model_dump(),
|
||||||
"identity_missing": missing_identity_keys,
|
"identity_missing": missing_identity_keys,
|
||||||
"judges": result.get("judge_results"),
|
"judges": result.get("judge_results"),
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class AgentState(TypedDict, total=False):
|
|||||||
domain: str
|
domain: str
|
||||||
mcp_tools: list[str]
|
mcp_tools: list[str]
|
||||||
mcp_results: list[dict[str, Any]]
|
mcp_results: list[dict[str, Any]]
|
||||||
|
rag_results: list[dict[str, Any]]
|
||||||
available_mcp_tools: list[str]
|
available_mcp_tools: list[str]
|
||||||
selected_tool_call: dict[str, Any]
|
selected_tool_call: dict[str, Any]
|
||||||
pending_tool_call: dict[str, Any]
|
pending_tool_call: dict[str, Any]
|
||||||
|
|||||||
@@ -570,6 +570,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"output_guardrails_already_applied": False,
|
"output_guardrails_already_applied": False,
|
||||||
"supervisor_action": "disabled",
|
"supervisor_action": "disabled",
|
||||||
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
||||||
@@ -577,7 +578,11 @@ class AgentWorkflow:
|
|||||||
|
|
||||||
context = {
|
context = {
|
||||||
**(state.get("context") or {}),
|
**(state.get("context") or {}),
|
||||||
"evidence": drained.mcp_results or (state.get("context") or {}).get("evidence"),
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
|
"mcp_results": drained.mcp_results,
|
||||||
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
@@ -650,6 +655,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"guardrail_decisions": state.get("guardrail_decisions", [])
|
"guardrail_decisions": state.get("guardrail_decisions", [])
|
||||||
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
||||||
}
|
}
|
||||||
@@ -876,6 +882,7 @@ class AgentWorkflow:
|
|||||||
"judges": state.get("judge_results", []),
|
"judges": state.get("judge_results", []),
|
||||||
"mcp_tools": state.get("mcp_tools", []),
|
"mcp_tools": state.get("mcp_tools", []),
|
||||||
"mcp_results": state.get("mcp_results", []),
|
"mcp_results": state.get("mcp_results", []),
|
||||||
|
"rag_results": state.get("rag_results", []),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class BillingAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "BILLING_ACTIVE",
|
"next_state": "BILLING_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class OrdersAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "ORDER_ACTIVE",
|
"next_state": "ORDER_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class ProductAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "PRODUCT_ACTIVE",
|
"next_state": "PRODUCT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class SupportAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "SUPPORT_ACTIVE",
|
"next_state": "SUPPORT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -361,6 +361,7 @@ async def _process_gateway_message(req: GatewayRequest, emit_sse: bool = False)
|
|||||||
"domain": result.get("domain"),
|
"domain": result.get("domain"),
|
||||||
"mcp_tools": result.get("mcp_tools"),
|
"mcp_tools": result.get("mcp_tools"),
|
||||||
"mcp_results": result.get("mcp_results"),
|
"mcp_results": result.get("mcp_results"),
|
||||||
|
"rag_results": result.get("rag_results"),
|
||||||
"business_context": business_context.model_dump(),
|
"business_context": business_context.model_dump(),
|
||||||
"identity_missing": missing_identity_keys,
|
"identity_missing": missing_identity_keys,
|
||||||
"judges": result.get("judge_results"),
|
"judges": result.get("judge_results"),
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class AgentState(TypedDict, total=False):
|
|||||||
domain: str
|
domain: str
|
||||||
mcp_tools: list[str]
|
mcp_tools: list[str]
|
||||||
mcp_results: list[dict[str, Any]]
|
mcp_results: list[dict[str, Any]]
|
||||||
|
rag_results: list[dict[str, Any]]
|
||||||
available_mcp_tools: list[str]
|
available_mcp_tools: list[str]
|
||||||
selected_tool_call: dict[str, Any]
|
selected_tool_call: dict[str, Any]
|
||||||
pending_tool_call: dict[str, Any]
|
pending_tool_call: dict[str, Any]
|
||||||
|
|||||||
@@ -568,6 +568,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"output_guardrails_already_applied": False,
|
"output_guardrails_already_applied": False,
|
||||||
"supervisor_action": "disabled",
|
"supervisor_action": "disabled",
|
||||||
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
||||||
@@ -575,7 +576,11 @@ class AgentWorkflow:
|
|||||||
|
|
||||||
context = {
|
context = {
|
||||||
**(state.get("context") or {}),
|
**(state.get("context") or {}),
|
||||||
"evidence": drained.mcp_results or (state.get("context") or {}).get("evidence"),
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
|
"mcp_results": drained.mcp_results,
|
||||||
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
@@ -648,6 +653,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"guardrail_decisions": state.get("guardrail_decisions", [])
|
"guardrail_decisions": state.get("guardrail_decisions", [])
|
||||||
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
||||||
}
|
}
|
||||||
@@ -805,6 +811,7 @@ class AgentWorkflow:
|
|||||||
"judges": state.get("judge_results", []),
|
"judges": state.get("judge_results", []),
|
||||||
"mcp_tools": state.get("mcp_tools", []),
|
"mcp_tools": state.get("mcp_tools", []),
|
||||||
"mcp_results": state.get("mcp_results", []),
|
"mcp_results": state.get("mcp_results", []),
|
||||||
|
"rag_results": state.get("rag_results", []),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class BillingAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "BILLING_ACTIVE",
|
"next_state": "BILLING_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class OrdersAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "ORDER_ACTIVE",
|
"next_state": "ORDER_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class ProductAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "PRODUCT_ACTIVE",
|
"next_state": "PRODUCT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class SupportAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "SUPPORT_ACTIVE",
|
"next_state": "SUPPORT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -361,6 +361,7 @@ async def _process_gateway_message(req: GatewayRequest, emit_sse: bool = False)
|
|||||||
"domain": result.get("domain"),
|
"domain": result.get("domain"),
|
||||||
"mcp_tools": result.get("mcp_tools"),
|
"mcp_tools": result.get("mcp_tools"),
|
||||||
"mcp_results": result.get("mcp_results"),
|
"mcp_results": result.get("mcp_results"),
|
||||||
|
"rag_results": result.get("rag_results"),
|
||||||
"business_context": business_context.model_dump(),
|
"business_context": business_context.model_dump(),
|
||||||
"identity_missing": missing_identity_keys,
|
"identity_missing": missing_identity_keys,
|
||||||
"judges": result.get("judge_results"),
|
"judges": result.get("judge_results"),
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class AgentState(TypedDict, total=False):
|
|||||||
domain: str
|
domain: str
|
||||||
mcp_tools: list[str]
|
mcp_tools: list[str]
|
||||||
mcp_results: list[dict[str, Any]]
|
mcp_results: list[dict[str, Any]]
|
||||||
|
rag_results: list[dict[str, Any]]
|
||||||
available_mcp_tools: list[str]
|
available_mcp_tools: list[str]
|
||||||
selected_tool_call: dict[str, Any]
|
selected_tool_call: dict[str, Any]
|
||||||
pending_tool_call: dict[str, Any]
|
pending_tool_call: dict[str, Any]
|
||||||
|
|||||||
@@ -568,6 +568,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"output_guardrails_already_applied": False,
|
"output_guardrails_already_applied": False,
|
||||||
"supervisor_action": "disabled",
|
"supervisor_action": "disabled",
|
||||||
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
||||||
@@ -575,7 +576,11 @@ class AgentWorkflow:
|
|||||||
|
|
||||||
context = {
|
context = {
|
||||||
**(state.get("context") or {}),
|
**(state.get("context") or {}),
|
||||||
"evidence": drained.mcp_results or (state.get("context") or {}).get("evidence"),
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
|
"mcp_results": drained.mcp_results,
|
||||||
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
@@ -648,6 +653,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"guardrail_decisions": state.get("guardrail_decisions", [])
|
"guardrail_decisions": state.get("guardrail_decisions", [])
|
||||||
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
||||||
}
|
}
|
||||||
@@ -805,6 +811,7 @@ class AgentWorkflow:
|
|||||||
"judges": state.get("judge_results", []),
|
"judges": state.get("judge_results", []),
|
||||||
"mcp_tools": state.get("mcp_tools", []),
|
"mcp_tools": state.get("mcp_tools", []),
|
||||||
"mcp_results": state.get("mcp_results", []),
|
"mcp_results": state.get("mcp_results", []),
|
||||||
|
"rag_results": state.get("rag_results", []),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class BillingAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "BILLING_ACTIVE",
|
"next_state": "BILLING_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class OrdersAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "ORDER_ACTIVE",
|
"next_state": "ORDER_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class ProductAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "PRODUCT_ACTIVE",
|
"next_state": "PRODUCT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class SupportAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "SUPPORT_ACTIVE",
|
"next_state": "SUPPORT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -361,6 +361,7 @@ async def _process_gateway_message(req: GatewayRequest, emit_sse: bool = False)
|
|||||||
"domain": result.get("domain"),
|
"domain": result.get("domain"),
|
||||||
"mcp_tools": result.get("mcp_tools"),
|
"mcp_tools": result.get("mcp_tools"),
|
||||||
"mcp_results": result.get("mcp_results"),
|
"mcp_results": result.get("mcp_results"),
|
||||||
|
"rag_results": result.get("rag_results"),
|
||||||
"business_context": business_context.model_dump(),
|
"business_context": business_context.model_dump(),
|
||||||
"identity_missing": missing_identity_keys,
|
"identity_missing": missing_identity_keys,
|
||||||
"judges": result.get("judge_results"),
|
"judges": result.get("judge_results"),
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class AgentState(TypedDict, total=False):
|
|||||||
domain: str
|
domain: str
|
||||||
mcp_tools: list[str]
|
mcp_tools: list[str]
|
||||||
mcp_results: list[dict[str, Any]]
|
mcp_results: list[dict[str, Any]]
|
||||||
|
rag_results: list[dict[str, Any]]
|
||||||
available_mcp_tools: list[str]
|
available_mcp_tools: list[str]
|
||||||
selected_tool_call: dict[str, Any]
|
selected_tool_call: dict[str, Any]
|
||||||
pending_tool_call: dict[str, Any]
|
pending_tool_call: dict[str, Any]
|
||||||
|
|||||||
@@ -568,6 +568,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"output_guardrails_already_applied": False,
|
"output_guardrails_already_applied": False,
|
||||||
"supervisor_action": "disabled",
|
"supervisor_action": "disabled",
|
||||||
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
||||||
@@ -575,7 +576,11 @@ class AgentWorkflow:
|
|||||||
|
|
||||||
context = {
|
context = {
|
||||||
**(state.get("context") or {}),
|
**(state.get("context") or {}),
|
||||||
"evidence": drained.mcp_results or (state.get("context") or {}).get("evidence"),
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
|
"mcp_results": drained.mcp_results,
|
||||||
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
@@ -648,6 +653,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"guardrail_decisions": state.get("guardrail_decisions", [])
|
"guardrail_decisions": state.get("guardrail_decisions", [])
|
||||||
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
||||||
}
|
}
|
||||||
@@ -805,6 +811,7 @@ class AgentWorkflow:
|
|||||||
"judges": state.get("judge_results", []),
|
"judges": state.get("judge_results", []),
|
||||||
"mcp_tools": state.get("mcp_tools", []),
|
"mcp_tools": state.get("mcp_tools", []),
|
||||||
"mcp_results": state.get("mcp_results", []),
|
"mcp_results": state.get("mcp_results", []),
|
||||||
|
"rag_results": state.get("rag_results", []),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class BillingAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "BILLING_ACTIVE",
|
"next_state": "BILLING_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class OrdersAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "ORDER_ACTIVE",
|
"next_state": "ORDER_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class ProductAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "PRODUCT_ACTIVE",
|
"next_state": "PRODUCT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class SupportAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "SUPPORT_ACTIVE",
|
"next_state": "SUPPORT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -361,6 +361,7 @@ async def _process_gateway_message(req: GatewayRequest, emit_sse: bool = False)
|
|||||||
"domain": result.get("domain"),
|
"domain": result.get("domain"),
|
||||||
"mcp_tools": result.get("mcp_tools"),
|
"mcp_tools": result.get("mcp_tools"),
|
||||||
"mcp_results": result.get("mcp_results"),
|
"mcp_results": result.get("mcp_results"),
|
||||||
|
"rag_results": result.get("rag_results"),
|
||||||
"business_context": business_context.model_dump(),
|
"business_context": business_context.model_dump(),
|
||||||
"identity_missing": missing_identity_keys,
|
"identity_missing": missing_identity_keys,
|
||||||
"judges": result.get("judge_results"),
|
"judges": result.get("judge_results"),
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class AgentState(TypedDict, total=False):
|
|||||||
domain: str
|
domain: str
|
||||||
mcp_tools: list[str]
|
mcp_tools: list[str]
|
||||||
mcp_results: list[dict[str, Any]]
|
mcp_results: list[dict[str, Any]]
|
||||||
|
rag_results: list[dict[str, Any]]
|
||||||
available_mcp_tools: list[str]
|
available_mcp_tools: list[str]
|
||||||
selected_tool_call: dict[str, Any]
|
selected_tool_call: dict[str, Any]
|
||||||
pending_tool_call: dict[str, Any]
|
pending_tool_call: dict[str, Any]
|
||||||
|
|||||||
@@ -568,6 +568,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"output_guardrails_already_applied": False,
|
"output_guardrails_already_applied": False,
|
||||||
"supervisor_action": "disabled",
|
"supervisor_action": "disabled",
|
||||||
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
||||||
@@ -575,7 +576,11 @@ class AgentWorkflow:
|
|||||||
|
|
||||||
context = {
|
context = {
|
||||||
**(state.get("context") or {}),
|
**(state.get("context") or {}),
|
||||||
"evidence": drained.mcp_results or (state.get("context") or {}).get("evidence"),
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
|
"mcp_results": drained.mcp_results,
|
||||||
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
@@ -648,6 +653,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"guardrail_decisions": state.get("guardrail_decisions", [])
|
"guardrail_decisions": state.get("guardrail_decisions", [])
|
||||||
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
||||||
}
|
}
|
||||||
@@ -805,6 +811,7 @@ class AgentWorkflow:
|
|||||||
"judges": state.get("judge_results", []),
|
"judges": state.get("judge_results", []),
|
||||||
"mcp_tools": state.get("mcp_tools", []),
|
"mcp_tools": state.get("mcp_tools", []),
|
||||||
"mcp_results": state.get("mcp_results", []),
|
"mcp_results": state.get("mcp_results", []),
|
||||||
|
"rag_results": state.get("rag_results", []),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class BillingAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "BILLING_ACTIVE",
|
"next_state": "BILLING_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class OrdersAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "ORDER_ACTIVE",
|
"next_state": "ORDER_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class ProductAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "PRODUCT_ACTIVE",
|
"next_state": "PRODUCT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class SupportAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "SUPPORT_ACTIVE",
|
"next_state": "SUPPORT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -460,6 +460,7 @@ async def _process_gateway_message(req: GatewayRequest, emit_sse: bool = False)
|
|||||||
"domain": result.get("domain"),
|
"domain": result.get("domain"),
|
||||||
"mcp_tools": result.get("mcp_tools"),
|
"mcp_tools": result.get("mcp_tools"),
|
||||||
"mcp_results": result.get("mcp_results"),
|
"mcp_results": result.get("mcp_results"),
|
||||||
|
"rag_results": result.get("rag_results"),
|
||||||
"transaction_evidence": result.get("relevant_transaction_evidence", []),
|
"transaction_evidence": result.get("relevant_transaction_evidence", []),
|
||||||
"business_context": business_context.model_dump(),
|
"business_context": business_context.model_dump(),
|
||||||
"identity_missing": missing_identity_keys,
|
"identity_missing": missing_identity_keys,
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class AgentState(TypedDict, total=False):
|
|||||||
domain: str
|
domain: str
|
||||||
mcp_tools: list[str]
|
mcp_tools: list[str]
|
||||||
mcp_results: list[dict[str, Any]]
|
mcp_results: list[dict[str, Any]]
|
||||||
|
rag_results: list[dict[str, Any]]
|
||||||
available_mcp_tools: list[str]
|
available_mcp_tools: list[str]
|
||||||
selected_tool_call: dict[str, Any]
|
selected_tool_call: dict[str, Any]
|
||||||
pending_tool_call: dict[str, Any]
|
pending_tool_call: dict[str, Any]
|
||||||
|
|||||||
@@ -570,6 +570,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"output_guardrails_already_applied": False,
|
"output_guardrails_already_applied": False,
|
||||||
"supervisor_action": "disabled",
|
"supervisor_action": "disabled",
|
||||||
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
||||||
@@ -577,7 +578,11 @@ class AgentWorkflow:
|
|||||||
|
|
||||||
context = {
|
context = {
|
||||||
**(state.get("context") or {}),
|
**(state.get("context") or {}),
|
||||||
"evidence": drained.mcp_results or (state.get("context") or {}).get("evidence"),
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
|
"mcp_results": drained.mcp_results,
|
||||||
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
@@ -650,6 +655,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"guardrail_decisions": state.get("guardrail_decisions", [])
|
"guardrail_decisions": state.get("guardrail_decisions", [])
|
||||||
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
||||||
}
|
}
|
||||||
@@ -733,6 +739,7 @@ class AgentWorkflow:
|
|||||||
relevant_transaction_evidence = list(state.get("relevant_transaction_evidence") or [])
|
relevant_transaction_evidence = list(state.get("relevant_transaction_evidence") or [])
|
||||||
judge_context["transaction_evidence"] = relevant_transaction_evidence
|
judge_context["transaction_evidence"] = relevant_transaction_evidence
|
||||||
current_evidence = list(state.get("mcp_results", []) or [])
|
current_evidence = list(state.get("mcp_results", []) or [])
|
||||||
|
current_evidence.extend(state.get("rag_results", []) or [])
|
||||||
current_evidence.extend(relevant_transaction_evidence)
|
current_evidence.extend(relevant_transaction_evidence)
|
||||||
judge_context["evidence"] = current_evidence or judge_context.get("evidence")
|
judge_context["evidence"] = current_evidence or judge_context.get("evidence")
|
||||||
judge_context["route"] = state.get("route")
|
judge_context["route"] = state.get("route")
|
||||||
@@ -880,6 +887,7 @@ class AgentWorkflow:
|
|||||||
"judges": state.get("judge_results", []),
|
"judges": state.get("judge_results", []),
|
||||||
"mcp_tools": state.get("mcp_tools", []),
|
"mcp_tools": state.get("mcp_tools", []),
|
||||||
"mcp_results": state.get("mcp_results", []),
|
"mcp_results": state.get("mcp_results", []),
|
||||||
|
"rag_results": state.get("rag_results", []),
|
||||||
"transaction_evidence": state.get("relevant_transaction_evidence", []),
|
"transaction_evidence": state.get("relevant_transaction_evidence", []),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class BillingAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "BILLING_ACTIVE",
|
"next_state": "BILLING_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class OrdersAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "ORDER_ACTIVE",
|
"next_state": "ORDER_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class ProductAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "PRODUCT_ACTIVE",
|
"next_state": "PRODUCT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,14 @@ class SupportAgent(AgentRuntimeMixin):
|
|||||||
"next_state": "SUPPORT_ACTIVE",
|
"next_state": "SUPPORT_ACTIVE",
|
||||||
"mcp_results": tool_context,
|
"mcp_results": tool_context,
|
||||||
"rag": rag_metadata,
|
"rag": rag_metadata,
|
||||||
|
"rag_context": rag_context,
|
||||||
|
"rag_results": [{
|
||||||
|
"intent": state.get("intent"),
|
||||||
|
"agent": self.name,
|
||||||
|
"source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),
|
||||||
|
"metadata": rag_metadata,
|
||||||
|
**({"context": rag_context} if rag_context else {}),
|
||||||
|
}],
|
||||||
"memory_context_metadata": state.get("memory_context_metadata"),
|
"memory_context_metadata": state.get("memory_context_metadata"),
|
||||||
**self.transaction_state_patch(state),
|
**self.transaction_state_patch(state),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -460,6 +460,7 @@ async def _process_gateway_message(req: GatewayRequest, emit_sse: bool = False)
|
|||||||
"domain": result.get("domain"),
|
"domain": result.get("domain"),
|
||||||
"mcp_tools": result.get("mcp_tools"),
|
"mcp_tools": result.get("mcp_tools"),
|
||||||
"mcp_results": result.get("mcp_results"),
|
"mcp_results": result.get("mcp_results"),
|
||||||
|
"rag_results": result.get("rag_results"),
|
||||||
"transaction_evidence": result.get("relevant_transaction_evidence", []),
|
"transaction_evidence": result.get("relevant_transaction_evidence", []),
|
||||||
"transaction_pre_validation": result.get("transaction_pre_validation"),
|
"transaction_pre_validation": result.get("transaction_pre_validation"),
|
||||||
"business_context": business_context.model_dump(),
|
"business_context": business_context.model_dump(),
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class AgentState(TypedDict, total=False):
|
|||||||
domain: str
|
domain: str
|
||||||
mcp_tools: list[str]
|
mcp_tools: list[str]
|
||||||
mcp_results: list[dict[str, Any]]
|
mcp_results: list[dict[str, Any]]
|
||||||
|
rag_results: list[dict[str, Any]]
|
||||||
available_mcp_tools: list[str]
|
available_mcp_tools: list[str]
|
||||||
selected_tool_call: dict[str, Any]
|
selected_tool_call: dict[str, Any]
|
||||||
pending_tool_call: dict[str, Any]
|
pending_tool_call: dict[str, Any]
|
||||||
|
|||||||
@@ -570,6 +570,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"output_guardrails_already_applied": False,
|
"output_guardrails_already_applied": False,
|
||||||
"supervisor_action": "disabled",
|
"supervisor_action": "disabled",
|
||||||
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
"supervisor_attempt": int(state.get("supervisor_attempt", 0)),
|
||||||
@@ -577,7 +578,11 @@ class AgentWorkflow:
|
|||||||
|
|
||||||
context = {
|
context = {
|
||||||
**(state.get("context") or {}),
|
**(state.get("context") or {}),
|
||||||
"evidence": drained.mcp_results or (state.get("context") or {}).get("evidence"),
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
|
"mcp_results": drained.mcp_results,
|
||||||
|
"evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),
|
||||||
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
"tool_result": drained.mcp_results or (state.get("context") or {}).get("tool_result"),
|
||||||
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
"tool_executed": any(isinstance(item, dict) and item.get("ok") for item in drained.mcp_results),
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
@@ -650,6 +655,7 @@ class AgentWorkflow:
|
|||||||
"pending_topics": drained.pending_topics,
|
"pending_topics": drained.pending_topics,
|
||||||
"handled_topics": drained.handled_topics,
|
"handled_topics": drained.handled_topics,
|
||||||
"mcp_results": drained.mcp_results,
|
"mcp_results": drained.mcp_results,
|
||||||
|
"rag_results": drained.rag_results,
|
||||||
"guardrail_decisions": state.get("guardrail_decisions", [])
|
"guardrail_decisions": state.get("guardrail_decisions", [])
|
||||||
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
+ [item for r in decision.results for item in (r.metadata or {}).get("legacy_decisions", [])],
|
||||||
}
|
}
|
||||||
@@ -733,6 +739,7 @@ class AgentWorkflow:
|
|||||||
relevant_transaction_evidence = list(state.get("relevant_transaction_evidence") or [])
|
relevant_transaction_evidence = list(state.get("relevant_transaction_evidence") or [])
|
||||||
judge_context["transaction_evidence"] = relevant_transaction_evidence
|
judge_context["transaction_evidence"] = relevant_transaction_evidence
|
||||||
current_evidence = list(state.get("mcp_results", []) or [])
|
current_evidence = list(state.get("mcp_results", []) or [])
|
||||||
|
current_evidence.extend(state.get("rag_results", []) or [])
|
||||||
current_evidence.extend(relevant_transaction_evidence)
|
current_evidence.extend(relevant_transaction_evidence)
|
||||||
judge_context["evidence"] = current_evidence or judge_context.get("evidence")
|
judge_context["evidence"] = current_evidence or judge_context.get("evidence")
|
||||||
judge_context["route"] = state.get("route")
|
judge_context["route"] = state.get("route")
|
||||||
@@ -880,6 +887,7 @@ class AgentWorkflow:
|
|||||||
"judges": state.get("judge_results", []),
|
"judges": state.get("judge_results", []),
|
||||||
"mcp_tools": state.get("mcp_tools", []),
|
"mcp_tools": state.get("mcp_tools", []),
|
||||||
"mcp_results": state.get("mcp_results", []),
|
"mcp_results": state.get("mcp_results", []),
|
||||||
|
"rag_results": state.get("rag_results", []),
|
||||||
"transaction_evidence": state.get("relevant_transaction_evidence", []),
|
"transaction_evidence": state.get("relevant_transaction_evidence", []),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user