Skip to main content

Module agent

Module agent 

Source
Expand description

Unified agent loop for both the fake provider and the Umans provider.

The loop runs on a background thread and sends AgentEvents through a channel. The TUI drains them with try_recv, keeping the UI responsive.

§Lifecycle

  1. RunHandle::spawn starts a thread with a run configuration and cancellation token.
  2. The run emits Started, then streams reasoning/assistant deltas and tool-use requests.
  3. Each tool-use request is dispatched via tools::dispatch_full and the result is emitted as a ToolFinished event appended to the transcript.
  4. For the Umans provider, tool results are fed back into the next turn: after each dispatched tool batch, the assistant message (with tool_use blocks) and the user message (with tool_result blocks) are appended to the message history, and the provider is re-requested.
  5. The loop enforces bounded tool-budget continuations to prevent recursive or unbounded tool-call loops while still allowing longer useful runs.
  6. Cancellation is cooperative: the loop checks the shared CancelToken between events, lines, and tool executions. When cancelled, it emits AgentEvent::Cancelled and stops.

Structs§

RetryPolicy
Bounded exponential retry policy for provider requests.
RunHandle
Handle for a single agent run: provider kind, config, prompt, and cancel.

Enums§

ProviderKind
Which provider drives this agent run.
ToolPermissionDecision
Decision returned by an application-owned tool permission hook.

Functions§

prompt_expects_workspace_write
Best-effort classifier for prompts that should not finish without a workspace write. This is intentionally narrow: it requires both a file-ish reference and an edit/action verb.

Type Aliases§

ToolExecutionHook
Application-local execution override supplied to the provider-neutral run.
ToolPermissionHook
Application-local permission policy supplied to the provider-neutral run.