refactor: 简化 AgentScope 运行时模块与 prompt 系统

This commit is contained in:
zl-q
2026-03-15 17:14:15 +08:00
parent 61997f3613
commit 072c09d99d
32 changed files with 750 additions and 1863 deletions
@@ -104,7 +104,23 @@ async def test_orchestrator_maps_binary_to_model_image_url(
orchestrator = AgentScopeRuntimeOrchestrator(pipeline=pipeline, runner=runner)
await orchestrator.run(
command=_run_command_with_binary(),
thread_id="00000000-0000-0000-0000-000000000010",
run_id="run-1",
context_messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "看这张图"},
{
"type": "image",
"source": {
"type": "url",
"url": "https://example.com/signed.png",
},
},
],
}
],
owner_id=UUID("00000000-0000-0000-0000-000000000001"),
user_context=_user_context(),
session=None,
@@ -132,7 +148,9 @@ async def test_orchestrator_emits_worker_output_on_text_end(
orchestrator = AgentScopeRuntimeOrchestrator(pipeline=pipeline, runner=runner)
await orchestrator.run(
command=_run_command_with_binary(),
thread_id="00000000-0000-0000-0000-000000000010",
run_id="run-1",
context_messages=[],
owner_id=UUID("00000000-0000-0000-0000-000000000001"),
user_context=_user_context(),
session=None,
@@ -31,7 +31,7 @@ class _FakeSessionCtx:
async def test_run_agentscope_task_calls_runtime_run(
monkeypatch: pytest.MonkeyPatch,
) -> None:
called: dict[str, int] = {"run": 0, "resume": 0}
called: dict[str, int] = {"run": 0}
class _FakeRuntime:
def __init__(self, **kwargs: object) -> None:
@@ -42,11 +42,6 @@ async def test_run_agentscope_task_calls_runtime_run(
called["run"] += 1
return object()
async def resume(self, **kwargs: object) -> object:
del kwargs
called["resume"] += 1
return object()
async def _fake_get_redis_client() -> object:
return object()
@@ -54,7 +49,7 @@ async def test_run_agentscope_task_calls_runtime_run(
del kwargs
return []
monkeypatch.setattr(tasks_module, "AgentRouteRuntime", _FakeRuntime)
monkeypatch.setattr(tasks_module, "AgentScopeRuntimeOrchestrator", _FakeRuntime)
monkeypatch.setattr(
tasks_module,
"get_or_init_redis_client",
@@ -77,7 +72,6 @@ async def test_run_agentscope_task_calls_runtime_run(
assert result["status"] == "completed"
assert called["run"] == 1
assert called["resume"] == 0
@pytest.mark.asyncio
@@ -98,10 +92,6 @@ async def test_run_agentscope_task_includes_recent_context_messages(
captured_messages.extend(raw_messages)
return object()
async def resume(self, **kwargs: object) -> object:
del kwargs
return object()
async def _fake_get_redis_client() -> object:
return object()
@@ -113,7 +103,7 @@ async def test_run_agentscope_task_includes_recent_context_messages(
del kwargs
return [{"id": "ctx-1", "role": "assistant", "content": "历史上下文"}]
monkeypatch.setattr(tasks_module, "AgentRouteRuntime", _FakeRuntime)
monkeypatch.setattr(tasks_module, "AgentScopeRuntimeOrchestrator", _FakeRuntime)
monkeypatch.setattr(
tasks_module,
"get_or_init_redis_client",
@@ -146,50 +136,6 @@ async def test_run_agentscope_task_includes_recent_context_messages(
assert captured_messages[1]["id"] == "u1"
@pytest.mark.asyncio
async def test_run_agentscope_task_calls_runtime_resume(
monkeypatch: pytest.MonkeyPatch,
) -> None:
called: dict[str, int] = {"run": 0, "resume": 0}
class _FakeRuntime:
def __init__(self, **kwargs: object) -> None:
del kwargs
async def run(self, **kwargs: object) -> object:
del kwargs
called["run"] += 1
return object()
async def resume(self, **kwargs: object) -> object:
del kwargs
called["resume"] += 1
return object()
async def _fake_get_redis_client() -> object:
return object()
monkeypatch.setattr(tasks_module, "AgentRouteRuntime", _FakeRuntime)
monkeypatch.setattr(
tasks_module,
"get_or_init_redis_client",
_fake_get_redis_client,
)
monkeypatch.setattr(tasks_module, "AsyncSessionLocal", lambda: _FakeSessionCtx())
result = await tasks_module.run_agentscope_task(
{
"command": "resume",
"owner_id": str(uuid4()),
"run_input": _run_input_payload(),
}
)
assert result["status"] == "completed"
assert called["run"] == 0
assert called["resume"] == 1
@pytest.mark.asyncio
async def test_run_agentscope_task_requires_owner_id() -> None:
with pytest.raises(ValueError, match="owner_id is required"):