Skip to main content

Crate megacode_agent_sdk

Crate megacode_agent_sdk 

Source
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.
ApprovalRequest
approval_request: a gate waiting for an answer.
CancelSignal
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.
ContextState
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
reasoning and assistant: 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.
ToolContext
What a call runs with (R8.4.4).
ToolOutput
A tool’s answer (R8.4.2): text, or text and one image.
ToolResult
tool_result.
ToolUse
tool_use.
TurnResult
result: the end of a turn.
TurnStream
One turn’s events, user to result (from query, init first).
Usage
A turn’s token counts.
UserMessage
user: a message that joined the conversation.

Enums§

ApprovalDecision
approval.decision: what a gate decided.
ApprovalKind
approval_request.kind: why a gate asks.
Choice
One of an approval_request’s choices.
Compaction
What compact did (R8.1.2).
Decision
An answer to an approval request (R8.3.1): the protocol’s decisions.
Disposition
A command’s outcome, from its response line.
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).
SystemPrompt
How the program’s text forms the system prompt (R2.3).
ToolStatus
tool_result.status.
TurnState
get_state.turn.
UserKind
user.kind.

Functions§

query
Starts a session, sends prompt, and yields init and then that turn’s events up to its result; then the session is closed (R8.1.1).