brain

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package brain is the orchestration loop (the plan's component 3): a stateless harness that claims model_turn work, replays the session's event log into a provider request, streams the model's turn back into Anthropic-native events, and drives the session state machine at turn end. It never runs tools in-process — a tool call is an emitted intent event, and the turn resumes when the matching result event lands (a fresh model_turn item enqueued by the control plane). Any brain can pick up any turn: all durable state is the event log.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Brain

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

Brain runs model turns. All instances are interchangeable ("cattle"): a crashed brain's lease expires and any other replays the session.

func New

func New(pool *pgxpool.Pool, registry *provider.Registry, cfg Config) *Brain

func (*Brain) Run

func (b *Brain) Run(ctx context.Context) error

Run claims and executes turns until the context ends. Infra errors are logged and retried — the turn's lease expires and is reclaimed.

func (*Brain) RunOnce

func (b *Brain) RunOnce(ctx context.Context) (bool, error)

RunOnce claims at most one model_turn and runs it to completion, reporting whether there was work.

type Config

type Config struct {
	// LeaseTTL is the work-item lease; the lease keeper re-extends it at
	// TTL/3 for as long as the turn is streaming.
	LeaseTTL time.Duration
	// PollInterval is the idle wait between empty queue checks.
	PollInterval time.Duration
}

Config sizes the loop.

Jump to

Keyboard shortcuts

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