Expand description
Drive a MEGA harness agent session from a Rust program.
A Client holds one session: Client::start (or
Client::resume) begins it, Client::send runs one turn and returns
its events, and the other methods steer, abort, compact or inspect it
while a turn’s events are read. query is one prompt, one turn, then
the end. A Tool given to Options::tool runs in this program when
the model calls it; an approval request is answered by
Options::on_approval’s callback, or else by the
ApprovalRequest event itself. Spec: docs/specs/slice-ar.md R8, R9.
Structs§
- Approval
approval: a gate’s decision.- Approval
Request approval_request: a gate waiting for an answer.- Cancel
Signal - A call’s cancellation signal.
- Client
- A session: cheap to clone, every method on
&self, usable while a turn’s stream is read (R8.1.2). - Compacted
compacted.- Context
State get_state.context.- Cost
- A turn’s cost.
- Denied
- A denied call.
- Diagnostics
- What is known about a session that ended unexpectedly. Every field is optional: a backend fills what it has.
- Escape
- An
approval_request’s escape. - Events
- A stream of events: a turn’s, or the session’s between turns.
- Info
init: the session’s facts.- Options
- The options a session starts (or resumes) with. Every field left unset takes R2.2’s default, which switches off everything personal.
- State
get_state’s data.- Text
reasoningandassistant: text.- Tool
- A tool the program runs (R8.4.1): a name, a description, an input schema sent to the model as given, whether it asks before every call, how long harness waits for it, and an async handler.
- Tool
Context - What a call runs with (R8.4.4).
- Tool
Output - A tool’s answer (R8.4.2): text, or text and one image.
- Tool
Result tool_result.- ToolUse
tool_use.- Turn
Result result: the end of a turn.- Turn
Stream - One turn’s events,
usertoresult(fromquery,initfirst). - Usage
- A turn’s token counts.
- User
Message user: a message that joined the conversation.
Enums§
- Approval
Decision approval.decision: what a gate decided.- Approval
Kind approval_request.kind: why a gate asks.- Choice
- One of an
approval_request’schoices. - Compaction
- What
compactdid (R8.1.2). - Decision
- An answer to an approval request (R8.3.1): the protocol’s decisions.
- Disposition
- A command’s outcome, from its
responseline. - Error
- What went wrong with a session.
- Event
- One event of a session, one per outbound line type (R8.5.1).
- Mode
- The mode a session starts in (R2.2
mode). - Outcome
result.outcome: how a turn ended.- Sandbox
- Where built-in commands run (R2.2
sandbox). - System
Prompt - How the program’s text forms the system prompt (R2.3).
- Tool
Status tool_result.status.- Turn
State get_state.turn.- User
Kind user.kind.
Functions§
- query
- Starts a session, sends
prompt, and yieldsinitand then that turn’s events up to itsresult; then the session is closed (R8.1.1).