Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
a5e088c
feat(agents): Codex serves atif/1, built live from the CLI's rollout
earakely-scale Nov 25, 2026
f0bfb44
feat(agents): Gemini serves atif/1, from its session transcript and i…
earakely-scale Nov 25, 2026
7e89286
test(agents): record Codex's and Gemini's atif/1 copies through their…
earakely-scale Nov 25, 2026
722721c
fix(agents): Codex's copy leaves out what a forked sub-agent copied, …
earakely-scale Nov 25, 2026
d081485
fix(agents): Gemini's copy never counts a call twice, and Codex reche…
earakely-scale Nov 25, 2026
b673e92
docs(agents): Codex's and Gemini's atif/1 copies
earakely-scale Nov 25, 2026
ecdd194
test(agents): Codex's and Gemini's atif/1 fixtures recorded again, wi…
earakely-scale Nov 25, 2026
458bef7
test(agents): a fork's copied turns hold the parent's own reply, whic…
earakely-scale Nov 25, 2026
188785a
fix(agents): a read in flight when following stops is fed, and an ear…
earakely-scale Nov 25, 2026
508c917
build(agents): Claude Code's protocol floor is 0.1.660, the first wit…
earakely-scale Nov 25, 2026
6b9f8fa
test(agents): Codex's atif/1 fixtures recorded again on its clocked i…
earakely-scale Nov 26, 2026
3e454df
fix(agents): Gemini's copy reads a .jsonl transcript too, as a sessio…
earakely-scale Nov 26, 2026
4109f34
fix(agents): Gemini's tail reads a transcript moved since the last po…
earakely-scale Nov 26, 2026
acedef4
fix(agents): Gemini's copy joins a response only to a call that had e…
earakely-scale Nov 26, 2026
fc1730d
fix(agents): Gemini's copy keeps a file in a tool result's own parts
earakely-scale Nov 26, 2026
f2476e1
refactor(agents): Gemini's copy joins a response to the latest call t…
earakely-scale Nov 27, 2026
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
4 changes: 3 additions & 1 deletion src/agent_env/agents/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ other with `self.register_secret(value)`, in `run` or later, and the SDK writes
Reference: `enable(TRAJECTORY_V1, live=True, ...)`, `ClaudeCodeAgent.run` passing
`event_callback=request.trajectory.append`, and `get_context_trajectory` / `upload_context_trajectory`. Its adapter,
`claude_code_atif.py`, builds steps from stream-json with each message's time, usage and tools from the CLI's session
transcript, which `claude_bridge.SessionTail` feeds as aux records only while `request.trajectory.builds_atif`. A runtime
transcript, which `claude_bridge.SessionTail` feeds as aux records only while `request.trajectory.builds_atif`. Codex's,
`codex_atif.py`, builds them from the CLI's rollout alone, which `codex_bridge.RolloutTail` feeds; Gemini's,
`gemini_atif.py`, from its session transcript (`gemini_bridge.SessionTail`) and the proxy's call records. A runtime
that only has a record at the end returns it with `native_trajectory(...)`: `agents/pi/pi_agent.py` `_result`.

### `skill-config/v1`, `/ext/skill-config`
Expand Down
27 changes: 15 additions & 12 deletions src/agent_env/agents/agents/claude-code/claude_code_atif.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,27 @@
from dataclasses import dataclass
from typing import Any

from agentenv_protocol.atif import Adapter, AtifError, Native, atif_adapter, aux, finish, native
from agentenv_protocol.atif import (
COMPACTION_TRIGGERS,
Adapter,
AtifError,
Native,
atif_adapter,
aux,
finish,
is_token_count,
native,
)

NATIVE_FORMAT = "claude-code-stream-json/1"
#: The CLI versions the recorded fixtures come from; a unit test holds the Dockerfile's pin to this list.
TESTED_WITH = ("2.1.322",)
#: The model a message the CLI wrote itself names, such as an API error's, which no model call produced.
_SYNTHETIC_MODEL = "<synthetic>"
#: What sets a compaction off, as atif/1's COMPACTION_TRIGGERS names it.
_TRIGGERS = ("manual", "auto")
#: A step's token counts as the builder takes them, and as the turn record and a session record give them.
_COUNTS = ("input_tokens", "output_tokens", "cache_read_tokens", "cache_write_tokens")


def _token_count(value: Any) -> int | None:
"""``value`` when it counts tokens, as atif/1's ``is_token_count`` says, which the module defines itself: it
imports only what its protocol floor has, and the image installs any protocol at or above that floor."""
return value if isinstance(value, int) and not isinstance(value, bool) and value >= 0 else None


@dataclass(frozen=True)
class _Boundary:
"""A ``compact_boundary``'s facts: what set the compaction off, and the history's tokens before and after it."""
Expand Down Expand Up @@ -147,8 +149,9 @@ def boundary(self, record: dict[str, Any], turn: Any) -> None:
"""The CLI's compaction: the next user message on stdout is its summary."""
metadata = record.get("compact_metadata") if _is_mapping(record.get("compact_metadata")) else {}
trigger, before, after = (metadata.get(key) for key in ("trigger", "pre_tokens", "post_tokens"))
self._boundary = _Boundary(trigger=trigger if trigger in _TRIGGERS else None,
tokens_before=_token_count(before), tokens_after=_token_count(after))
self._boundary = _Boundary(trigger=trigger if trigger in COMPACTION_TRIGGERS else None,
tokens_before=before if is_token_count(before) else None,
tokens_after=after if is_token_count(after) else None)

