refactor: unify skills+cli runtime and streamline ag-ui flow

This commit is contained in:
qzl
2026-04-22 17:09:37 +08:00
parent eeed737949
commit 4d55df45ab
111 changed files with 4858 additions and 3264 deletions
@@ -1,90 +1,28 @@
from __future__ import annotations
from schemas.agent.runtime_models import RouterAgentOutput, WorkerAgentOutputRich
from schemas.agent.runtime_models import RouterAgentOutput, WorkerAgentOutputLite
def test_router_agent_output_coerces_key_entity_value_to_string() -> None:
def test_router_agent_output_parses_simplified_contract() -> None:
payload = {
"normalized_task_input": {
"user_text": "test",
"multimodal_summary": [],
"context_summary": "",
},
"key_entities": [
{
"name": "priority",
"type": "number",
"value": 8,
}
],
"constraints": [],
"task_typing": {
"primary": "planning",
"secondary": [],
},
"execution_mode": "onestep",
"result_typing": {
"primary": "summary",
"secondary": [],
},
"objective": "查询今天的日程安排",
"context_summary": "用户询问天气",
"requires_tool_evidence": True,
}
model = RouterAgentOutput.model_validate(payload)
assert model.key_entities[0].value == "8"
assert model.objective == "查询今天的日程安排"
assert model.requires_tool_evidence is True
def test_router_agent_output_coerces_constraint_value_to_string() -> None:
payload = {
"normalized_task_input": {
"user_text": "test",
"multimodal_summary": [],
"context_summary": "",
},
"key_entities": [],
"constraints": [
{
"key": "strict_mode",
"value": True,
"required": True,
}
],
"task_typing": {
"primary": "planning",
"secondary": [],
},
"execution_mode": "onestep",
"result_typing": {
"primary": "summary",
"secondary": [],
},
}
model = RouterAgentOutput.model_validate(payload)
assert model.constraints[0].value == "True"
def test_worker_agent_output_rich_accepts_list_item_status_object() -> None:
def test_worker_agent_output_lite_keeps_suggested_actions() -> None:
payload = {
"status": "success",
"answer": "done",
"result_type": "summary",
"ui_hints": {
"intent": "status",
"status": "info",
"title": "状态",
"listItems": [
{
"title": "任务A",
"status": {"type": "info", "value": "已归档"},
}
],
},
"suggested_actions": ["要不要我继续帮你查明天的安排?"],
}
model = WorkerAgentOutputRich.model_validate(payload)
model = WorkerAgentOutputLite.model_validate(payload)
assert model.ui_hints is not None
assert model.ui_hints.list_items[0].status is not None
assert model.ui_hints.list_items[0].status.value == "info"
assert model.suggested_actions == ["要不要我继续帮你查明天的安排?"]
@@ -5,27 +5,20 @@ import pytest
from schemas.agent.system_agent import SystemAgentLLMConfig
def test_system_agent_llm_config_normalizes_enabled_tools_aliases() -> None:
def test_system_agent_llm_config_normalizes_enabled_skills() -> None:
config = SystemAgentLLMConfig.model_validate(
{
"enabled_tools": [
"calendar.write",
"calendar_write",
"user.lookup",
]
"enabled_skills": ["calendar", "calendar", "contacts"]
}
)
assert [tool.value for tool in config.enabled_tools] == [
"calendar.write",
"user.lookup",
]
assert [skill.value for skill in config.enabled_skills] == ["calendar", "contacts"]
def test_system_agent_llm_config_rejects_unknown_enabled_tool() -> None:
with pytest.raises(ValueError, match="unknown enabled tool"):
def test_system_agent_llm_config_rejects_unknown_enabled_skill() -> None:
with pytest.raises(ValueError):
SystemAgentLLMConfig.model_validate(
{
"enabled_tools": ["calendar.remove"],
"enabled_skills": ["calendar.remove"],
}
)