mirror of
https://github.com/hoshikawa2/agent_platform_oci.git
synced 2026-11-06 03:14:12 +00:00
new feature: frontend with separated responses
This commit is contained in:
@@ -40,6 +40,28 @@ def test_transactional_intent_is_primary_even_when_mentioned_second():
|
||||
assert [item.intent for item in plan.operations] == ["cancel", "invoice"]
|
||||
|
||||
|
||||
def test_multiword_keyword_accepts_intermediate_qualifier_without_yaml_variant():
|
||||
plan = _planner().plan("quero cancelar meu pedido e preciso da segunda via")
|
||||
assert plan is not None
|
||||
assert [item.intent for item in plan.operations] == ["cancel", "invoice"]
|
||||
|
||||
|
||||
def test_first_of_multiple_transactions_is_primary_and_next_is_deferred():
|
||||
planner = MultiIntentPlanner([
|
||||
IntentDefinition(name="invoice", agent="billing", priority=30, keywords=["fatura"], mcp_tools=["consultar_fatura"]),
|
||||
IntentDefinition(name="return", agent="support", priority=20, keywords=["devolver pedido"], mcp_tools=["solicitar_devolucao"]),
|
||||
IntentDefinition(name="cancel", agent="orders", priority=10, keywords=["cancelar pedido"], mcp_tools=["cancelar_pedido"]),
|
||||
], transactional_tools={"solicitar_devolucao", "cancelar_pedido"})
|
||||
|
||||
plan = planner.plan(
|
||||
"quero consultar minha fatura. quero devolver pedido. quero cancelar pedido"
|
||||
)
|
||||
|
||||
assert plan is not None
|
||||
assert [item.intent for item in plan.operations] == ["return", "invoice", "cancel"]
|
||||
assert [item.disposition for item in plan.operations] == ["execute", "execute", "defer"]
|
||||
|
||||
|
||||
def test_sentence_boundary_does_not_leak_previous_intent_into_knowledge_query():
|
||||
planner = MultiIntentPlanner([
|
||||
IntentDefinition(name="invoice", agent="billing", priority=20, keywords=["fatura"]),
|
||||
|
||||
@@ -66,3 +66,52 @@ async def test_secondary_topic_does_not_inherit_primary_transaction_state():
|
||||
]
|
||||
assert result.rag_results[0]["metadata"]["provider"] == "kbdb"
|
||||
assert result.rag_results[0]["context"] == "Documento recuperado da base de conhecimento."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_deferred_transaction_is_promoted_after_primary_completes():
|
||||
async def cancellation_agent(state):
|
||||
assert state["user_text"] == "quero cancelar meu pedido"
|
||||
return {
|
||||
"answer": "Você confirma o cancelamento do pedido PED-1001?",
|
||||
"transaction_status": "AWAITING_CONFIRMATION",
|
||||
"confirmation_required": True,
|
||||
"pending_tool_call": {
|
||||
"tool_name": "cancelar_pedido",
|
||||
"arguments": {"order_id": "PED-1001"},
|
||||
},
|
||||
"active_transaction": {
|
||||
"tool_name": "cancelar_pedido",
|
||||
"status": "AWAITING_CONFIRMATION",
|
||||
},
|
||||
}
|
||||
|
||||
state = {
|
||||
"answer": "A devolução foi registrada com sucesso.",
|
||||
"route": "support_agent",
|
||||
"active_agent": "support_agent",
|
||||
"intent": "retail_support_exchange_return",
|
||||
"transaction_status": "COMPLETED",
|
||||
"pending_topics": [{
|
||||
"operation_id": "op-3",
|
||||
"intent": "retail_order_cancel",
|
||||
"agent": "orders_agent",
|
||||
"domain": "retail",
|
||||
"tools": ["consultar_pedido", "cancelar_pedido"],
|
||||
"source_text": "quero cancelar meu pedido",
|
||||
"disposition": "defer",
|
||||
"status": "pending",
|
||||
}],
|
||||
}
|
||||
|
||||
result = await drain_pending_topics(
|
||||
state, state["answer"], {"orders_agent": cancellation_agent}
|
||||
)
|
||||
|
||||
assert result.pending_topics == []
|
||||
assert result.state_patch["route"] == "orders_agent"
|
||||
assert result.state_patch["intent"] == "retail_order_cancel"
|
||||
assert result.state_patch["transaction_status"] == "AWAITING_CONFIRMATION"
|
||||
assert result.state_patch["pending_tool_call"]["tool_name"] == "cancelar_pedido"
|
||||
assert result.agent_responses[-1]["primary"] is True
|
||||
assert result.agent_responses[-1]["agent"] == "orders_agent"
|
||||
|
||||
Reference in New Issue
Block a user