@native(type="system", where={"subtype": "init"})
def init(self, record: dict[str, Any], turn: Any) -> None:
Expand Down Expand Up @@ -443,7 +446,7 @@ def _usage(session: dict[str, Any] | None) -> dict[str, int] | None:
counts = {"input_tokens": usage.get("input_tokens"), "output_tokens": usage.get("output_tokens"),
"cache_read_tokens": usage.get("cache_read_input_tokens"),
"cache_write_tokens": usage.get("cache_creation_input_tokens")}
counts = {name: value for name, value in counts.items() if _token_count(value) is not None}
counts = {name: value for name, value in counts.items() if is_token_count(value)}
return counts or None

def _attempt_failed(self, result: dict[str, Any], turn: Any) -> None:
Expand Down
6 changes: 3 additions & 3 deletions src/agent_env/agents/agents/claude-code/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The image installs the newest agentenv-framework-protocol at or above this floor; a release doesn't pin it, so the
# image is built again only when this folder changes. The floor is the first whose live atif/1 reads take the header's
# digest and a cursor per sub-agent; raise it when the agent needs a newer protocol.
agentenv-framework-protocol[agent]>=0.1.649
# image is built again only when this folder changes. The floor is the first with atif/1 profile 1.2, whose compactions
# hold the history's tokens before and after them; raise it when the agent needs a newer protocol.
agentenv-framework-protocol[agent]>=0.1.660
2 changes: 1 addition & 1 deletion src/agent_env/agents/agents/codex/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RUN npm ci --ignore-scripts --omit=dev --no-audit --no-fund --loglevel=error &&
COPY requirements.txt model-requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt -r model-requirements.txt
# install.sh and run.sh are install/v1's: in the image, so they stay in its build context.
COPY a2a_server.py codex_bridge.py codex_config.py codex_date.py codex_kit.py entrypoint.sh install.sh run.sh ./
COPY a2a_server.py codex_atif.py codex_bridge.py codex_config.py codex_date.py codex_kit.py entrypoint.sh install.sh run.sh ./
# Every clocked agent's egress rule, which the bridge imports, the clock page's format it reads, and the model relay
# each CLI run calls the endpoint through (shared_sources.toml).
COPY agent_clock/agent_egress.py clock/clockpage.py model_relay/model_relay.py ./
Expand Down
2 changes: 1 addition & 1 deletion src/agent_env/agents/agents/codex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ come.
| `agent-config/v1` | `CodexConfig`: `model`, `effort` (Codex's `model_reasoning_effort`; a set without it clears it), `system_prompt` (Codex's `developer_instructions`), `output_format` (a JSON schema, as `--output-schema`), `project_id`, `task_id`, `timeout_seconds`, `builtin_tools`, `web_tools` (below) |
| `mcp-config/v1` | SDK default; written to `config.toml` before each task |
| `skill-config/v1` | inline and bundle skills installed as `~/.agents/skills/<name>/SKILL.md`, where Codex finds them |
| `trajectory/v1` | the task's `codex exec --json` events, live while it runs (format `codex-exec-json/1`) |
| `trajectory/v1` | the task's `codex exec --json` events, live while it runs (format `codex-exec-json/1`); `atif/1` when the run prescribes it, built live from the CLI's rollout (`codex_atif.py`): a step per model response with its time (the rollout's, real time on an armed clock too) and usage, each sub-agent embedded under its `spawn_agent` call, a resumed attempt's steps numbered |
| `snapshot/v1` | `save` uploads the thread's rollout JSONL and the workspace as a gzipped tar, each held to a size limit, once no task of the context runs; `load` writes the rollout under a fresh thread id, replaces the workspace's contents (extracted aside first) and binds the thread to the target context |
| `peer-agents/v1` | SDK default: the CLI reaches the task's other agents through the SDK's `peer_agents` MCP tools |
| `attribution-probe/v1` | the `project_id` and `task_id` the last CLI run sent |
Expand Down
13 changes: 12 additions & 1 deletion src/agent_env/agents/agents/codex/a2a_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
from starlette.exceptions import HTTPException

import codex_config
from codex_atif import CodexAtif
from codex_bridge import (
SESSIONS_DIR,
CodexResult,
Expand Down Expand Up @@ -232,6 +233,12 @@ def _discard_execution_task(context_id: str, task: asyncio.Task) -> None:
_active_execution_tasks.pop(context_id, None)


def _builds_atif(request: TaskRequest[CodexConfig]) -> bool:
"""Whether the task feeds an atif/1 copy; a protocol from before ``builds_atif`` is taken to, and its copy is built
only when the run prescribed it."""
return getattr(request.trajectory, "builds_atif", True)


class CodexConfig(AgentConfig):
model: str | None = None
effort: str | None = None
Expand Down Expand Up @@ -647,7 +654,10 @@ def total(name: str, of: list[ThreadCalls]) -> int | None:
TRAJECTORY_V1,
live=True,
native=TRAJECTORY_FORMAT,
description="Retrieve a task's Codex --json trajectory, also while it runs.",
atif=CodexAtif,
description=(
"Retrieve a task's Codex --json trajectory, also while it runs; atif/1 when the run prescribes it."
),
),
enable(
ATTRIBUTION_PROBE_V1,
Expand Down Expand Up @@ -751,6 +761,7 @@ def _record_event(event: dict) -> None:
project_id=cfg.project_id,
task_id=cfg.task_id,
event_callback=_record_event,
aux_callback=request.trajectory.aux if _builds_atif(request) else None,
max_turns=cfg.max_turns,
mcp_urls=[info["url"] for info in request.mcp_servers.values()],
config_overrides=[*codex_config.role_overrides(request.mcp_servers, cfg.role),
Expand Down
Loading
Loading