Goal: let Agent-Host and other Go applications use Offload as an execution
component without launching the Offload CLI. Import
github.com/zhoushoujianwork/offload/pkg/execution and call the same execution
entry point used by the CLI. Native Claude/Codex processes still own their model
and tool loops.
The caller owns tasks, authorization, Agent/project routing, context and Skills, session compatibility, business acceptance, delivery and durable application memory. Offload owns native backend invocation, supported tool restrictions, events, cancellation, timeout and process cleanup. Execution completion never implies business acceptance or memory publication.
Configuration is explicit: construct a client with a resolved profile, or load a
named profile from an explicit absolute configuration path. A Claude profile with
AuthMode: "native" uses the installed Claude Code's official login and needs no
BaseURL, Token or TokenCmd; an empty AuthMode is the gateway mode. A request supplies
the task, working directory, internal instructions and optional native session.
The caller cancels through its context; the package installs no process-wide
signal handlers and does not change cwd or environment.
cfg, err := execution.LoadConfig("/absolute/offload/config.json", "host-profile")
if err != nil { return err }
client, err := execution.New(cfg)
if err != nil { return err }
result, err := client.Run(ctx, execution.Request{
Caller: "agh", CallerRunID: "agh:task-123",
RecordHistory: true, // Optional: include this run in Offload Monitor/history.
Directory: "/absolute/project", Task: "Inspect the retry behavior.",
Instructions: []byte("Report evidence and any unresolved conditions."),
})
// Inspect err and result independently; persist private evidence under Host policy.
// Also inspect result.HistoryError; a log failure does not undo execution.- Public configuration, request, result and raw native event types, with no
internaltypes in the exported API. - Fresh execution and explicit continuation on Claude/Codex, additional directories, existing supported tool controls and per-request deadlines.
- Private result evidence and ordered, bounded native output callbacks.
- Optional shared history writes let Monitor retain completed, failed and canceled package calls; recording is off by default for existing consumers.
- One execution implementation for the library and existing CLI; preserve CLI flags, JSON, history, transcript, scheduling and thread behavior.
- Concurrent independent calls in one process have distinct execution records.
- Independent consumer-module tests use fake native executables, not live models.
The library performs no automatic retry, profile fallback or salvage by default. The CLI explicitly retains its existing opt-in/default report-salvage behavior. Callers serialize turns that share a native session and retain the session's compatible profile, account and workspace; a session ID alone grants no access.
This delivery makes Offload importable. It does not switch Agent-Host's current CLI adapter, implement dynamic MCP injection, token deltas, interactive approvals or automatic session migration. Existing Offload user config/account/state homes remain process-wide; per-client homes and an application-specific prompt policy require a separate contract. Native events are backend records, not a promise of a normalized or complete UI transcript.
API, compatibility and validation details.
For authorization-bound runtime setup, injection receipts and reference-based handoff, see AGH context execution.
Optional Request.Native controls let an embedding Host preserve Claude session
IDs/forks, exact MCP and Skills mounts, permissions, structured extraction and
image input through the same worker. Codex image input requires its explicit
app-server mode; legacy Codex execution still rejects it. CallerContext keeps
caller-supplied instructions and task separate from Offload's delegation role.
Set Caller and CallerRunID on business and internal requests so history keeps attribution.
Unsupported backend controls fail before launch; ordinary Codex requests remain
supported. This adds no Host policy, message routing or automatic session adoption.
The worker drains native output independently of callback latency and retains native exit/error evidence. See the control contract.
Set Request.Monitor = &execution.MonitorOptions{CaptureTranscript: true}
and RecordHistory: true for per-run Stop and bounded live/replayable output.
Stop cancels only that execution context, including concurrent calls in one Host
process. Check Result.MonitorError separately from execution and history.
To offer Resume, supply ResumeCommand (exact argv beginning with an absolute
executable) and ResumeDirectory (absolute directory). The command must re-enter
the owning Host's validated session; omit it when that cannot be reconstructed.
A dedicated continuation may pass MonitorResumeSource() as ResumedFrom to
link the new run. This metadata grants no execution permissions.
See task controls.
execution.ReadTranscript(execution.TranscriptReadOptions{RunID, CallerRunID, Cursor, Limit, MaxBytes})
and execution.ListTranscripts(callerRunID, limit) read what CaptureTranscript wrote. They wrap the
same reader as offload transcript read|list --json, and the response types are aliases, so the JSON is
identical. Reading opens only the requested run's file, starts no backend and uses no worker slot.
A missing run or invalid cursor is reported in Availability and Reason (not_found,
cursor_invalid), not as an error. Page by passing NextCursor back as Cursor while HasMore is true.
See transcripts.