Skip to main content

Module export_for_agent

Module export_for_agent 

Source
Expand description

bundle.export_for_agent / bundle.export_for_agent_with_history: build an ABF from a live agent definition, optionally with its session history under the size budgets defined here.

Structs§

BundleExportWithHistoryResponse 🔒
Response for bundle.export_for_agent_with_history, which always zips.
ExportForAgentReq 🔒
bundle.export_for_agent — ABF v0.2 §2.3. The only export path that carries native memory: pulls a bundle’s normal components (identical to bundle.export) plus a snapshot of ONE agent’s db_agent_native_memory rows, refreshed from the live filesystem first (see [native_memory_handlers::refresh_memory_mirror_from_live_fs]’s doc comment for why that refresh is required, not optional). bundle. export stays agent-less and memory-less — bundles are reusable across many agents by design, so memory (inherently per-agent) needs its own, explicitly-scoped entry point rather than an implicit “whichever agent happens to be attached” guess.
ExportForAgentWithHistoryReq 🔒

Constants§

MAX_HISTORY_SESSION_FILE_SIZE_BYTES 🔒
Per-transcript size ceiling for bundle.export_for_agent_with_history. reagentx P1 on PR #2613: reading every session fully into a String with no bound could exhaust server memory for the multi-GB histories this feature exists to migrate. Unlike MAX_ABF_FILE_SIZE_BYTES (context files, truncated with a warning when oversized — fine, since a partial context file is still useful), a transcript is skipped ENTIRELY rather than truncated: JSONL requires whole lines, and a truncated mid-record file could fail to parse (or silently misparse) on the receiving end, which is worse than the session being visibly absent with a warning explaining why.
MAX_TOTAL_HISTORY_BYTES 🔒
Aggregate ceiling across every session included in one bundle.export_for_agent_with_history call. reagentx P1, third review round: a per-file cap alone doesn’t bound an agent with many sessions each just under it — this is the analogous total cap the sibling import path already enforces (MAX_TOTAL_UNCOMPRESSED_BYTES, bundle_import.rs), sized larger since export’s job is specifically to carry as much real history as reasonably fits, not to validate a small hand-authored bundle. Sessions are processed in sessions_for_agent’s existing modified_at desc order, so hitting this cap keeps the most recent conversations and cuts off the oldest — the same priority a human moving “my history” to a new machine would want. Unlike import’s reject-the-whole-thing-on-overflow behavior, export keeps its existing best-effort philosophy: stop including further sessions and say so in a warning, never fail the call outright.

Functions§

build_export_for_agent 🔒
bundle.export_for_agent — ABF v0.2 §2.3. The only export path that carries native memory: pulls a bundle’s normal components (identical to bundle.export) plus a snapshot of ONE agent’s db_agent_native_memory rows, refreshed from the live filesystem first (see [native_memory_handlers::refresh_memory_mirror_from_live_fs]’s doc comment for why that refresh is required, not optional). bundle. export stays agent-less and memory-less — bundles are reusable across many agents by design, so memory (inherently per-agent) needs its own, explicitly-scoped entry point rather than an implicit “whichever agent happens to be attached” guess. Extracted from the RPC closure into a directly-callable, directly-testable function, matching bundle_import_preview_impl’s pattern. Shared by bundle_export_for_agent_impl and bundle_export_for_agent_with_history_impl: resolve the bundle + agent, build the base BundleExport, splice in native memory. Returns the export, the resolved agent (the history variant needs its id), combined warnings, and missing skill ids. Everything after this point (whether to zip, whether to also append history files) is caller-specific.
bundle_export_for_agent_impl 🔒
bundle_export_for_agent_with_history_impl 🔒
bundle.export_for_agent_with_history — docs/specs/SPEC_AGENT_IDENTITY_HISTORY_PERSISTENCE_PROTOCOL_2026_08_16.md §3.3. Deliberately a SEPARATE, explicit, opt-in action from bundle.export_for_agent — see COMMAND_BUNDLE_EXPORT_FOR_AGENT_WITH_HISTORY’s doc comment for why conversation transcripts must never ride along in the default (shareable, reusable-across-agents) bundle export. Builds the identical base export, then appends every session HistoryService::sessions_for_agent finds for this agent under history/<provider>/<session_id>.jsonl. Always returns a zip — a multi-file, potentially large archive has no sensible inline-JSON shape, unlike the plain export’s optional format. A transcript that fails to read (deleted, permission issue, or over MAX_HISTORY_SESSION_FILE_SIZE_BYTES) is warned about and skipped, never fails the whole export — same best-effort philosophy as the memory-splicing step above.
register_bundle_export_for_agent 🔒
register_bundle_export_for_agent_with_history 🔒
sessions_within_total_budget 🔒
Given per-session sizes already in priority order (most-recent-first, matching sessions_for_agent’s modified_at desc sort), decide how many fit within total_cap. Returns (count_included, stopped_at_cap). Pure — no I/O — deliberately extracted so this decision is testable with tiny numbers instead of needing real MAX_TOTAL_HISTORY_BYTES- scale files on disk.