feat: add remote workspaces and verified deliverables

This commit is contained in:
wuyang
2026-07-26 12:58:04 +08:00
parent 37f83eaac7
commit 0b4d799216
30 changed files with 1595 additions and 55 deletions
+134 -2
View File
@@ -6,7 +6,7 @@ from typing import Any
from agent_platform.auth import UserIdentity
from agent_platform.models import get_model_spec
from agent_platform.runtime.loop import AgentLoop
from agent_platform.runtime.loop import AgentLoop, tool_event_details
from agent_platform.runtime.tools import TOOL_METADATA
from agent_platform.store import RuntimeStore
@@ -119,11 +119,23 @@ async def test_mutating_tool_calls_are_serialized(settings) -> None:
}
]
}
verify = {
"choices": [
{
"message": {
"role": "assistant",
"content": None,
"tool_calls": [tool_call("3", "read_file", {"path": "a"})],
},
"finish_reason": "tool_calls",
}
]
}
final = {"choices": [{"message": {"role": "assistant", "content": "done"}, "finish_reason": "stop"}]}
store = RuntimeStore(settings.database_url)
await store.initialize()
registry = SerialRegistry()
loop = AgentLoop(ScriptedProvider([first, final]), registry, store, max_tool_output_chars=10_000)
loop = AgentLoop(ScriptedProvider([first, verify, final]), registry, store, max_tool_output_chars=10_000)
async def callback(event_type, payload):
return None
@@ -140,3 +152,123 @@ async def test_mutating_tool_calls_are_serialized(settings) -> None:
assert registry.max_active == 1
finally:
await store.close()
class RecordingRegistry:
def __init__(self) -> None:
self.calls = []
def specs(self, *, read_only=False, allow_delegate=True):
return [metadata.openai_spec() for metadata in TOOL_METADATA.values()]
async def execute(self, name, arguments, context):
self.calls.append((name, arguments))
return {"ok": True, "output": f"{name} complete"}
async def test_artifact_completion_is_rejected_until_written_and_verified(settings) -> None:
premature = {"choices": [{"message": {"role": "assistant", "content": "报告已经完成"}, "finish_reason": "stop"}]}
write = {
"choices": [
{
"message": {
"role": "assistant",
"tool_calls": [tool_call("1", "write_file", {"path": "report.md", "content": "ok"})],
},
"finish_reason": "tool_calls",
}
]
}
verify = {
"choices": [
{
"message": {
"role": "assistant",
"tool_calls": [tool_call("2", "read_file", {"path": "report.md"})],
},
"finish_reason": "tool_calls",
}
]
}
final = {"choices": [{"message": {"role": "assistant", "content": "已完成 report.md"}, "finish_reason": "stop"}]}
provider = ScriptedProvider([premature, write, verify, final])
registry = RecordingRegistry()
store = RuntimeStore(settings.database_url)
await store.initialize()
events = []
async def callback(event_type, payload):
events.append(event_type)
try:
answer = await AgentLoop(provider, registry, store, max_tool_output_chars=10_000).run(
spec=get_model_spec("work-light"),
messages=[{"role": "user", "content": "写一个脚本并生成报告"}],
identity=UserIdentity("u1", "", "", "user"),
raw_user_jwt="jwt",
chat_id="c1",
callback=callback,
)
assert answer == "已完成 report.md"
assert [name for name, _ in registry.calls] == ["write_file", "read_file"]
assert "completion.rejected" in events
finally:
await store.close()
async def test_bare_interactive_exec_is_blocked_before_registry(settings) -> None:
first = {
"choices": [
{
"message": {
"role": "assistant",
"tool_calls": [tool_call("1", "exec", {"command": "python3"})],
},
"finish_reason": "tool_calls",
}
]
}
final = {"choices": [{"message": {"role": "assistant", "content": "无法执行"}, "finish_reason": "stop"}]}
registry = RecordingRegistry()
store = RuntimeStore(settings.database_url)
await store.initialize()
async def callback(event_type, payload):
return None
try:
answer = await AgentLoop(
ScriptedProvider([first, final]),
registry,
store,
max_tool_output_chars=10_000,
).run(
spec=get_model_spec("work-light"),
messages=[{"role": "user", "content": "你好"}],
identity=UserIdentity("u1", "", "", "user"),
raw_user_jwt="jwt",
chat_id="c1",
callback=callback,
)
assert answer == "无法执行"
assert registry.calls == []
finally:
await store.close()
def test_tool_events_render_one_friendly_completed_card() -> None:
assert tool_event_details("tool.started", {"name": "exec"}) is None
rendered = tool_event_details(
"tool.completed",
{
"call_id": "call-1",
"name": "exec",
"arguments": {"command": "pytest -q"},
"ok": True,
"summary": "2 passed",
},
)
assert rendered is not None
assert 'name="执行命令"' in rendered
assert "2 passed" in rendered
assert 'done="false"' not in rendered