Skip to main content

Abort

AbortSignal provides cooperative cancellation for running agent invocations. It cleanly terminates LLM streaming and tool execution.

Basic Usage

What Happens on Abort

During LLM Streaming

  1. The streaming connection is terminated
  2. Whatever content was received so far is preserved
  3. The runtime produces an internal truncation patch with:
    • partial_content — what was received before abort
    • abort_reason — the reason you provided
  4. The ReAct loop terminates via the finalize path

During Tool Execution

  1. Running tools are cancelled (asyncio task cancellation)
  2. For each cancelled tool, the runtime produces an internal cancellation patch with:
    • tool_call_id — which call was cancelled
    • tool_name — the tool that was running
    • abort_reason — your reason
  3. This ensures the transcript stays structurally valid (every tool call has a result)

The Guarantee

Abort always produces a valid final state. The transcript is never left with dangling tool calls or incomplete messages. Internal transcript patches ensure structural consistency.

Abort in @llm_function

Works the same way:

TUI Integration

The built-in @tui decorator handles abort automatically — Ctrl+C triggers the signal:

Checking Abort State

Practical Pattern: Timeout

API Reference: Events