agentenv-framework-protocol 0.1.603__tar.gz → 0.1.606__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/PKG-INFO +72 -2
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/README.md +71 -1
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/pyproject.toml +1 -1
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/a2a_agent/__init__.py +8 -0
- agentenv_framework_protocol-0.1.606/src/agentenv_protocol/a2a_agent/_atif_copy.py +267 -0
- agentenv_framework_protocol-0.1.606/src/agentenv_protocol/a2a_agent/_snapshot_state.py +124 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/a2a_agent/_trajectory_log.py +153 -19
- agentenv_framework_protocol-0.1.606/src/agentenv_protocol/a2a_agent/_turn_index.py +78 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/a2a_agent/extensions.py +75 -6
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/a2a_agent/framework.py +171 -13
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/a2a_agent/tasks/v1.py +37 -3
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/PROFILE.md +17 -5
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/__init__.py +11 -8
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/builder.py +99 -24
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/profile.py +8 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/runner.py +50 -14
- agentenv_framework_protocol-0.1.606/src/agentenv_protocol/atif/served.py +114 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/clock.py +18 -0
- agentenv_framework_protocol-0.1.606/tests/conftest.py +8 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_a2a_agent_clock.py +16 -0
- agentenv_framework_protocol-0.1.606/tests/test_a2a_atif_serving.py +647 -0
- agentenv_framework_protocol-0.1.606/tests/test_a2a_atif_turns.py +313 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_atif_builder.py +118 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/.gitignore +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/LICENSE +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/NOTICE +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/THIRD_PARTY_NOTICES.md +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/advanced_agent.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/basic_agent.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/custom_extensions_agent.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/multimodal_agent.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/reference_model.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/streaming_agent.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/website/notes/.gitignore +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/website/notes/Dockerfile +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/website/notes/Dockerfile.dockerignore +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/website/notes/README.md +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/website/notes/data/seed.json +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/website/notes/env.toml +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/website/notes/site.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/website/notes/web/index.html +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/website/notes/web/package-lock.json +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/website/notes/web/package.json +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/website/notes/web/src/main.js +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/website/notes/web/src/style.css +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/examples/website/notes/web/vite.config.js +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/a2a_agent/_triggers.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/a2a_agent/clock.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/a2a_agent/control_token.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/a2a_agent/peer_agents.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/a2a_agent/proxy.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/a2a_agent/registry.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/a2a_agent/staging.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/a2a_agent/tasks/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/agent_env_environment.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/__main__.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/adapter.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/fixtures/coding.json +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/fixtures/coding.stripped.json +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/fixtures/computer_use.json +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/fixtures/late_result.json +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/fixtures/media/482405b002a62efa8516c36709a7a100637507670576fa73a20ad5420d55c66f.png +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/fixtures/media/55c64d0fcd6f9d5f7c828093857e3fdfda68478bb4e9bd24d481ef391c7804e8.heic +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/fixtures/media/67905ad3cc2dd52b1f5f6a6d2814de0396618b29b4238b9af5207aeb69936e6d.mp4 +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/fixtures/media/69a8aa01fe5537076d023dd5e9cc4275b39fc0434aa6483a9f58b66ef2f3c896.png +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/fixtures/media/82e60066a2de261b6653bcdda90d1cb9a7af2f474cecd82e8d371e8384d72315.png +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/fixtures/media/845e91831319e89c4d656bdb80c278ac09a7230d61e5dfd2e1b1fbb436ac8917.pdf +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/fixtures/multi_agent.json +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/fixtures/odd_parts.json +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/fixtures/subagent.json +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/fixtures/two_turns.json +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/kit.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/models/LICENSE +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/models/VENDORED.md +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/models/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/models/agent.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/models/content.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/models/final_metrics.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/models/metrics.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/models/observation.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/models/observation_result.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/models/step.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/models/subagent_trajectory_ref.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/models/tool_call.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/models/trajectory.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/reader.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/atif/validator.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/client.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/_declare.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/_desktop.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/_job.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/_linux.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/_load.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/_macos.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/_reaping.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/_session_posix.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/_session_windows.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/_windows.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/_with_fds.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/_x11.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/app.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/app_data.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/app_runtime.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/apps.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/card.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/checks.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/conformance/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/conformance/__main__.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/conformance/checks.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/conformance/client.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/conformance/desk.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/conformance/fixture.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/conformance/mp4.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/conformance/page_fixture.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/conformance/report.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/conformance/wayland_fixture.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/dataplane.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/driver.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/errors.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/extensions.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/frames.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/keys.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/launch.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/manifest.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/operations.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/platform.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/prefix.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/queue.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/recording.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/results.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/run_install_step.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/runtime.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/seed.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/serve.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/serve_app.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/served.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/session.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/settings.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/skill.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/spaces.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/svc.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/computer/tools.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/errors.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/manifest.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/passthrough.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/preflight.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/tool_access.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/tool_client.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/tool_context.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/transfers.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/types.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website/clock.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website/conformance.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website/environment.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website/errors.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website/forwarding.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website/readiness.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website/routes.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website/session.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website_browser/__init__.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website_browser/cdp.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website_browser/contexts.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website_browser/control.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website_browser/data.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website_browser/devtools.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website_browser/environment.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website_browser/log.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website_browser/network.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website_browser/recording.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website_browser/scope.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website_browser/shapes.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/src/agentenv_protocol/website_browser/stream.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/atif_cases.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/computer_fake.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/probe_fake.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_a2a_agent.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_a2a_agent_examples.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_a2a_cdp_config.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_a2a_object_transfers.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_a2a_peer_agents.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_a2a_proxy.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_a2a_staging.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_a2a_trajectory_log.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_agent_env_environment.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_atif_fixtures.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_atif_kit.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_atif_profile.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_atif_reader.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_atif_validator.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_atif_vendored.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_browser_cdp.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_browser_contexts.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_browser_data.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_browser_log.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_browser_network.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_browser_recording.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_browser_state.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_client.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_app_data.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_app_server.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_clock.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_conformance.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_conformance_attempts.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_conformance_checks.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_conformance_page.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_conformance_recording.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_dataplane.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_declare.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_driver.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_driver_keys.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_extensions.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_frames.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_macos.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_page.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_queue.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_recording.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_seed.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_serve.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_served.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_session_windows.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_spaces.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_svc_forward.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_tool_prefix.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_computer_windows_driver.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_control_token.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_data_objects.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_devtools_pipe.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_errors.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_extension_methods.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_intake.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_manifest.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_preflight.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_tool_access.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_tool_annotations.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_tool_client.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_tool_context.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_tool_context_fastmcp.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_tool_context_injection.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_usage.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_website_api.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_website_browser.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_website_conformance.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_website_environment.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_website_forwarding.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_website_live.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_website_mcp.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_website_notes_example.py +0 -0
- {agentenv_framework_protocol-0.1.603 → agentenv_framework_protocol-0.1.606}/tests/test_website_readiness.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: agentenv-framework-protocol
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.606
|
|
4
4
|
Summary: Open data-plane protocol and server SDK for agent environments.
|
|
5
5
|
Project-URL: Homepage, https://www.agentenvframework.com
|
|
6
6
|
Project-URL: Documentation, https://www.agentenvframework.com/docs
|
|
@@ -1669,6 +1669,74 @@ the most recent format its tasks set. Readers trust a response's `format` over
|
|
|
1669
1669
|
the card. An agent that binds its own context reads should name, in their
|
|
1670
1670
|
responses, the format it serves.
|
|
1671
1671
|
|
|
1672
|
+
#### Serving ATIF (`atif/1`)
|
|
1673
|
+
|
|
1674
|
+
`atif` names the agent's ATIF adapter, an `@atif_adapter` class from
|
|
1675
|
+
`agentenv_protocol.atif` that reads the `native` format:
|
|
1676
|
+
|
|
1677
|
+
```python
|
|
1678
|
+
enable(TRAJECTORY_V1, live=True, native="my-cli-events/1", atif=MyCliAtif)
|
|
1679
|
+
```
|
|
1680
|
+
|
|
1681
|
+
The card then lists `atif/1` in `formats` too; `default` stays `native`. The
|
|
1682
|
+
SDK keeps one ATIF document per A2A context, run through one adapter instance,
|
|
1683
|
+
and feeds it every event the agent appends, as it appends it. A native
|
|
1684
|
+
trajectory returned at task end runs through the adapter then. The agent's own
|
|
1685
|
+
code feeds the adapter's aux files, records that aren't in the native log such
|
|
1686
|
+
as a hook's notes, with `request.trajectory.aux(name, record)`, where they
|
|
1687
|
+
happened among the events. An agent with an adapter that both appends events and
|
|
1688
|
+
returns a native trajectory fails the turn with code
|
|
1689
|
+
`framework.trajectory_appended_and_returned`, since its ATIF copy would come
|
|
1690
|
+
from one of them and its native record from the other.
|
|
1691
|
+
|
|
1692
|
+
The SDK writes each task's user step from the inbound message and its final
|
|
1693
|
+
response from the result, both as [PROFILE.md](src/agentenv_protocol/atif/PROFILE.md)
|
|
1694
|
+
says, stamped on the clock the agent's programs read: the universe's when the
|
|
1695
|
+
agent follows the env's clock, though the server itself stays on real time. `session_id` is the A2A context id, and `trajectory_id` names the document.
|
|
1696
|
+
Reads naming `atif/1` are served by the SDK, context reads an agent binds
|
|
1697
|
+
included:
|
|
1698
|
+
|
|
1699
|
+
- A task read returns the context's document as it stood when the task ended,
|
|
1700
|
+
with `aux`, the task's aux log (each record with `after`, the number of events
|
|
1701
|
+
before it), and `turn_context`, its TurnContext and how it ended: an
|
|
1702
|
+
`AuxEntry` each and a `ServedTurn`, both in `agentenv_protocol.atif`. With
|
|
1703
|
+
those and the native events, `RecordedTask.from_served` and `replay` rebuild
|
|
1704
|
+
the document offline. In the objects form, `aux` and `turn_context` are optional
|
|
1705
|
+
grants beside `trajectory`, uploaded only when given; other reads refuse them.
|
|
1706
|
+
- A context read returns the live page: every step that has closed and whose
|
|
1707
|
+
calls are all answered, up to the first that isn't.
|
|
1708
|
+
- A cursor read pages those closed steps by `step_id`: `after` is the last
|
|
1709
|
+
`step_id` read, and `next` is the last one served. Each page carries `header`,
|
|
1710
|
+
the document's root without its steps (with `final_metrics` once no task is
|
|
1711
|
+
open), and `subagents`, the embedded
|
|
1712
|
+
sub-agent trajectories of the tasks its steps belong to, as far as each is
|
|
1713
|
+
served. A sub-agent can gain steps while its task runs, so keep each one's
|
|
1714
|
+
latest copy; the page that serves a task's last step, which closes only as the
|
|
1715
|
+
task ends, carries them whole.
|
|
1716
|
+
|
|
1717
|
+
Every `atif/1` answer names `schema_version` and `profile_version` beside
|
|
1718
|
+
`format`. An adapter that raises stops its context's copy, never the turn: the
|
|
1719
|
+
copy's reads then answer HTTP 409 with code `atif_unavailable`, and native reads
|
|
1720
|
+
are unaffected.
|
|
1721
|
+
|
|
1722
|
+
Each task's user step carries its turn index, the number of tasks its context
|
|
1723
|
+
started before it. The SDK keeps each context's count on disk, under
|
|
1724
|
+
`agentenv/turns/` in the user's state folder (`$XDG_STATE_HOME`, else
|
|
1725
|
+
`~/.local/state`), so a restarted server, or a context it dropped
|
|
1726
|
+
from memory, goes on counting in a new document of the same session; a home it
|
|
1727
|
+
can't write keeps the counts in memory, with one warning. A snapshot carries the
|
|
1728
|
+
count in its `state` object, a JSON object that is the SDK's own: on save the
|
|
1729
|
+
SDK uploads it after the agent's handler returns and adds it to the answer, and
|
|
1730
|
+
on load it reads it before the agent's handler runs and seeds the context the
|
|
1731
|
+
handler restored into, whose next task goes on from the snapshot's count in a
|
|
1732
|
+
new document. While such a save or load is in flight, a task of its context
|
|
1733
|
+
waits to start until the agent's handler returns, so the count is the
|
|
1734
|
+
conversation's the agent captured; a task already running goes on, as a capture
|
|
1735
|
+
mid-task expects. The agent's handlers leave `state` alone. The card's snapshot
|
|
1736
|
+
extension names the state the SDK keeps (`"state": ["turns"]` in its params,
|
|
1737
|
+
`SNAPSHOT_STATE_PARAM`), and agent-env grants the object only to an agent whose
|
|
1738
|
+
card has it, since an SDK from before it refuses the object.
|
|
1739
|
+
|
|
1672
1740
|
`enable(..., description="...")` is reserved for declarations carrying
|
|
1673
1741
|
configuration or metadata. It preserves the agent-specific extension prose
|
|
1674
1742
|
published in the Agent Card. The versioned SDK definition provides a generic
|
|
@@ -1804,7 +1872,9 @@ counterpart. Without them, or `enable(TRAJECTORY_V1, live=True)`, the
|
|
|
1804
1872
|
generated card advertises only the framework-owned completed-task variants:
|
|
1805
1873
|
`{task_id}`, answered inline, and `{task_id, objects}`, answered by upload.
|
|
1806
1874
|
Snapshot `save` and `load` are an atomic core contract, while its optional
|
|
1807
|
-
changelog handlers are enabled as an atomic feature group.
|
|
1875
|
+
changelog handlers are enabled as an atomic feature group. A snapshot's optional
|
|
1876
|
+
`state` object is the SDK's own, which its handlers leave alone (see
|
|
1877
|
+
[Serving ATIF](#serving-atif-atif1)).
|
|
1808
1878
|
Each operation has at most one response model. The framework validates a
|
|
1809
1879
|
handler's return value against it before serializing, so a response with a
|
|
1810
1880
|
missing or unknown field is an HTTP 500.
|
|
@@ -1598,6 +1598,74 @@ the most recent format its tasks set. Readers trust a response's `format` over
|
|
|
1598
1598
|
the card. An agent that binds its own context reads should name, in their
|
|
1599
1599
|
responses, the format it serves.
|
|
1600
1600
|
|
|
1601
|
+
#### Serving ATIF (`atif/1`)
|
|
1602
|
+
|
|
1603
|
+
`atif` names the agent's ATIF adapter, an `@atif_adapter` class from
|
|
1604
|
+
`agentenv_protocol.atif` that reads the `native` format:
|
|
1605
|
+
|
|
1606
|
+
```python
|
|
1607
|
+
enable(TRAJECTORY_V1, live=True, native="my-cli-events/1", atif=MyCliAtif)
|
|
1608
|
+
```
|
|
1609
|
+
|
|
1610
|
+
The card then lists `atif/1` in `formats` too; `default` stays `native`. The
|
|
1611
|
+
SDK keeps one ATIF document per A2A context, run through one adapter instance,
|
|
1612
|
+
and feeds it every event the agent appends, as it appends it. A native
|
|
1613
|
+
trajectory returned at task end runs through the adapter then. The agent's own
|
|
1614
|
+
code feeds the adapter's aux files, records that aren't in the native log such
|
|
1615
|
+
as a hook's notes, with `request.trajectory.aux(name, record)`, where they
|
|
1616
|
+
happened among the events. An agent with an adapter that both appends events and
|
|
1617
|
+
returns a native trajectory fails the turn with code
|
|
1618
|
+
`framework.trajectory_appended_and_returned`, since its ATIF copy would come
|
|
1619
|
+
from one of them and its native record from the other.
|
|
1620
|
+
|
|
1621
|
+
The SDK writes each task's user step from the inbound message and its final
|
|
1622
|
+
response from the result, both as [PROFILE.md](src/agentenv_protocol/atif/PROFILE.md)
|
|
1623
|
+
says, stamped on the clock the agent's programs read: the universe's when the
|
|
1624
|
+
agent follows the env's clock, though the server itself stays on real time. `session_id` is the A2A context id, and `trajectory_id` names the document.
|
|
1625
|
+
Reads naming `atif/1` are served by the SDK, context reads an agent binds
|
|
1626
|
+
included:
|
|
1627
|
+
|
|
1628
|
+
- A task read returns the context's document as it stood when the task ended,
|
|
1629
|
+
with `aux`, the task's aux log (each record with `after`, the number of events
|
|
1630
|
+
before it), and `turn_context`, its TurnContext and how it ended: an
|
|
1631
|
+
`AuxEntry` each and a `ServedTurn`, both in `agentenv_protocol.atif`. With
|
|
1632
|
+
those and the native events, `RecordedTask.from_served` and `replay` rebuild
|
|
1633
|
+
the document offline. In the objects form, `aux` and `turn_context` are optional
|
|
1634
|
+
grants beside `trajectory`, uploaded only when given; other reads refuse them.
|
|
1635
|
+
- A context read returns the live page: every step that has closed and whose
|
|
1636
|
+
calls are all answered, up to the first that isn't.
|
|
1637
|
+
- A cursor read pages those closed steps by `step_id`: `after` is the last
|
|
1638
|
+
`step_id` read, and `next` is the last one served. Each page carries `header`,
|
|
1639
|
+
the document's root without its steps (with `final_metrics` once no task is
|
|
1640
|
+
open), and `subagents`, the embedded
|
|
1641
|
+
sub-agent trajectories of the tasks its steps belong to, as far as each is
|
|
1642
|
+
served. A sub-agent can gain steps while its task runs, so keep each one's
|
|
1643
|
+
latest copy; the page that serves a task's last step, which closes only as the
|
|
1644
|
+
task ends, carries them whole.
|
|
1645
|
+
|
|
1646
|
+
Every `atif/1` answer names `schema_version` and `profile_version` beside
|
|
1647
|
+
`format`. An adapter that raises stops its context's copy, never the turn: the
|
|
1648
|
+
copy's reads then answer HTTP 409 with code `atif_unavailable`, and native reads
|
|
1649
|
+
are unaffected.
|
|
1650
|
+
|
|
1651
|
+
Each task's user step carries its turn index, the number of tasks its context
|
|
1652
|
+
started before it. The SDK keeps each context's count on disk, under
|
|
1653
|
+
`agentenv/turns/` in the user's state folder (`$XDG_STATE_HOME`, else
|
|
1654
|
+
`~/.local/state`), so a restarted server, or a context it dropped
|
|
1655
|
+
from memory, goes on counting in a new document of the same session; a home it
|
|
1656
|
+
can't write keeps the counts in memory, with one warning. A snapshot carries the
|
|
1657
|
+
count in its `state` object, a JSON object that is the SDK's own: on save the
|
|
1658
|
+
SDK uploads it after the agent's handler returns and adds it to the answer, and
|
|
1659
|
+
on load it reads it before the agent's handler runs and seeds the context the
|
|
1660
|
+
handler restored into, whose next task goes on from the snapshot's count in a
|
|
1661
|
+
new document. While such a save or load is in flight, a task of its context
|
|
1662
|
+
waits to start until the agent's handler returns, so the count is the
|
|
1663
|
+
conversation's the agent captured; a task already running goes on, as a capture
|
|
1664
|
+
mid-task expects. The agent's handlers leave `state` alone. The card's snapshot
|
|
1665
|
+
extension names the state the SDK keeps (`"state": ["turns"]` in its params,
|
|
1666
|
+
`SNAPSHOT_STATE_PARAM`), and agent-env grants the object only to an agent whose
|
|
1667
|
+
card has it, since an SDK from before it refuses the object.
|
|
1668
|
+
|
|
1601
1669
|
`enable(..., description="...")` is reserved for declarations carrying
|
|
1602
1670
|
configuration or metadata. It preserves the agent-specific extension prose
|
|
1603
1671
|
published in the Agent Card. The versioned SDK definition provides a generic
|
|
@@ -1733,7 +1801,9 @@ counterpart. Without them, or `enable(TRAJECTORY_V1, live=True)`, the
|
|
|
1733
1801
|
generated card advertises only the framework-owned completed-task variants:
|
|
1734
1802
|
`{task_id}`, answered inline, and `{task_id, objects}`, answered by upload.
|
|
1735
1803
|
Snapshot `save` and `load` are an atomic core contract, while its optional
|
|
1736
|
-
changelog handlers are enabled as an atomic feature group.
|
|
1804
|
+
changelog handlers are enabled as an atomic feature group. A snapshot's optional
|
|
1805
|
+
`state` object is the SDK's own, which its handlers leave alone (see
|
|
1806
|
+
[Serving ATIF](#serving-atif-atif1)).
|
|
1737
1807
|
Each operation has at most one response model. The framework validates a
|
|
1738
1808
|
handler's return value against it before serializing, so a response with a
|
|
1739
1809
|
missing or unknown field is an HTTP 500.
|
|
@@ -78,6 +78,9 @@ from .extensions import (
|
|
|
78
78
|
TaskTrajectoryRequest,
|
|
79
79
|
TrajectoryEventsResponse,
|
|
80
80
|
TrajectoryObjectsResponse,
|
|
81
|
+
AtifEventsResponse,
|
|
82
|
+
AtifObjectsResponse,
|
|
83
|
+
AtifUploadedObjects,
|
|
81
84
|
TrajectoryState,
|
|
82
85
|
TrajectoryUploadedObjects,
|
|
83
86
|
TrajectoryWriteObjects,
|
|
@@ -90,6 +93,7 @@ from .extensions import (
|
|
|
90
93
|
request_fields,
|
|
91
94
|
)
|
|
92
95
|
from .control_token import ControlTokenMiddleware
|
|
96
|
+
from ._snapshot_state import SNAPSHOT_STATE_PARAM
|
|
93
97
|
from .framework import (
|
|
94
98
|
A2AAgentApplication,
|
|
95
99
|
AgentEnvAgent,
|
|
@@ -150,6 +154,7 @@ __all__ = [
|
|
|
150
154
|
"PEER_AGENTS_V1",
|
|
151
155
|
"REPORTED_USAGE_KEY",
|
|
152
156
|
"SKILL_CONFIG_V1",
|
|
157
|
+
"SNAPSHOT_STATE_PARAM",
|
|
153
158
|
"SNAPSHOT_V1",
|
|
154
159
|
"STAGING_ENDPOINT",
|
|
155
160
|
"STAGING_V1_URI",
|
|
@@ -247,6 +252,9 @@ __all__ = [
|
|
|
247
252
|
"TaskTrajectoryRequest",
|
|
248
253
|
"TextPart",
|
|
249
254
|
"TrajectoryEventsResponse",
|
|
255
|
+
"AtifEventsResponse",
|
|
256
|
+
"AtifObjectsResponse",
|
|
257
|
+
"AtifUploadedObjects",
|
|
250
258
|
"TrajectoryLog",
|
|
251
259
|
"TrajectoryObjectsResponse",
|
|
252
260
|
"TrajectoryState",
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"""The SDK's atif/1 copy of an A2A context: one adapter run per context, fed every native and aux record as the agent
|
|
2
|
+
writes it, and read as a task's document, the context's live page or a cursor page. An adapter that fails stops that
|
|
3
|
+
context's copy, never the agent's turn."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import base64
|
|
8
|
+
import binascii
|
|
9
|
+
import json
|
|
10
|
+
import logging
|
|
11
|
+
import threading
|
|
12
|
+
import uuid
|
|
13
|
+
from contextlib import contextmanager
|
|
14
|
+
from dataclasses import dataclass, field
|
|
15
|
+
from datetime import datetime, timezone
|
|
16
|
+
from typing import Any, Iterable, Iterator, Sequence
|
|
17
|
+
from urllib.parse import urlsplit, urlunsplit
|
|
18
|
+
|
|
19
|
+
from ..atif import FORMAT, Adapter, AdapterRun, AuxEntry, Media, ServedTurn, TurnContext
|
|
20
|
+
from ..computer import clock as follower
|
|
21
|
+
from ..errors import AgentEnvError
|
|
22
|
+
from . import clock as agent_clock
|
|
23
|
+
from .tasks.v1 import DataPart, FilePart, TaskError, TextPart, _thaw
|
|
24
|
+
|
|
25
|
+
logger = logging.getLogger(__name__)
|
|
26
|
+
|
|
27
|
+
#: The DataPart key ``add_structured_output`` writes: its value is the task's answer, so it is written as text.
|
|
28
|
+
STRUCTURED_OUTPUT = "structured_output"
|
|
29
|
+
#: How a context's copy answers once its adapter failed: the request was fine, the copy can't be served.
|
|
30
|
+
UNAVAILABLE_STATUS = 409
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
34
|
+
class TurnStart:
|
|
35
|
+
"""What the SDK knows of a task as it starts, beside its ids: the inbound message and the agent."""
|
|
36
|
+
|
|
37
|
+
message_id: str | None
|
|
38
|
+
parts: Sequence[Any]
|
|
39
|
+
agent_name: str | None
|
|
40
|
+
agent_version: str | None
|
|
41
|
+
agent_model: str | None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(slots=True)
|
|
45
|
+
class _Task:
|
|
46
|
+
place: int
|
|
47
|
+
context: TurnContext
|
|
48
|
+
natives: int = 0
|
|
49
|
+
aux: list[AuxEntry] = field(default_factory=list)
|
|
50
|
+
turn: ServedTurn | None = None
|
|
51
|
+
ended: bool = False
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass(frozen=True, slots=True)
|
|
55
|
+
class AtifPage:
|
|
56
|
+
"""A cursor page of a copy: the closed steps after ``after``, ``next`` the last one's ``step_id``, and the
|
|
57
|
+
sub-agents of their tasks."""
|
|
58
|
+
|
|
59
|
+
header: dict[str, Any] | None
|
|
60
|
+
subagents: list[dict[str, Any]]
|
|
61
|
+
steps: list[dict[str, Any]]
|
|
62
|
+
next: int
|
|
63
|
+
has_more: bool
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class AtifCopy:
|
|
67
|
+
"""One A2A context's atif/1 document. Safe to feed from the agent's thread while the loop reads it."""
|
|
68
|
+
|
|
69
|
+
def __init__(self, adapter: type[Adapter], context_id: str) -> None:
|
|
70
|
+
self._run = AdapterRun(adapter, trajectory_id=uuid.uuid4().hex)
|
|
71
|
+
self._adapter = adapter.__name__
|
|
72
|
+
self._context_id = context_id
|
|
73
|
+
self._lock = threading.Lock()
|
|
74
|
+
self._tasks: dict[str, _Task] = {}
|
|
75
|
+
self._failed: str | None = None
|
|
76
|
+
# The steps the SDK writes keep the clock the adapter's steps come from: an agent that follows the env's clock
|
|
77
|
+
# runs its programs on the universe's time, while this server stays on real time.
|
|
78
|
+
self._now = _session_now if agent_clock.follows() else _real_now
|
|
79
|
+
|
|
80
|
+
def start(self, task_id: str, index: int, turn: TurnStart) -> None:
|
|
81
|
+
with self._lock:
|
|
82
|
+
if self._failed is not None:
|
|
83
|
+
return
|
|
84
|
+
with self._guarded():
|
|
85
|
+
context = TurnContext(
|
|
86
|
+
index=index, context_id=self._context_id, task_id=task_id, message_id=turn.message_id,
|
|
87
|
+
inbound=tuple(_inbound(turn.parts, self._run)), agent_name=turn.agent_name,
|
|
88
|
+
agent_version=turn.agent_version, agent_model=turn.agent_model, started_at=self._now())
|
|
89
|
+
self._run.start_task(context)
|
|
90
|
+
self._tasks[task_id] = _Task(place=len(self._tasks), context=context)
|
|
91
|
+
|
|
92
|
+
def native(self, task_id: str, record: Any) -> None:
|
|
93
|
+
with self._lock:
|
|
94
|
+
task = self._open(task_id)
|
|
95
|
+
if task is not None:
|
|
96
|
+
with self._guarded():
|
|
97
|
+
self._feed(task, record)
|
|
98
|
+
|
|
99
|
+
def aux(self, task_id: str, name: str, record: Any) -> None:
|
|
100
|
+
with self._lock:
|
|
101
|
+
task = self._open(task_id)
|
|
102
|
+
if task is None:
|
|
103
|
+
return
|
|
104
|
+
# A copy: an adapter may change the record it's handed, and the log is replay's input.
|
|
105
|
+
task.aux.append(AuxEntry(name=name, record=json.loads(json.dumps(record)), after=task.natives))
|
|
106
|
+
with self._guarded():
|
|
107
|
+
self._run.aux(name, record)
|
|
108
|
+
|
|
109
|
+
def end(self, task_id: str, *, state: str, final: Sequence[Any] = (), error: TaskError | None = None,
|
|
110
|
+
native: Any = None) -> None:
|
|
111
|
+
"""Close the task: a native trajectory it returned instead of appending runs through the adapter first."""
|
|
112
|
+
with self._lock:
|
|
113
|
+
task = self._open(task_id)
|
|
114
|
+
if task is None:
|
|
115
|
+
return
|
|
116
|
+
with self._guarded():
|
|
117
|
+
for record in (native if isinstance(native, list) else [native]) if native is not None else ():
|
|
118
|
+
self._feed(task, record)
|
|
119
|
+
content, data = _final(final, self._run)
|
|
120
|
+
ending = {
|
|
121
|
+
"state": state, "final": content or None, "ended_at": self._now(), "data": data or None,
|
|
122
|
+
"error": None if error is None else {"kind": error.error_type, "message": error.message,
|
|
123
|
+
"code": error.code},
|
|
124
|
+
}
|
|
125
|
+
self._run.end_task(**ending)
|
|
126
|
+
task.turn = ServedTurn.of(task.context, **ending)
|
|
127
|
+
task.ended = True
|
|
128
|
+
|
|
129
|
+
def task_read(self, task_id: str) -> tuple[dict[str, Any], list[AuxEntry], ServedTurn] | None:
|
|
130
|
+
"""An ended task's document as it stood when the task ended, its aux log and its served turn context."""
|
|
131
|
+
with self._lock:
|
|
132
|
+
self._check()
|
|
133
|
+
task = self._tasks.get(task_id)
|
|
134
|
+
if task is None or task.turn is None:
|
|
135
|
+
return None
|
|
136
|
+
document = self._run.document(through=task.place)
|
|
137
|
+
assert document is not None
|
|
138
|
+
return document, list(task.aux), task.turn
|
|
139
|
+
|
|
140
|
+
def context_read(self) -> dict[str, Any] | None:
|
|
141
|
+
"""The context's live page: every closed step a reader may be served, or None before the first."""
|
|
142
|
+
with self._lock:
|
|
143
|
+
self._check()
|
|
144
|
+
return self._run.page()
|
|
145
|
+
|
|
146
|
+
def page(self, after: int, max_steps: int, max_bytes: int, *, task_id: str | None = None) -> AtifPage:
|
|
147
|
+
"""The closed steps after step ``after``, of the whole context or of task ``task_id``, within both budgets; the
|
|
148
|
+
first is always returned, so one larger than ``max_bytes`` can't stall a reader. With them, the sub-agents of
|
|
149
|
+
every task they belong to, as far as each is served: a sub-agent can gain steps while its task runs, and the
|
|
150
|
+
page that serves a task's last step, which closes only as the task ends, carries them whole."""
|
|
151
|
+
with self._lock:
|
|
152
|
+
self._check()
|
|
153
|
+
document = self._run.page()
|
|
154
|
+
by_place = {task.place: task_id for task_id, task in self._tasks.items()}
|
|
155
|
+
step_tasks = [by_place.get(place) for place in self._run.step_tasks()]
|
|
156
|
+
sub_tasks = {agent_id: by_place.get(place) for agent_id, place in self._run.subagent_tasks().items()}
|
|
157
|
+
steps = document["steps"] if document is not None else []
|
|
158
|
+
if after > len(steps):
|
|
159
|
+
raise ValueError(f"after={after} is past the document's {len(steps)} closed steps")
|
|
160
|
+
pending = [(step, owner) for step, owner in zip(steps, step_tasks)
|
|
161
|
+
if (task_id is None or owner == task_id) and step["step_id"] > after]
|
|
162
|
+
served: list[dict[str, Any]] = []
|
|
163
|
+
tasks: set[str | None] = set()
|
|
164
|
+
used = 0
|
|
165
|
+
for step, owner in pending[:max_steps]:
|
|
166
|
+
size = len(json.dumps(step))
|
|
167
|
+
if served and used + size > max_bytes:
|
|
168
|
+
break
|
|
169
|
+
served.append(step)
|
|
170
|
+
tasks.add(owner)
|
|
171
|
+
used += size
|
|
172
|
+
header = None
|
|
173
|
+
subagents: list[dict[str, Any]] = []
|
|
174
|
+
if document is not None:
|
|
175
|
+
header = {key: value for key, value in document.items() if key not in ("steps", "subagent_trajectories")}
|
|
176
|
+
subagents = [sub for sub in document.get("subagent_trajectories", [])
|
|
177
|
+
if sub_tasks.get(sub["trajectory_id"]) in tasks]
|
|
178
|
+
return AtifPage(header=header, subagents=subagents, steps=served,
|
|
179
|
+
next=served[-1]["step_id"] if served else after, has_more=len(served) < len(pending))
|
|
180
|
+
|
|
181
|
+
def _open(self, task_id: str) -> _Task | None:
|
|
182
|
+
if self._failed is not None:
|
|
183
|
+
return None
|
|
184
|
+
task = self._tasks.get(task_id)
|
|
185
|
+
return task if task is not None and not task.ended else None
|
|
186
|
+
|
|
187
|
+
def _feed(self, task: _Task, record: Any) -> None:
|
|
188
|
+
self._run.native(record)
|
|
189
|
+
task.natives += 1
|
|
190
|
+
|
|
191
|
+
@contextmanager
|
|
192
|
+
def _guarded(self) -> Iterator[None]:
|
|
193
|
+
"""Run a step of the copy: an error there stops the copy, and never reaches the agent's turn."""
|
|
194
|
+
try:
|
|
195
|
+
yield
|
|
196
|
+
except Exception as exc:
|
|
197
|
+
self._failed = f"{type(exc).__name__}: {exc}"
|
|
198
|
+
logger.warning("the atif/1 copy of context %s stopped at an error in %s: %s", self._context_id,
|
|
199
|
+
self._adapter, self._failed)
|
|
200
|
+
|
|
201
|
+
def _check(self) -> None:
|
|
202
|
+
if self._failed is not None:
|
|
203
|
+
raise AgentEnvError(
|
|
204
|
+
"atif_unavailable",
|
|
205
|
+
f"the {FORMAT} copy of context {self._context_id!r} stopped at an error in its adapter "
|
|
206
|
+
f"{self._adapter}: {self._failed}; its native trajectory is unaffected",
|
|
207
|
+
status=UNAVAILABLE_STATUS,
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _real_now() -> datetime:
|
|
212
|
+
return datetime.now(timezone.utc)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def _session_now() -> datetime:
|
|
216
|
+
return datetime.fromtimestamp(follower.session_time(), timezone.utc)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def _inbound(parts: Iterable[Any], run: AdapterRun) -> list[Any]:
|
|
220
|
+
"""An inbound message as ATIF content: text as text, a DataPart as its compact JSON, a file's bytes as media and a
|
|
221
|
+
file by URI as a note naming it."""
|
|
222
|
+
content: list[Any] = []
|
|
223
|
+
for part in parts:
|
|
224
|
+
if isinstance(part, TextPart):
|
|
225
|
+
content.append(part.text)
|
|
226
|
+
elif isinstance(part, DataPart):
|
|
227
|
+
content.append(_compact(_thaw(part.data)))
|
|
228
|
+
elif isinstance(part, FilePart):
|
|
229
|
+
content.append(_file(part, run))
|
|
230
|
+
return content
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def _final(parts: Iterable[Any], run: AdapterRun) -> tuple[list[Any], list[dict[str, Any]]]:
|
|
234
|
+
"""A final response as ATIF content and its diagnostics: text, files and a structured output (the task's answer,
|
|
235
|
+
as compact JSON) are content; any other DataPart is the harness's diagnostics, for the last step's ``data``."""
|
|
236
|
+
content: list[Any] = []
|
|
237
|
+
data: list[dict[str, Any]] = []
|
|
238
|
+
for part in parts:
|
|
239
|
+
if isinstance(part, TextPart):
|
|
240
|
+
content.append(part.text)
|
|
241
|
+
elif isinstance(part, DataPart):
|
|
242
|
+
value = _thaw(part.data)
|
|
243
|
+
if set(value) == {STRUCTURED_OUTPUT}:
|
|
244
|
+
content.append(_compact(value[STRUCTURED_OUTPUT]))
|
|
245
|
+
else:
|
|
246
|
+
data.append({"data": value, **({"metadata": _thaw(part.metadata)} if part.metadata else {})})
|
|
247
|
+
elif isinstance(part, FilePart):
|
|
248
|
+
content.append(_file(part, run))
|
|
249
|
+
return content, data
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def _file(part: FilePart, run: AdapterRun) -> Media | str:
|
|
253
|
+
media_type = part.mime_type or "application/octet-stream"
|
|
254
|
+
if part.bytes is not None:
|
|
255
|
+
try:
|
|
256
|
+
data = base64.b64decode(part.bytes, validate=True)
|
|
257
|
+
except (binascii.Error, ValueError):
|
|
258
|
+
return f"[file: {part.name or 'unnamed'}, {media_type}, bytes that aren't base64]"
|
|
259
|
+
return run.media(data, media_type, name=part.name)
|
|
260
|
+
assert part.uri is not None
|
|
261
|
+
where = urlsplit(part.uri)
|
|
262
|
+
# The query and fragment are dropped: a signed URL's signature is a grant.
|
|
263
|
+
return f"[file: {part.name or 'unnamed'}, {media_type}, {urlunsplit((*where[:3], '', ''))}]"
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _compact(value: Any) -> str:
|
|
267
|
+
return json.dumps(value, separators=(",", ":"), ensure_ascii=False, allow_nan=False)
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""The SDK's own state in an agent's snapshots: each context's atif/1 turn count. The SDK uploads it after the agent's
|
|
2
|
+
save handler and reads it before its load handler, through the request's ``state`` grant, and the card names it, so a
|
|
3
|
+
caller grants the object only to an SDK that takes it. While such a snapshot is in flight no task of its context
|
|
4
|
+
starts, so the count is the conversation's the agent captured; a running task goes on, as a capture mid-task expects."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import asyncio
|
|
9
|
+
import tempfile
|
|
10
|
+
from collections.abc import AsyncIterator, Awaitable, Callable
|
|
11
|
+
from contextlib import asynccontextmanager
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
from pydantic import BaseModel, ConfigDict, Field, ValidationError
|
|
17
|
+
|
|
18
|
+
from ..errors import AgentEnvError
|
|
19
|
+
from ..transfers import download, upload
|
|
20
|
+
from ._trajectory_log import TaskTrajectories
|
|
21
|
+
from .extensions import SNAPSHOT_V1, ObjectSnapshotLoadRequest, ObjectSnapshotSaveRequest
|
|
22
|
+
|
|
23
|
+
#: The snapshot extension's card param naming the fields of the state an SDK keeps in each snapshot: a caller grants
|
|
24
|
+
#: the ``state`` object only to an agent whose card has it, since an SDK from before it refuses the object.
|
|
25
|
+
SNAPSHOT_STATE_PARAM = "state"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class SnapshotState(BaseModel):
|
|
29
|
+
"""What the SDK keeps in a snapshot beside the agent's own objects: the context's turn count. A newer SDK may add
|
|
30
|
+
fields, which an older one reading the snapshot leaves alone."""
|
|
31
|
+
|
|
32
|
+
model_config = ConfigDict(extra="ignore", frozen=True)
|
|
33
|
+
|
|
34
|
+
turns: int = Field(ge=0)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class SnapshotStates:
|
|
38
|
+
"""The SDK's state in the snapshots of an agent that serves atif/1."""
|
|
39
|
+
|
|
40
|
+
def __init__(self, trajectories: TaskTrajectories) -> None:
|
|
41
|
+
self._trajectories = trajectories
|
|
42
|
+
self._in_flight = _InFlightSnapshots()
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
def card_extension(item: dict[str, Any]) -> dict[str, Any]:
|
|
46
|
+
"""An extension's card entry; the snapshot extension's names the state the SDK keeps."""
|
|
47
|
+
if item.get("uri") != SNAPSHOT_V1.uri:
|
|
48
|
+
return item
|
|
49
|
+
return {**item, "params": {**item.get("params", {}), SNAPSHOT_STATE_PARAM: list(SnapshotState.model_fields)}}
|
|
50
|
+
|
|
51
|
+
async def save(self, request: Any, invoke: Callable[[], Awaitable[dict[str, Any]]]) -> dict[str, Any]:
|
|
52
|
+
"""The agent's save, then the context's count uploaded through the ``state`` grant and named in the answer. A
|
|
53
|
+
request that grants no state is the agent's alone."""
|
|
54
|
+
if not isinstance(request, ObjectSnapshotSaveRequest) or request.objects.state is None:
|
|
55
|
+
return await invoke()
|
|
56
|
+
async with self._in_flight.holding(request.context_id):
|
|
57
|
+
answer = await invoke()
|
|
58
|
+
state = SnapshotState(turns=self._trajectories.turns(request.context_id))
|
|
59
|
+
uploaded = await upload(request.objects.state, state.model_dump_json().encode())
|
|
60
|
+
return {**answer, "objects": {**answer["objects"], "state": uploaded.model_dump(mode="json", exclude_none=True)}}
|
|
61
|
+
|
|
62
|
+
async def load(self, request: Any, invoke: Callable[[], Awaitable[dict[str, Any]]]) -> dict[str, Any]:
|
|
63
|
+
"""The state the snapshot carries, read before the agent's load, then the context the agent restored into
|
|
64
|
+
seeded with its count. A request that grants no state is the agent's alone."""
|
|
65
|
+
if not isinstance(request, ObjectSnapshotLoadRequest) or request.objects.state is None:
|
|
66
|
+
return await invoke()
|
|
67
|
+
state = await _read(request.objects.state)
|
|
68
|
+
async with self._in_flight.holding(request.target_context_id):
|
|
69
|
+
answer = await invoke()
|
|
70
|
+
self._trajectories.restored(str(answer["context_id"]), state.turns)
|
|
71
|
+
return answer
|
|
72
|
+
|
|
73
|
+
async def task_may_start(self, context_id: str) -> None:
|
|
74
|
+
"""Wait until no snapshot of the context is in flight."""
|
|
75
|
+
await self._in_flight.wait(context_id)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
async def _read(grant: Any) -> SnapshotState:
|
|
79
|
+
with tempfile.TemporaryDirectory() as folder:
|
|
80
|
+
path = Path(folder) / "state.json"
|
|
81
|
+
await download(grant, path)
|
|
82
|
+
try:
|
|
83
|
+
return SnapshotState.model_validate_json(path.read_bytes())
|
|
84
|
+
except ValidationError as exc:
|
|
85
|
+
raise AgentEnvError(
|
|
86
|
+
"snapshot_state_invalid",
|
|
87
|
+
f"the snapshot's state object isn't the SDK's snapshot state: {exc.errors()[0]['msg']}",
|
|
88
|
+
status=400,
|
|
89
|
+
) from exc
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@dataclass(slots=True)
|
|
93
|
+
class _InFlight:
|
|
94
|
+
count: int = 0
|
|
95
|
+
turn: asyncio.Lock = field(default_factory=asyncio.Lock)
|
|
96
|
+
done: asyncio.Event = field(default_factory=asyncio.Event)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class _InFlightSnapshots:
|
|
100
|
+
"""Each context's snapshots in flight, taken one at a time, so a load can't change the count a save is about to
|
|
101
|
+
read, and a task of the context waits to start until none is."""
|
|
102
|
+
|
|
103
|
+
def __init__(self) -> None:
|
|
104
|
+
self._contexts: dict[str, _InFlight] = {}
|
|
105
|
+
|
|
106
|
+
@asynccontextmanager
|
|
107
|
+
async def holding(self, context_id: str | None) -> AsyncIterator[None]:
|
|
108
|
+
if context_id is None:
|
|
109
|
+
yield
|
|
110
|
+
return
|
|
111
|
+
entry = self._contexts.setdefault(context_id, _InFlight())
|
|
112
|
+
entry.count += 1
|
|
113
|
+
try:
|
|
114
|
+
async with entry.turn:
|
|
115
|
+
yield
|
|
116
|
+
finally:
|
|
117
|
+
entry.count -= 1
|
|
118
|
+
if not entry.count:
|
|
119
|
+
del self._contexts[context_id]
|
|
120
|
+
entry.done.set()
|
|
121
|
+
|
|
122
|
+
async def wait(self, context_id: str) -> None:
|
|
123
|
+
while (entry := self._contexts.get(context_id)) is not None:
|
|
124
|
+
await entry.done.wait()
|