interrupt

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package interrupt defines the [InterruptError] sentinel used by tools and middleware to signal that a tool call needs external input (human approval, clarification answer, etc.) before it can complete.

It lives in its own package — separate from toolwrap and clarify — to avoid import cycles. Both packages depend on this one, but neither depends on the other.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Is

func Is(err error) bool

Is reports whether err is or wraps an interrupt Error.

func ResumeValueFrom

func ResumeValueFrom(ctx context.Context) (any, bool)

ResumeValueFrom extracts the resume value from ctx. Returns (nil, false) if this is a fresh (non-resumed) call.

func WithResumeValue

func WithResumeValue(ctx context.Context, val any) context.Context

WithResumeValue returns a child context carrying the given resume value. The executor calls this when re-invoking a tool after an interrupt, passing the human's answer (string for clarifications, *hitl.ApprovalRequest for approvals). Tool functions retrieve it via ResumeValueFrom.

Types

type Error

type Error struct {
	// Kind distinguishes clarification pauses from approval pauses.
	Kind Kind

	// RequestID is the unique identifier of the pending request
	// (clarification ID or approval ID).
	RequestID string

	// Payload carries kind-specific metadata:
	//   - Clarify:  clarify.ClarificationEvent
	//   - Approval: hitl.ApprovalRequest
	Payload any
}

Error signals that a tool call needs external input (human approval, clarification, etc.) before it can complete.

In the current in-process executor (blocking mode), the middleware catches this internally and blocks on the store's wait channel — callers never see it. In a future Temporal executor (non-blocking mode), the workflow propagates the interrupt upward so it can be modelled as a Temporal signal wait.

The API mirrors [graph.InterruptError] from trpc-agent-go so that the two can be bridged without conversion when Temporal is adopted.

func Get

func Get(err error) (*Error, bool)

Get extracts an interrupt Error from err if present. Returns (nil, false) if err does not contain an interrupt Error.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

type Kind

type Kind string

Kind identifies what type of human input is required.

const (
	// Clarify indicates the tool needs the user to answer a clarifying
	// question before execution can continue.
	Clarify Kind = "clarify"

	// Approval indicates the tool call requires human approval
	// (approve / reject) before execution can proceed.
	Approval Kind = "approval"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL