states

package
v0.156.3 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewApprovingToolsState

func NewApprovingToolsState(ctx *domain.StateContext) domain.StateHandler

NewApprovingToolsState creates a new ApprovingTools state handler

func NewBlockingToolsState added in v0.121.0

func NewBlockingToolsState(ctx *domain.StateContext) domain.StateHandler

NewBlockingToolsState creates a new BlockingTools state handler

func NewCancelledState

func NewCancelledState(ctx *domain.StateContext) domain.StateHandler

NewCancelledState creates a new Cancelled state handler

func NewCheckingQueueState

func NewCheckingQueueState(ctx *domain.StateContext) domain.StateHandler

NewCheckingQueueState creates a new CheckingQueue state handler

func NewCompletingState

func NewCompletingState(ctx *domain.StateContext) domain.StateHandler

NewCompletingState creates a new Completing state handler

func NewErrorState

func NewErrorState(ctx *domain.StateContext) domain.StateHandler

NewErrorState creates a new Error state handler

func NewEvaluatingToolsState

func NewEvaluatingToolsState(ctx *domain.StateContext) domain.StateHandler

NewEvaluatingToolsState creates a new EvaluatingTools state handler

func NewExecutingToolsState

func NewExecutingToolsState(ctx *domain.StateContext) domain.StateHandler

NewExecutingToolsState creates a new ExecutingTools state handler

func NewIdleState

func NewIdleState(ctx *domain.StateContext) domain.StateHandler

NewIdleState creates a new Idle state handler

func NewPostStreamState

func NewPostStreamState(ctx *domain.StateContext) domain.StateHandler

NewPostStreamState creates a new PostStream state handler

func NewPostToolExecutionState

func NewPostToolExecutionState(ctx *domain.StateContext) domain.StateHandler

NewPostToolExecutionState creates a new PostToolExecution state handler

func NewStoppedState

func NewStoppedState(ctx *domain.StateContext) domain.StateHandler

NewStoppedState creates a new Stopped state handler

func NewStreamingLLMState

func NewStreamingLLMState(ctx *domain.StateContext) domain.StateHandler

NewStreamingLLMState creates a new StreamingLLM state handler

Types

type ApprovingToolsState

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

ApprovingToolsState handles events in the ApprovingTools state.

This state manages sequential tool approval with overlapping execution:

  1. MessageReceivedEvent → initializes the tool round, starts sequential approval
  2. AllToolsProcessedEvent → transitions to PostToolExecution
  3. ApprovalFailedEvent → handles approval failures

func (*ApprovingToolsState) Handle

func (s *ApprovingToolsState) Handle(event domain.AgentEvent) error

Handle processes events in ApprovingTools state

func (*ApprovingToolsState) Name

Name returns the state this handler manages

type BlockingToolsState added in v0.121.0

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

BlockingToolsState handles events in the BlockingTools state.

This state is entered (from EvaluatingTools) when at least one tool call requires approval but that approval cannot be delivered in the current session (approval_behaviour resolves to block - e.g. approval_behaviour=block, or =ipc with no broker attached). There is no approver to prompt, so each gated tool is rejected with an actionable reason instead of being executed. Tool calls in the same batch that do NOT require approval (e.g. read-only tools, allow-listed Bash) still run, preserving tool-call order.

  1. MessageReceivedEvent → processes the batch, then emits AllToolsProcessedEvent
  2. AllToolsProcessedEvent → transitions to PostToolExecution

func (*BlockingToolsState) Handle added in v0.121.0

func (s *BlockingToolsState) Handle(event domain.AgentEvent) error

Handle processes events in BlockingTools state

func (*BlockingToolsState) Name added in v0.121.0

Name returns the state this handler manages

type CancelledState

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

CancelledState handles events in the Cancelled state.

The Cancelled state is a terminal state reached when the agent is cancelled by the user. The event loop will exit when this state is reached.

func (*CancelledState) Handle

func (s *CancelledState) Handle(event domain.AgentEvent) error

Handle processes events in Cancelled state This is a terminal state, so no events are expected

func (*CancelledState) Name

Name returns the state this handler manages

type CheckingQueueState

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

CheckingQueueState handles events in the CheckingQueue state.

This state evaluates conditions to determine the next action:

  1. Tool results pending → must respond to tools first (StreamingLLM)
  2. Messages queued → drain queue into conversation
  3. Can complete → transition to Completing
  4. Otherwise → continue agent loop (StreamingLLM)

The turn does NOT wait in-state for background work. Background-job completion notes are drained from the queue here (when the chat-UI ticker or headless waiter starts a fresh turn), so Idle stays terminal.

func (*CheckingQueueState) Handle

