Skip to content
Merged
6 changes: 5 additions & 1 deletion packages/agentenv-protocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,11 @@ the profile's spec, and `fixtures/` holds its canonical examples. The package ne
with the cache included, stores media at `media/<sha256>.<ext>`, embeds sub-agents and normalizes timestamps. A
record no method takes is counted in the root profile. `turn.tool_definitions([...], agent=None)` writes the tools
the model was offered, in OpenAI's function form, to a trajectory's `agent.tool_definitions`; a later call adds
tools and replaces those of the same name.
tools and replaces those of the same name. A message the harness itself put in the conversation, such as a
command's output, is `turn.system_message(text=...)`, a `source: system` step of its own. A compaction, a summary
that replaced the conversation in what the agent sees, is the message of the step of the call that wrote it,
marked by `turn.compaction(step=..., written_by="assistant" | "harness", trigger="manual" | "auto")`, its usage
that call's (profile 1.1).
- **The runner** (`AdapterRun`, `replay`) feeds one A2A context's records through one adapter instance, a task at a
time. It writes each task's user step from its `TurnContext`, and the final response once, with the task's
terminal state on its last step. Its `page()` is the live view, built when it's read: closed steps only, so a
Expand Down
48 changes: 33 additions & 15 deletions packages/agentenv-protocol/src/agentenv_protocol/atif/PROFILE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The agentenv profile of ATIF

Profile 1.0. agentenv records what an agent did as an ATIF v1.8 document: Harbor's
Profile 1.1. agentenv records what an agent did as an ATIF v1.8 document: Harbor's
[Agent Trajectory Interchange Format](https://github.com/harbor-framework/harbor/blob/main/rfcs/0001-trajectory-format.md),
whose models are vendored in `models/`. An agent serves it as format `atif/1`, beside its native log. What ATIF has no
typed field for, agentenv adds under `extra.agentenv` on the objects that have an `extra`. This file is the profile's spec.
Expand Down Expand Up @@ -36,14 +36,20 @@ to native exactly.
call's result by `subagent_trajectory_ref`. It belongs to the task of the call that spawned it. A sub-agent that
wrote no step is left out, and so is the reference to it. A spawning call with no result when its task ends gets
one, with no content and `status: canceled`, so its sub-agent stays referenced.
- `schema_version` is the oldest ATIF version that holds the document's fields: `ATIF-v1.8` for profile 1.0.
- `schema_version` is the oldest ATIF version that holds the document's fields: `ATIF-v1.8` for profile 1.1.
- Format id: `atif/1`. The profile's own version is the root's `extra.agentenv.version`.

## Steps

- A step is one model response, keyed by its native id (a message id), or a step with no model call
(`llm_call_count` 0, no metrics or reasoning). A step closes when the next step of its trajectory starts, or when its
task ends.
- A `source: system` step is a message the harness itself put in the conversation, such as a command's output: neither
the agent's words nor the user's. A reader that stages a turn for a judge shows it as a note. (1.1)
- A compaction is when the harness replaces the conversation so far with a summary, in what the agent sees from then
on. The summary is the message of the step of the model call that wrote it: a `source: agent` step carrying that
call's metrics, its profile's `compaction` saying who wrote it and what set it off. A reader that stages a turn for a
judge shows it as a note, not as the agent speaking. (1.1)
- A result always sits in the step that made its call, as ATIF requires. One that arrives after that step closed records
when, in `arrived`.
- A live reader is served closed steps only, each trajectory up to its first step still waiting on a result or
Expand Down Expand Up @@ -117,7 +123,7 @@ One vocabulary, in three places:

| Object | Field | Meaning | Read by |
| --- | --- | --- | --- |
| Trajectory | `version` | The profile version: `1.0` | every reader |
| Trajectory | `version` | The profile version: `1.1` | every reader |
| Trajectory | `native_format` | The native format id the copy was built from | the worker that stores copies; renormalizing |
| Trajectory | `adapter` | The adapter's `name` and `version` | the worker that stores copies; renormalizing |
| Trajectory | `unmatched` | Native records no method took, counted by type | the adapter kit |
Expand All @@ -126,6 +132,7 @@ One vocabulary, in three places:
| Step | `attempt` | The harness attempt the step belongs to; absent means 1 | the explorer |
| Step | `error` | A step-level error: `kind`, `message`, `code` | the explorer |
| Step | `data` | On a task's last step: its final response's diagnostic DataParts, in order, each `data` and its `metadata` | the explorer |
| Step | `compaction` | On a compaction's step: who wrote the summary (`written_by`) and what set it off (`trigger`). (1.1) | judges' turn events |
| Step | `reasoning` | Each reasoning block: `chars`, `visibility`, `signature`, `data` | resuming a session; RL replay |
| Step | `media` | Details of the media the message names, by path | media transfer; the explorer |
| ObservationResult | `status` | The result's status; absent means `ok` | the explorer, judges' turn events |
Expand All @@ -137,12 +144,13 @@ One vocabulary, in three places:
| FinalMetrics | `cost_source` | Where `total_cost_usd` came from | the run's usage and cost result |
| FinalMetrics | `total_cache_write_tokens` | Cache writes summed over the steps | the run's usage and cost result |

A media entry (MediaInfo) holds `sha256`, `bytes`, and, where they apply, `width`, `height`, `duration_ms`, `pages`
and `name`, plus `media_type` for media ATIF has no part type for. A reasoning block (ReasoningBlock) holds `chars`,
its share of `reasoning_content` (0 when the provider withheld the text), its `visibility`, the provider's `signature`,
and a redacted block's ciphertext as `data`, byte for byte. A step error (StepError) holds `kind`, `message` and `code`.
An arrival (Arrival) holds `at` and `step_id`. The Agent, ToolCall and SubagentTrajectoryRef profiles define no fields
in 1.0.
A media entry (MediaInfo) holds `sha256`, `bytes`, and, where they apply, `width`, `height`, `duration_ms`, `pages` and
`name`, plus `media_type` for media ATIF has no part type for. A reasoning block (ReasoningBlock) holds `chars`, its
share of `reasoning_content` (0 when the provider withheld the text), its `visibility`, the provider's `signature`, and
a redacted block's ciphertext as `data`, byte for byte. A step error (StepError) holds `kind`, `message` and `code`. An
arrival (Arrival) holds `at` and `step_id`. A compaction (Compaction) holds `written_by`, `assistant` for the agent's
own model or `harness`, and `trigger`, `manual` when something asked for it, such as a command, or `auto` when the
harness set it off itself. The Agent, ToolCall and SubagentTrajectoryRef profiles define no fields in 1.1.

## Vocabularies

Expand All @@ -155,18 +163,27 @@ A reader keeps a value it doesn't know.
| `StepError.kind` | `agent_error`, `infra_error` |
| `ReasoningBlock.visibility` | `raw`, `summary`, `omitted`, `redacted` |
| `MetricsProfile.cost_source`, `FinalMetricsProfile.cost_source` | `harness`, `provider` |
| `Compaction.written_by` | `assistant`, `harness` |
| `Compaction.trigger` | `manual`, `auto` |

## Versions

A minor version only adds optional fields and vocabulary values, each with the reader or producer that needs it. A
field added in a later minor names the version it arrived in. Proposed for a later minor, with their first producer:
`input_includes_cache` on the root and `cost_status` (`reported`, `priced` or `unpriced`), with the usage
cross-check that reads them; per-part origins, when a reader needs them; and an always-on harness's fields.
field added in a later minor names the version it arrived in, and a reader of a minor reads every one before it.

- 1.1 adds `compaction` and `source: system` steps as the harness's own messages. Their first producer is Claude
Code's adapter, and their reader the judges' turn events.
- Proposed for a later minor, with their first producer:
- `input_includes_cache` on the root and `cost_status` (`reported`, `priced` or `unpriced`), with the usage
cross-check that reads them;
- per-part origins, when a reader needs them;
- the rest of an always-on harness's fields: the facts of its compaction (what it kept), the purpose of its
messages, and the tools it provides itself.

## Validator

`validate(document)` returns findings, each with a rule id below, a severity and where in the document it is. It holds a
producer's output to profile 1.0. `reader=True` checks someone else's document for reading instead: what a producer
producer's output to this profile. `reader=True` checks someone else's document for reading instead: what a producer
must not write only warns, and the document fails only where agentenv couldn't read it. `media` is the folder the
document's media paths are relative to, the one holding `media/`, or the files by path; without it only the paths' form
is checked. `StoredMedia(sizes)` stands for files stored beside the document whose bytes were checked against their
Expand All @@ -182,8 +199,9 @@ and exits 1 when one is an error.
| `json` | The document is a JSON object: UTF-8, with no NaN or infinity | error | error |
| `atif` | ATIF's own models, vendored from Harbor, accept it | error | error |
| `profile` | Each `extra.agentenv` parses with its profile model | error | error |
| `profile-key` | Each `extra.agentenv` holds only the fields profile 1.0 defines | error | warning |
| `profile-version` | The root's `extra.agentenv.version`, when given, is `1.0` | error | warning |
| `profile-key` | Each `extra.agentenv` holds only the fields this profile defines | error | warning |
| `profile-version` | The root's `extra.agentenv.version`, when given, is a 1.x this validator knows: 1.0 or 1.1 | error | warning |
| `compaction` | A step's `compaction` is on a `source: agent` step and names who wrote its summary | error | warning |
| `vocabulary` | A vocabulary field holds one of its values | error | warning |
| `outside-key` | No `extra` holds a key outside `agentenv` but `ToolCall.extra.raw_arguments` | error | warning |
| `call-id` | Each `tool_call_id` is unique across the document and its sub-agents | error | warning |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@
Trajectory,
)
from .profile import (
COMPACTION_TRIGGERS,
FORMAT,
PROFILE_KEY,
PROFILE_VERSION,
PROFILES,
RAW_ARGUMENTS,
SCHEMA_VERSION,
SUMMARY_WRITERS,
VOCABULARIES,
AdapterRef,
AgentProfile,
Arrival,
AtifError,
Compaction,
FinalMetricsProfile,
MediaInfo,
MetricsProfile,
Expand Down Expand Up @@ -68,13 +71,14 @@

__all__ = [
"Adapter", "AdapterRef", "AdapterRun", "AdapterSpec", "Agent", "AgentProfile", "Arrival", "atif_adapter",
"AtifError", "AtifTurn", "AudioSource", "aux", "AuxEntry", "check", "check_adapter", "check_media", "ContentItem", "ContentPart",
"AtifError", "AtifTurn", "AudioSource", "aux", "AuxEntry", "check", "check_adapter", "check_media", "Compaction",
"COMPACTION_TRIGGERS", "ContentItem", "ContentPart",
"Document", "dump_profile", "errors_in", "Fed", "FinalMetrics", "FinalMetricsProfile", "Finding", "finish",
"FORMAT", "ImageSource", "is_prefix", "KIT_RULES", "KitResult", "load", "Media", "MEDIA_PATH", "media_file", "media_paths", "MediaInfo",
"MediaItem", "MediaRef", "media_refs", "Metrics", "MetricsProfile", "Native", "native", "Observation", "ObservationResult",
"ObservationResultProfile", "PROFILE_KEY", "profile_of", "PROFILE_VERSION", "PROFILES", "RAW_ARGUMENTS",
"read_profile", "ReasoningBlock", "RecordedTask", "replay", "Rule", "RULES", "SCHEMA_VERSION", "Selector",
"ServedData", "ServedError", "ServedMedia", "ServedTurn", "Step", "StepData", "StepError", "StepProfile", "StoredMedia",
"strip_profile", "SubagentTrajectoryRef", "SubagentTrajectoryRefProfile", "Task", "task_document", "tasks", "tasks_document", "timestamp", "ToolCall",
"strip_profile", "SubagentTrajectoryRef", "SUMMARY_WRITERS", "SubagentTrajectoryRefProfile", "Task", "task_document", "tasks", "tasks_document", "timestamp", "ToolCall",
"ToolCallProfile", "Trajectory", "TrajectoryProfile", "TurnContext", "validate", "validate_live", "validate_media", "VOCABULARIES",
]
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
from .adapter import AdapterSpec
from .models.content import AudioMediaType, ContentPart, ImageSource
from .profile import (
COMPACTION_TRIGGERS,
COST_SOURCES,
ERROR_KINDS,
PROFILE_KEY,
PROFILE_VERSION,
RAW_ARGUMENTS,
RESULT_STATUSES,
SCHEMA_VERSION,
SUMMARY_WRITERS,
TASK_STATES,
VISIBILITIES,
AtifError,
Expand Down Expand Up @@ -345,6 +347,9 @@ def peek(self, key: str, agent: str | None) -> _Step | None:
def step_for(self, key: str, agent: str | None) -> _Step:
return self.peek(key, agent) or self._start(self._traj(agent), "agent", key)

def system_step(self) -> _Step:
return self._start(self._traj(None), "system", None)

def open_step(self, agent: str | None) -> _Step:
step = self._traj(agent).open
if step is None:
Expand Down Expand Up @@ -899,6 +904,30 @@ def error(self, *, message: str, kind: str = "agent_error", code: str | None = N
target.profile["error"] = {k: v for k, v in (("kind", kind), ("message", message), ("code", code))
if v is not None}

def system_message(self, *, text: str | None = None, content: Sequence[Any] | None = None,
time: str | datetime | None = None) -> None:
"""A message the harness itself put in the conversation, such as a command's output: a ``source: system`` step
of its own in the root trajectory, which closes the step before it. Profile 1.1."""
parts, media = self._doc.parse_parts(content, text)
when = timestamp(time)
target = self._doc.system_step()
target.parts.extend(parts)
target.media.update(media)
self._touch(target, when)

def compaction(self, *, step: str, written_by: str, trigger: str | None = None, agent: str | None = None) -> None:
"""Mark step ``step`` a compaction: its message a summary that replaced the conversation before it in what the
agent sees, written by ``written_by`` (``assistant``, the agent's own model, or ``harness``) and set off by
``trigger`` (``manual``, something asked for it, or ``auto``). The step is the call that wrote the summary,
so its usage goes on it with ``step``. Profile 1.1."""
if written_by not in SUMMARY_WRITERS:
raise AtifError(f"written_by {written_by!r} isn't one of {', '.join(SUMMARY_WRITERS)}")
if trigger is not None and trigger not in COMPACTION_TRIGGERS:
raise AtifError(f"trigger {trigger!r} isn't one of {', '.join(COMPACTION_TRIGGERS)}")
target = self._doc.step_for(_key(step), agent)
target.profile["compaction"] = {key: value for key, value in (("written_by", written_by), ("trigger", trigger))
if value is not None}

def attempt(self, number: int) -> None:
"""A harness retry: steps from here on carry attempt ``number``."""
self._doc.set_attempt(number)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
},
"extra": {
"agentenv": {
"version": "1.0",
"version": "1.1",
"native_format": "toy-events/1",
"adapter": {
"name": "toy-events-atif",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
},
"extra": {
"agentenv": {
"version": "1.0",
"version": "1.1",
"native_format": "toy-events/1",
"adapter": {
"name": "toy-events-atif",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
},
"extra": {
"agentenv": {
"version": "1.0",
"version": "1.1",
"native_format": "toy-events/1",
"adapter": {
"name": "toy-events-atif",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
},
"extra": {
"agentenv": {
"version": "1.0",
"version": "1.1",
"native_format": "toy-events/1",
"adapter": {
"name": "toy-events-atif",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
},
"extra": {
"agentenv": {
"version": "1.0",
"version": "1.1",
"native_format": "toy-events/1",
"adapter": {
"name": "toy-events-atif",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
},
"extra": {
"agentenv": {
"version": "1.0",
"version": "1.1",
"native_format": "toy-events/1",
"adapter": {
"name": "toy-events-atif",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
},
"extra": {
"agentenv": {
"version": "1.0",
"version": "1.1",
"native_format": "toy-events/1",
"adapter": {
"name": "toy-events-atif",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
FORMAT = "atif/1"
#: The key under each ``extra`` that holds the profile.
PROFILE_KEY = "agentenv"
PROFILE_VERSION = "1.0"
PROFILE_VERSION = "1.1"
#: The ATIF version producers write: the oldest that holds the fields they use.
SCHEMA_VERSION = "ATIF-v1.8"
#: The only key outside ``extra.agentenv`` a producer writes: Harbor's, on a ToolCall whose input wasn't an object.
Expand All @@ -24,13 +24,19 @@
ERROR_KINDS = ("agent_error", "infra_error")
VISIBILITIES = ("raw", "summary", "omitted", "redacted")
COST_SOURCES = ("harness", "provider")
#: Who wrote a compaction's summary: the agent's own model, or the harness. Added in 1.1.
SUMMARY_WRITERS = ("assistant", "harness")
#: What set a compaction off: something asked for it (a command), or the harness on its own. Added in 1.1.
COMPACTION_TRIGGERS = ("manual", "auto")
VOCABULARIES = {
"StepProfile.state": TASK_STATES,
"ObservationResultProfile.status": RESULT_STATUSES,
"StepError.kind": ERROR_KINDS,
"ReasoningBlock.visibility": VISIBILITIES,
"MetricsProfile.cost_source": COST_SOURCES,
"FinalMetricsProfile.cost_source": COST_SOURCES,
"Compaction.written_by": SUMMARY_WRITERS,
"Compaction.trigger": COMPACTION_TRIGGERS,
}


Expand Down Expand Up @@ -77,6 +83,14 @@ class StepError(_Profile):
code: str | None = None


class Compaction(_Profile):
"""A step whose message is a summary that replaced the conversation before it, in what the agent sees from then on:
who wrote it, and what set it off. Added in 1.1."""

written_by: str | None = None
trigger: str | None = None


class Arrival(_Profile):
"""When a result arrived after its call's step had closed: its time, and the step open when it came."""

Expand Down Expand Up @@ -113,6 +127,7 @@ class StepProfile(_Profile):
reasoning: list[ReasoningBlock] | None = None
media: dict[str, MediaInfo] | None = None
data: list[StepData] | None = None
compaction: Compaction | None = None


class ToolCallProfile(_Profile):
Expand Down
Loading
Loading