turnrunner

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const EmptyResponseFallback = "I processed your message but couldn't formulate a visible response. Could you try rephrasing your question?"

EmptyResponseFallback is used only for truly empty successful turns.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	IdleTimeout time.Duration
	HardCeiling time.Duration
	TraceStore  turntrace.Store

	// DelegationBudgetMax is the delegation count threshold for budget warnings.
	// Zero means use default (15).
	DelegationBudgetMax int
}

Config controls runner timeouts and durable trace storage.

type Executor

type Executor interface {
	RunStreamingDetailed(
		ctx context.Context,
		sessionID, input string,
		onChunk adk.ChunkCallback,
		opts ...adk.RunOption,
	) (adk.RunReport, error)
}

Executor is the subset of adk.Agent used by the runner.

type Request

type Request struct {
	SessionKey string
	Input      string
	Entrypoint string
	OnChunk    func(string)
	OnWarning  func(elapsed, hardCeiling time.Duration)

	// OnDelegation is called when a delegation event is observed in the trace.
	// from/to are agent names, reason is optional context.
	OnDelegation func(from, to, reason string)

	// OnBudgetWarning is called when delegation count approaches the threshold.
	OnBudgetWarning func(used, max int)

	// OnToolCall is called when a tool invocation begins.
	OnToolCall func(callID, toolName string, params map[string]any)

	// OnToolResult is called when a tool invocation completes.
	OnToolResult func(callID, toolName string, success bool, duration time.Duration, preview string)

	// OnThinking is called when thinking/reasoning is detected via genai.Part.Thought.
	// started=true means thinking began (summary is the thought text);
	// started=false means thinking ended.
	OnThinking func(agentName string, started bool, summary string)
}

Request is a single turn execution request.

type Result

type Result struct {
	ResponseText    string
	Outcome         TurnOutcome
	TraceID         string
	UserMessage     string
	Elapsed         time.Duration
	ErrorCode       string
	CauseClass      string
	CauseDetail     string
	OperatorSummary string
	Summary         string
}

Result is the structured result of a completed turn.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner owns timeout handling, durable tracing, and outcome classification.

func New

func New(
	cfg Config,
	executor Executor,
	sessionStore langosession.Store,
	sanitizer Sanitizer,
) *Runner

New creates a new turn runner.

func (*Runner) OnTurnComplete

func (r *Runner) OnTurnComplete(cb TurnCallback)

OnTurnComplete registers a callback fired after each completed turn.

func (*Runner) Run

func (r *Runner) Run(parent context.Context, req Request) (Result, error)

Run executes a single turn through the shared runtime.

type Sanitizer

type Sanitizer interface {
	Enabled() bool
	Sanitize(string) string
}

Sanitizer is the subset of gatekeeper.Sanitizer needed by the runner.

type TurnCallback

type TurnCallback func(sessionKey string)

TurnCallback fires after a turn finishes.

type TurnOutcome

type TurnOutcome = turntrace.Outcome

TurnOutcome is the shared classification for a completed turn.

Jump to

Keyboard shortcuts

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