Help us shape the future of Go! Take the 2026 Go Developer Survey

state

package
v0.2.7 Latest Latest
Warning

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

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

Documentation

Overview

Package state holds all mutable state of one loop run behind one mutex. Nothing else in loop keeps shared state, so this is the only place to look for data races.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	MaxIterations *int
	Temperature   *float64
}

Change is a change to Settings. Nil fields are left unchanged.

type Run

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

Run is one run's state. settings.go and usage.go hold the rest of its methods.

func New

func New(settings Settings) *Run

func (*Run) AddUsage

func (r *Run) AddUsage(msg *schema.Message)

AddUsage adds the token usage reported on an assistant message.

func (*Run) Append

func (r *Run) Append(msg *schema.Message)

func (*Run) Apply

func (r *Run) Apply(c Change)

Apply changes the settings.

func (*Run) Begin

func (r *Run) Begin(msgs []*schema.Message) bool

Begin moves Idle to Running with a copy of the starting messages. It returns false if the run had already started.

func (*Run) Fail

func (r *Run) Fail(msg string)

Fail records a fatal error.

func (*Run) Iteration

func (r *Run) Iteration() int

Iteration is the number of model calls started so far.

func (*Run) LastError

func (r *Run) LastError() string

func (*Run) LastReply

func (r *Run) LastReply() string

LastReply returns the text of the model's latest reply that had any, or "" when there is none.

func (*Run) MarkDoneIfRunning

func (r *Run) MarkDoneIfRunning()

MarkDoneIfRunning settles a run that ended without a more specific status.

func (*Run) MaxIterations

func (r *Run) MaxIterations() int

func (*Run) Messages

func (r *Run) Messages() []*schema.Message

Messages returns a copy of the conversation as it stands now.

func (*Run) NextIteration

func (r *Run) NextIteration() int

NextIteration counts one more model call and returns its number.

func (*Run) Result

func (r *Run) Result() (event.DoneData, bool)

Result returns the outcome. ok is false until the run has ended.

func (*Run) SetResult

func (r *Run) SetResult(d event.DoneData)

SetResult records the run's outcome.

func (*Run) SetStatus

func (r *Run) SetStatus(s Status)

func (*Run) Status

func (r *Run) Status() Status

func (*Run) TakeUnlogged

func (r *Run) TakeUnlogged() (start int, added []*schema.Message)

TakeUnlogged returns the messages added since the last call, and the index of the first one.

func (*Run) Temperature

func (r *Run) Temperature() float64

func (*Run) Usage

func (r *Run) Usage() Usage

Usage returns a snapshot of the token use so far.

type Settings

type Settings struct {
	MaxIterations int
	Temperature   float64
}

Settings are the parts of the configuration a caller may change while the loop runs.

type Status

type Status string

Status is the lifecycle state of a run.

const (
	// Idle is the state before Start.
	Idle Status = "idle"
	// Running is the state between Start and the done event.
	Running Status = "running"
	// Done means the loop ended on its own: finished, max iterations,
	// timeout, or handed over to a human.
	Done Status = "done"
	// Stopped means the loop ended because it was told to stop.
	Stopped Status = "stopped"
	// Error means the loop ended on a fatal error.
	Error Status = "error"
)

type Usage

type Usage struct {
	Input     int
	Output    int
	TotalOnly int // totals a provider reported without an input/output split
	Model     string
}

Usage is the token use of a run so far.

func (Usage) Summary

func (u Usage) Summary() event.LLMUsageSummary

Jump to

Keyboard shortcuts

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