2026-06-15 22:55:18 +08:00
|
|
|
|
from app.services.steward_intent_agent import (
|
|
|
|
|
|
STEWARD_INTENT_FUNCTION_NAME,
|
|
|
|
|
|
StewardIntentAgent,
|
|
|
|
|
|
)
|
2026-06-24 21:58:35 +08:00
|
|
|
|
from app.schemas.steward import StewardPlanRequest
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _NoToolCallRuntimeChatService:
|
|
|
|
|
|
def __init__(self) -> None:
|
|
|
|
|
|
self.kwargs = {}
|
|
|
|
|
|
|
|
|
|
|
|
def complete_with_tool_call(self, messages, **kwargs):
|
|
|
|
|
|
self.kwargs = kwargs
|
|
|
|
|
|
|
|
|
|
|
|
class _Result:
|
|
|
|
|
|
tool_call = None
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def calls_as_dicts():
|
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
|
|
return _Result()
|
2026-06-15 22:55:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_steward_intent_tool_schema_supports_pending_flow_confirmation() -> None:
|
|
|
|
|
|
schema = StewardIntentAgent._build_intent_tool_schema(
|
|
|
|
|
|
["expense_type", "time_range", "location", "reason", "transport_mode"]
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
function_schema = schema["function"]
|
|
|
|
|
|
assert function_schema["name"] == STEWARD_INTENT_FUNCTION_NAME
|
|
|
|
|
|
properties = function_schema["parameters"]["properties"]
|
2026-06-24 21:58:35 +08:00
|
|
|
|
task_schema = properties["tasks"]["items"]
|
2026-06-15 22:55:18 +08:00
|
|
|
|
pending_schema = properties["pending_flow_confirmation"]
|
|
|
|
|
|
candidate_schema = pending_schema["properties"]["candidate_flows"]["items"]
|
|
|
|
|
|
|
2026-06-24 21:58:35 +08:00
|
|
|
|
assert task_schema["properties"]["requested_action"]["enum"] == [
|
|
|
|
|
|
"preview",
|
|
|
|
|
|
"save_draft",
|
|
|
|
|
|
"submit",
|
|
|
|
|
|
]
|
|
|
|
|
|
assert "requested_action" in task_schema["required"]
|
2026-06-15 22:55:18 +08:00
|
|
|
|
assert "pending_flow_confirmation" in properties
|
|
|
|
|
|
assert pending_schema["properties"]["status"]["enum"] == ["none", "pending"]
|
|
|
|
|
|
assert candidate_schema["properties"]["flow_id"]["enum"] == [
|
|
|
|
|
|
"travel_application",
|
|
|
|
|
|
"travel_reimbursement",
|
|
|
|
|
|
]
|
|
|
|
|
|
assert candidate_schema["properties"]["missing_fields"]["items"]["enum"] == [
|
|
|
|
|
|
"expense_type",
|
|
|
|
|
|
"time_range",
|
|
|
|
|
|
"location",
|
|
|
|
|
|
"reason",
|
|
|
|
|
|
"transport_mode",
|
|
|
|
|
|
]
|
2026-06-24 21:58:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_steward_intent_agent_uses_ten_second_timeout_and_three_attempts() -> None:
|
|
|
|
|
|
runtime_chat = _NoToolCallRuntimeChatService()
|
|
|
|
|
|
agent = StewardIntentAgent(runtime_chat)
|
|
|
|
|
|
|
|
|
|
|
|
agent.detect(
|
|
|
|
|
|
StewardPlanRequest(message="2026-02-20 至 2026-02-23,上海出差,火车,保存草稿。"),
|
|
|
|
|
|
base_date=__import__("datetime").date(2026, 6, 24),
|
|
|
|
|
|
canonical_fields=["expense_type", "time_range", "location", "reason", "transport_mode"],
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert runtime_chat.kwargs["timeout_seconds"] == 10
|
|
|
|
|
|
assert runtime_chat.kwargs["max_attempts"] == 3
|
|
|
|
|
|
assert runtime_chat.kwargs["use_failure_cooldown"] is False
|