Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/agent_env/a2a_agent/clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ async def follow(agent: DeployedAgent, env: DeployedEnv, *, env_get_time_url: Op
url = (agent.a2a_url or agent.api_url).rstrip("/") + path
try:
async with httpx.AsyncClient() as client:
answer = await client.post(url, json=body, timeout=timeout, headers=sandbox_request_headers_for_url(url))
answer = await client.post(url, json=body, timeout=timeout,
headers={**sandbox_request_headers_for_url(url), **agent.control_headers})
except httpx.HTTPError as e:
why = f"({type(e).__name__}): {e}"
else:
Expand Down
6 changes: 5 additions & 1 deletion tst/unit/task_step/agent_clock_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from types import SimpleNamespace

import pytest
from agentenv_protocol import CONTROL_TOKEN_HEADER

from agent_env.env.gateway.constants import EXT_CLOCK_URI
from agent_env.task_step.context import DeployedAgent, StepContextError, TaskStepContext
Expand All @@ -16,14 +17,16 @@
_step)

AGENT_URL = "http://solver:8000"
AGENT_CONTROL_TOKEN = "the-agents-control-token"
SYNC_TIME = {"method": "POST", "endpoint": "/ext/clock/sync-time",
"request": {"required": ["env_get_time_url"], "optional": ["timezone", "watch_url", "name", "read_token"]}}


def _agent(name="solver", sync_time=SYNC_TIME, env_ids=("e1",)) -> DeployedAgent:
extensions = [{"uri": EXT_CLOCK_URI, "params": {"endpoint": "/ext/clock", "methods": {"sync_time": sync_time}}}]
return DeployedAgent(agent_name=name, api_url=AGENT_URL, a2a_url=AGENT_URL, env_ids=list(env_ids),
a2a_card={"capabilities": {"extensions": extensions if sync_time else []}})
a2a_card={"capabilities": {"extensions": extensions if sync_time else []}},
control_token=AGENT_CONTROL_TOKEN)


async def _context(*agents) -> TaskStepContext:
Expand All @@ -49,6 +52,7 @@ async def test_an_agent_is_declared_a_follower_then_handed_its_config_with_the_s
declared, synced = sent[3], sent[4]
assert (declared.method, str(declared.url)) == ("PUT", f"{_CARD}/clock/followers")
assert (synced.method, str(synced.url)) == ("POST", f"{AGENT_URL}/ext/clock/sync-time")
assert synced.headers[CONTROL_TOKEN_HEADER] == AGENT_CONTROL_TOKEN
declaration, config = json.loads(declared.content), json.loads(synced.content)
assert declaration == {"name": "agent-solver", "read_token": config["read_token"]} and len(config["read_token"]) > 30
assert config == {"env_get_time_url": CLOCK_URL, "watch_url": "http://gw/clock/watch", "name": "agent-solver",
Expand Down
Loading