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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ or removing a command fails until the table changes in the same commit.
| `agentSessions.list` | List a page of recorded agent sessions by directory and order, with their activity and the whole list's counts, or find one by its ID |
| `agentSessions.search` | Search recorded agent session text |
| `agentSessions.read` | Read one recorded range as messages and where the next page starts |
| `agentSessions.page` | Read a bounded whole-line window before or after a recorded byte cursor, growing only for a long source line |
| `agentSessions.stats` | Sum recorded agent usage with the latest rate limits |
| `agentSessions.calls` | List a page of recorded agent calls, most recent first, with their cost, cache hit rate and speed |
| `agentLibrary.configure` | Open the agent library in the platform's application data |
Expand Down Expand Up @@ -9180,3 +9181,41 @@ retained history. Unknown operations/fields and malformed projection input fail
with `invalid_request`. This hot path is excluded from request tracing; its text
may contain secrets. Public backend methods and lifecycle are specified in the
[plugin contract](../../shared/plugins/contract/v1/README.md#workflow-host-methods).

### Recorded conversation windows

`agentSessions.page` takes `{agent, path, size, generation, cursor, direction}` for a
readable agent. `size` is a listed session's nonzero `readBytes` snapshot and
`generation` the same listing's `generation`; empty sessions need no page request. `direction` is `before`
or `after`, and `cursor` is zero, `size`, or a whole-line boundary previously
returned by Core. The answer is `{changed, tooLong, start, end, messages}`.
A nonempty source window advances in the requested direction even when no
message was found; use `start` to read older content and `end` for newer content.
An exhausted edge returns `start == end == cursor`. A zero size, invalid direction or an
interior cursor refuses with `agentSessions.invalidPage`; existing read grants,
source ownership and cached-file revision checks apply.

Core starts with 256 KiB of source, grows up to 16 MiB only when one line needs
it, and passes whole lines to the existing backend `read` function in batches
of at most 128 lines or about 64 KiB. A line that would take a nonempty batch past
64 KiB starts the next batch, so a long line is read alone and kept whole. The
encoded messages of a page are bounded to 768 KiB and 2048 messages, except
that the first complete batch is retained when it exceeds the page budget
while still fitting the backend result bound. A rejected next batch is read
again on the next page. `tooLong` stops a window that cannot advance within
the source bound. File replacement or truncation answers `changed` with no
messages: the cache reads such a file again under a new `generation`, and a page
whose `generation` is not the file's current one answers `changed` before reading,
even when the replacement has the same length; append-only growth beyond `size` stays outside the snapshot. Hosts
keep a bounded set of pages and reread evicted windows rather than truncating
long conversations. The backend `read` request includes `messageIDs: true`;
only then may a backend return the optional message `id`, an opaque source
identity for mirrors. Deduplicate it within the same agent, session and source
snapshot. The original read and title requests omit this flag, preserving the
strict message shape understood by older Core versions. The page request also sends
`toolCalls: true`, which lets a `tool` message carry the live `toolCall`
details (`toolCallID`, `status`, `toolKind`, `title`, `locations`); Core checks
them against the live event's bounds. `agentSessions.read` does not ask for them
and refuses a reading that carries any of these fields, even as `null`, with
`agentSessions.invalidRead`. See the executable
examples in [`record-page-v1.json`](../fixtures/agents/record-page-v1.json).
2 changes: 2 additions & 0 deletions rust/crates/agent-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub const AGENT_SESSION_COMMANDS: &[&str] = &[
"agentSessions.list",
"agentSessions.search",
"agentSessions.read",
"agentSessions.page",
"agentSessions.stats",
"agentSessions.calls",
];
Expand Down Expand Up @@ -147,6 +148,7 @@ impl Runtime {
"agentSessions.list" => self.records.list(self, payload),
"agentSessions.search" => self.records.search(self, payload),
"agentSessions.read" => self.records.read(self, payload),
"agentSessions.page" => self.records.page(self, payload),
"agentSessions.stats" => self.records.stats(self, payload),
"agentSessions.calls" => self.records.calls(self, payload),
"agentLibrary.configure" => self.library.configure(payload),
Expand Down
Loading
Loading