Repository navigation
fix(task-steps): a run-wide agent pick of another agent no longer takes the step's pinned version #842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cikowski
wants to merge
2
commits into
main
Choose a base branch
from
fix/agent-override-version
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix(task-steps): a run-wide agent pick of another agent no longer takes the step's pinned version #842
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,121 @@ | ||
| """A run-wide agent pick (``user_overrides.a2a_agent_id``: ``task run --a2a-agent-id``, a hub run's agent pick) reaches | ||
| every ``deploy_agent`` and ``install_agent`` step, a ``prompt_agent`` task's user agent included, exactly as on main. | ||
| A ``deploy_user_sim_agent`` step keeps its own agent through its own ``_resolve_agent_ref``, not anything these steps | ||
| read.""" | ||
| every ``deploy_agent`` and ``install_agent`` step, a ``prompt_agent`` task's user agent included. A step's pinned | ||
| version belongs to the agent the step names, so a pick of another agent never takes it. Each case runs the step and | ||
| reads what it asks the agent store for. A ``deploy_user_sim_agent`` step keeps its own agent through its own | ||
| ``_resolve_agent_ref``, not anything these steps read.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from agent_env.task_step.context import TaskStepContext | ||
| import asyncio | ||
| from types import SimpleNamespace | ||
|
|
||
| import pytest | ||
|
|
||
| from agent_env.a2a_agent import A2AAgent | ||
| from agent_env.config import ConfigError, get_config, reset_config | ||
| from agent_env.providers.sandbox_providers import sandbox_provider | ||
| from agent_env.task_step.context import DeployedSandbox, TaskStepContext | ||
| from agent_env.task_step.task_steps.deploy_agent import DeployAgentTaskStep | ||
| from agent_env.task_step.task_steps.install_agent import InstallAgentTaskStep | ||
|
|
||
| SOLVER = {"id": "deploy-solver", "type": "deploy_agent", "env_ids": [], "agent_name": "solver", | ||
| "a2a_agent_id": "theirs", "a2a_agent_version": 4} | ||
| HUMAN = {"id": "deploy-human", "type": "deploy_agent", "env_ids": [], "agent_name": "human_agent", | ||
| "a2a_agent_id": "sim", "a2a_agent_version": 2} | ||
| INSTALL = {"id": "install-human", "type": "install_agent", "agent_name": "human_agent", "a2a_agent_id": "sim", | ||
| "a2a_agent_version": 2, "sandbox_name": "world"} | ||
| UNNAMED = {"id": "deploy-default", "type": "deploy_agent", "env_ids": [], "agent_name": "solver", | ||
| "a2a_agent_version": 6} | ||
| UNNAMED_INSTALL = {"id": "install-default", "type": "install_agent", "agent_name": "solver", "a2a_agent_version": 6, | ||
| "sandbox_name": "world"} | ||
|
|
||
|
|
||
| class _Asked(Exception): | ||
| pass | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def asked(monkeypatch, local_stores) -> list: | ||
| """Each (id, version) a step asks the agent store for; the step stops there.""" | ||
| asked: list = [] | ||
|
|
||
| def get(agent_id, version=None): | ||
| asked.append((agent_id, version)) | ||
| raise _Asked | ||
|
|
||
| monkeypatch.setattr(A2AAgent, "get", staticmethod(get)) | ||
| monkeypatch.setattr(sandbox_provider, "build_sandbox_provider", lambda name: SimpleNamespace( | ||
| get_sandbox=lambda sandbox_id: asyncio.sleep(0, result=SimpleNamespace()))) | ||
| return asked | ||
|
|
||
|
|
||
| async def _run(step_dict: dict, asked: list, **overrides) -> tuple: | ||
| step_class = InstallAgentTaskStep if step_dict["type"] == "install_agent" else DeployAgentTaskStep | ||
| context = TaskStepContext(instance_id="run-1", metadata={"user_overrides": overrides}, deployed_sandboxes=[ | ||
| DeployedSandbox(sandbox_name="world", sandbox_id="sb-1", sandbox_mode="vm", sandbox_type="local", | ||
| tunnel_urls={"8000": "http://127.0.0.1:8000"})]) | ||
| with pytest.raises(_Asked): | ||
| await step_class.from_dict(step_dict).execute(context) | ||
| return asked[-1] | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.parametrize("step", [SOLVER, HUMAN, INSTALL], ids=lambda step: step["id"]) | ||
| async def test_a_step_with_no_pick_keeps_its_agent_and_pin(asked, step): | ||
| assert await _run(step, asked) == (step["a2a_agent_id"], step["a2a_agent_version"]) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.parametrize("step", [SOLVER, HUMAN, INSTALL], ids=lambda step: step["id"]) | ||
| async def test_a_pick_of_another_agent_does_not_take_the_steps_pinned_version(asked, step): | ||
| assert await _run(step, asked, a2a_agent_id="mine") == ("mine", None) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.parametrize("step", [SOLVER, HUMAN, INSTALL], ids=lambda step: step["id"]) | ||
| async def test_a_pick_of_another_agent_with_a_version_deploys_that_version(asked, step): | ||
| assert await _run(step, asked, a2a_agent_id="mine", a2a_agent_version=9) == ("mine", 9) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.parametrize("step", [SOLVER, HUMAN, INSTALL], ids=lambda step: step["id"]) | ||
| async def test_a_pick_of_the_steps_own_agent_keeps_its_pin(asked, step): | ||
| assert await _run(step, asked, a2a_agent_id=step["a2a_agent_id"]) == (step["a2a_agent_id"], step["a2a_agent_version"]) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.parametrize("step", [UNNAMED, UNNAMED_INSTALL], ids=lambda step: step["id"]) | ||
| async def test_a_step_naming_no_agent_keeps_its_pin_only_for_the_default_agent(asked, local_stores, step): | ||
| default = local_stores.get_default_a2a_agent_id() | ||
| assert await _run(step, asked) == (default, 6) | ||
| assert await _run(step, asked, a2a_agent_id=default) == (default, 6) | ||
| assert await _run(step, asked, a2a_agent_id="mine") == ("mine", None) | ||
|
|
||
| def _picked(**overrides) -> TaskStepContext: | ||
| return TaskStepContext(instance_id="run-1", metadata={"user_overrides": {"a2a_agent_id": "mine", **overrides}}) | ||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.parametrize("step", [UNNAMED, UNNAMED_INSTALL], ids=lambda step: step["id"]) | ||
| async def test_a_pick_runs_where_the_default_agent_cannot_be_read(asked, tmp_path, monkeypatch, step): | ||
| config = tmp_path / "config.toml" | ||
| config.write_text('[agents]\ndefault_a2a_agent_id = "env:AGENT_ENV_TEST_UNSET_DEFAULT_AGENT"\n') | ||
| monkeypatch.delenv("AGENT_ENV_TEST_UNSET_DEFAULT_AGENT", raising=False) | ||
| monkeypatch.setenv("AGENT_ENV_CONFIG", str(config)) | ||
| reset_config() | ||
| with pytest.raises(ConfigError): | ||
| get_config().get_default_a2a_agent_id() | ||
|
|
||
| def test_the_pick_reaches_a_prompt_agent_tasks_user_agent_too_at_each_steps_stored_version(): | ||
| ctx = _picked() | ||
| assert DeployAgentTaskStep.from_dict(SOLVER)._resolve_agent_ref(ctx) == ("mine", 4) | ||
| assert DeployAgentTaskStep.from_dict(HUMAN)._resolve_agent_ref(ctx) == ("mine", 2) | ||
| assert await _run(step, asked, a2a_agent_id="mine") == ("mine", None) | ||
| assert await _run(step, asked, a2a_agent_id="mine", a2a_agent_version=9) == ("mine", 9) | ||
|
|
||
|
|
||
| def test_a_picked_version_applies_to_every_deploy(): | ||
| ctx = _picked(a2a_agent_version=9) | ||
| assert DeployAgentTaskStep.from_dict(SOLVER)._resolve_agent_ref(ctx) == ("mine", 9) | ||
| assert DeployAgentTaskStep.from_dict(HUMAN)._resolve_agent_ref(ctx) == ("mine", 9) | ||
| @pytest.mark.asyncio | ||
| async def test_a_picked_version_alone_applies_to_every_deploy_and_no_install(asked): | ||
| assert await _run(SOLVER, asked, a2a_agent_version=9) == ("theirs", 9) | ||
| assert await _run(HUMAN, asked, a2a_agent_version=9) == ("sim", 9) | ||
| assert await _run(INSTALL, asked, a2a_agent_version=9) == ("sim", 2) | ||
|
|
||
|
|
||
| def test_install_agent_takes_the_pick_at_its_stored_version(): | ||
| installed = InstallAgentTaskStep.from_dict({"id": "install-human", "type": "install_agent", | ||
| "agent_name": "human_agent", "a2a_agent_id": "sim", | ||
| "a2a_agent_version": 2, "sandbox_name": "world"}) | ||
| assert installed._agent_ref(_picked()) == ("mine", 2) | ||
| @pytest.mark.asyncio | ||
| async def test_a_steps_own_version_override_wins_over_the_pick(asked): | ||
| step_params = {"deploy-solver": {"a2a_agent_version": 5}} | ||
| assert await _run(SOLVER, asked, a2a_agent_id="mine", step_params=step_params) == ("mine", 5) | ||
| assert await _run(SOLVER, asked, a2a_agent_id="mine", a2a_agent_version=9, step_params=step_params) == ("mine", 5) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This help names "the run's a2a_agent_version", but
task runhas no flag that sets it: line 422 only writesuser_overrides["a2a_agent_id"]. So after this PR,task run --a2a-agent-id mineon a task pinned totheirsv4 always getsmineat latest, resolved separately in each step, and the only way to pin it is a hand-written--context-json. Could you add--a2a-agent-versionnext to--a2a-agent-id(written intouser_overrides), or say "latest; pin via --context-json user_overrides.a2a_agent_version" in the help?