Expand description
Drive model context through generation and tool calls at replayable boundaries. Callers supply tool execution, event sinks, context, and persistence callbacks.
§Embedding
Construct Agent with a [GenerativeModel], ToolExecutor, and EventSink.
Supply input with Agent::append_input or install history with
Agent::replace_context, then await Agent::run. The crate does not read
Myco configuration or create sessions, prompts, hosts, or terminal output.
§Ownership and persistence
The executor owns live resources independently of agent history. Calls within a round run concurrently; results are recorded in call order. Checkpoints persist pending effects and their settled observations. Pending tool batches are durable intent, not replayable model context; recover them before reuse.
Cancel a clone of the run’s CancelToken and await the run future to let
cleanup finish. Aborting the task bypasses that cooperative completion path.
EventSink provides live observations, not a complete durable event log.
See the agent guide and
run cargo run -p myco-agent --example headless for an offline model/tool round.
Structs§
- Agent
- A headless model/tool loop over caller-supplied context and capabilities.
- Agent
State - Context and control state, without a model, executor, clock, or event sink. Every transition is synchronous; the caller interprets returned effects.
- Cancel
Token - A token which can be used to signal a cancellation request to one or more tasks.
- Null
Event Sink - No-op sink for tests and headless runs.
- Operation
Id - RunOutcome
- A run ending at an output cap is distinct from a completed model turn.
- Trace
Context - Event attribution for frontends and evaluators. Session and thread are present when bound; depth lets displays distinguish nested workers.
Enums§
- Agent
Event - Live events emitted by the agent runtime.
- Agent
Interaction Error - Effect
- Pending
Operation - Durable intent. A tool intent without its result is an unknown external effect after restart, even when dispatch may not actually have begun.
- State
Error
Constants§
- CONTINUE_
PROMPT - The user turn sent to resume a reply that
max_tokenscut off mid-text. - DEFAULT_
MAX_ TRUNCATED_ RESUMES
Traits§
- Event
Sink - Consumer of
AgentEvents (CLI, TUI, metrics, …). - Tool
Executor - Capabilities available to this execution. Ownership and routing belong to the caller.
Functions§
- recover_
checkpoint - Recover observations without reissuing any pending operation. The caller must persist this context before allowing new effects.
- validate_
checkpoint - validate_
context - Every tool call has exactly one result in the immediately following batch.
Type Aliases§
- Async
- Before
Generation Notice - Supply a pending runtime notice before a generation step. The returned text is appended as internal system content to the latest user input or tool result and checkpointed before generation; this callback does not reload the system prompt. Retries reuse the same input. Consume the notice only when the future completes, since cancellation can drop the future.
- Checkpoint
- Persist context and pending intent before effects begin, and completed observations before the next effect. Failure stops execution. A pending tool batch is a durable observation, not a valid model input or context fork.