func (s *CheckingQueueState) Handle(event domain.AgentEvent) error

Handle processes events in CheckingQueue state

func (*CheckingQueueState) Name

Name returns the state this handler manages

type CompletingState

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

CompletingState handles events in the Completing state.

This state finalizes the agent execution:

  1. Performs a final 20ms queue check
  2. If messages queued → restart agent (CheckingQueue)
  3. Otherwise → publish completion event and transition to Idle

func (*CompletingState) Handle

func (s *CompletingState) Handle(event domain.AgentEvent) error

Handle processes events in Completing state. Completion is driven solely by CompletionRequestedEvent (emitted right after the transition into Completing); any other event is ignored so a stray wake-up cannot finalize the agent.

func (*CompletingState) Name

Name returns the state this handler manages

type ErrorState

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

ErrorState handles events in the Error state.

The Error state is a terminal state reached when unrecoverable errors occur. The event loop will exit when this state is reached.

func (*ErrorState) Handle

func (s *ErrorState) Handle(event domain.AgentEvent) error

Handle processes events in Error state This is a terminal state, so no events are expected

func (*ErrorState) Name

Name returns the state this handler manages

type EvaluatingToolsState

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

EvaluatingToolsState handles events in the EvaluatingTools state.

This state:

  1. Publishes chat complete event with tool calls
  2. Checks if any tool requires approval
  3. If approval needed → ApprovingTools
  4. Otherwise → ExecutingTools (starts background execution)

func (*EvaluatingToolsState) Handle

func (s *EvaluatingToolsState) Handle(event domain.AgentEvent) error

Handle processes events in EvaluatingTools state

func (*EvaluatingToolsState) Name

Name returns the state this handler manages

type ExecutingToolsState

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

ExecutingToolsState handles events in the ExecutingTools state.

This state processes tool execution completion:

  1. ToolsCompletedEvent (Stop=false) → transitions to PostToolExecution
  2. ToolsCompletedEvent (Stop=true) → transitions to the Stopped terminal (a rejected tool or a successful RequestPlanApproval ended the loop)

func (*ExecutingToolsState) Handle

func (s *ExecutingToolsState) Handle(event domain.AgentEvent) error

Handle processes events in ExecutingTools state

func (*ExecutingToolsState) Name

Name returns the state this handler manages

type IdleState

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

IdleState handles events in the Idle state.

The Idle state is the initial and final resting state of the agent. When a MessageReceivedEvent arrives, it transitions to CheckingQueue to begin processing.

func (*IdleState) Handle

func (s *IdleState) Handle(event domain.AgentEvent) error

Handle processes events in Idle state

func (*IdleState) Name

Name returns the state this handler manages

type PostStreamState

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

PostStreamState handles events in the PostStream state.

This state:

  1. Stores assistant message to conversation
  2. Checks if messages were queued during stream → CheckingQueue
  3. If tool calls exist → EvaluatingTools
  4. If no tools and can complete → Completing
  5. Otherwise → CheckingQueue

func (*PostStreamState) Handle

func (s *PostStreamState) Handle(event domain.AgentEvent) error

Handle processes events in PostStream state

func (*PostStreamState) Name

Name returns the state this handler manages

type PostToolExecutionState

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

PostToolExecutionState handles events in the PostToolExecution state.

This state:

  1. Checks if messages were queued during tool execution → drains and goes to CheckingQueue
  2. Checks if can complete → Completing
  3. Otherwise → CheckingQueue for next turn

func (*PostToolExecutionState) Handle

func (s *PostToolExecutionState) Handle(event domain.AgentEvent) error

Handle processes events in PostToolExecution state

func (*PostToolExecutionState) Name

Name returns the state this handler manages

type StoppedState

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

StoppedState handles events in the Stopped state.

The Stopped state is a terminal state reached when the agent stops execution (e.g., due to tool rejection or other stop conditions). The event loop will exit when this state is reached.

func (*StoppedState) Handle

func (s *StoppedState) Handle(event domain.AgentEvent) error

Handle processes events in Stopped state This is a terminal state, so no events are expected

func (*StoppedState) Name

Name returns the state this handler manages

type StreamingLLMState

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

StreamingLLMState handles events in the StreamingLLM state.

This state manages LLM streaming:

  1. StartStreamingEvent → launches background streaming goroutine
  2. StreamCompletedEvent → processes completed stream, stores data, transitions to PostStream

func (*StreamingLLMState) Handle

func (s *StreamingLLMState) Handle(event domain.AgentEvent) error

Handle processes events in StreamingLLM state

func (*StreamingLLMState) Name

Name returns the state this handler manages

Jump to

Keyboard shortcuts

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