The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: verify API Runs continuation consumers over loopback HTTP
Teknium6530eb41adbb
diff --git a/evals/api_delegation_http_probe.py b/evals/api_delegation_http_probe.pyindex af4f54717a2..4158287de71 100644--- a/evals/api_delegation_http_probe.py+++ b/evals/api_delegation_http_probe.py@@ -51,7 +51,9 @@ async def probe():adapter._create_agent = create_agentapp = web.Application()app.router.add_post("/v1/chat/completions", adapter._handle_chat_completions)+ app.router.add_post("/v1/runs", adapter._handle_runs)records = []+ runs = []async with TestClient(TestServer(app)) as client:for stream in (False, True):for explicit in (False, True):@@ -71,7 +73,27 @@ async def probe():calls_after = len(captured)response = await client.post("/v1/chat/completions", headers={"Authorization": "Bearer fixture-api-key", "X-Hermes-Session-Id": "parent"}, json={"messages": [{"role": "user", "content": "read result"}]})await response.read()- result = {"requests": records, "delivery_error": delivery_error, "unsolicited_calls": calls_after-calls_before, "resumed_history": captured[-1]["history"], "durable_child_rows": len(db.get_messages("child"))}+ resumed_history = captured[-1]["history"]+ snapshot = [{"role": "user", "content": "caller snapshot"}]+ adapter._response_store.put("resp-seed", {"conversation_history": snapshot, "session_id": "parent"})+ db.create_session("declared", source="api_server", session_key="fixture-key")+ db.append_message("declared", "assistant", "DECLARED_HISTORY")+ for name, body, extra_headers in (+ ("session", {"session_id": "parent"}, {}),+ ("caller_history", {"session_id": "parent", "conversation_history": snapshot}, {}),+ ("response_chain", {"previous_response_id": "resp-seed"}, {}),+ ("declared_key", {}, {"X-Hermes-Session-Key": "fixture-key"}),+ ):+ count = len(captured)+ response = await client.post("/v1/runs", headers={"Authorization": "Bearer fixture-api-key", **extra_headers}, json={"input": "continue", **body})+ await response.read()+ async def wait_for_run():+ while len(captured) == count:+ await asyncio.sleep(0.01)+ if response.status == 202:+ await asyncio.wait_for(wait_for_run(), 10)+ runs.append({"name": name, "status": response.status, "runtime": captured[-1] if len(captured) > count else None})+ result = {"requests": records, "runs": runs, "delivery_error": delivery_error, "unsolicited_calls": calls_after-calls_before, "resumed_history": resumed_history, "durable_child_rows": len(db.get_messages("child"))}db.close()return resultdiff --git a/tests/gateway/test_api_delegation_delivery_contract.py b/tests/gateway/test_api_delegation_delivery_contract.pyindex b77d75baf26..6ada9a64427 100644--- a/tests/gateway/test_api_delegation_delivery_contract.py+++ b/tests/gateway/test_api_delegation_delivery_contract.py@@ -41,6 +41,15 @@ async def test_detached_dispatch_requires_a_declared_consumer(monkeypatch):assert result["unsolicited_calls"] == 0assert result["durable_child_rows"] == 1assert sum(m["content"] == "DELIVERY_RESULT" for m in result["resumed_history"]) == 1+ runs = {r["name"]: r for r in result["runs"]}+ assert all(r["status"] == 202 for r in runs.values())+ for name in ("caller_history", "response_chain"):+ assert runs[name]["runtime"]["target"] is None+ assert runs[name]["runtime"]["history"] == [{"role": "user", "content": "caller snapshot"}]+ assert runs["session"]["runtime"]["target"] == "child"+ assert runs["session"]["runtime"]["history"] == result["resumed_history"]+ assert runs["declared_key"]["runtime"]["target"] == "declared"+ assert runs["declared_key"]["runtime"]["history"][0]["content"] == "DECLARED_HISTORY"@pytest.mark.asyncio