Documentation
¶
Index ¶
- Constants
- Variables
- func SubjectPromptRequested(runID string) event.Subject
- type AckMode
- type AskUserFunc
- type Authority
- type BaseSessionObserver
- type CatalogProvider
- type CatalogProviderFunc
- type DeliveryCursor
- type HostFactory
- type HostFactoryFunc
- type HostRequest
- type InstanceResolver
- type Key
- type Lease
- type Manager
- type ManagerOption
- func WithCatalogProvider(provider CatalogProvider) ManagerOption
- func WithCheckpointStore(store agent.CheckpointStore) ManagerOption
- func WithDeliveryConcurrency(limit int) ManagerOption
- func WithIdleTimeout(timeout time.Duration) ManagerOption
- func WithMaxSessions(limit int) ManagerOption
- func WithResume(enable bool) ManagerOption
- func WithSessionObserver(observer SessionObserver) ManagerOption
- func WithSinkBufferSize(size int) ManagerOption
- func WithSpeculativeBufferLimits(events, bytes int) ManagerOption
- type PromptRequested
- type Session
- type SessionObserver
- type SinkSpec
- type Turn
- func (t *Turn) Ack(sinkID string, cursor DeliveryCursor) error
- func (t *Turn) After(_ context.Context, _ agent.Identity, _ *agent.Request, res *agent.Result) (agent.Decision, error)
- func (t *Turn) CommitView(_ context.Context, _ agent.Identity, _ *agent.Request, res *agent.Result) (agent.CommitView, error)
- func (t *Turn) Interrupt(interrupt agent.Interrupt) error
- func (t *Turn) OnInterrupt(context.Context, agent.Identity, agent.Interrupt)
- func (t *Turn) OnRunEnd(context.Context, agent.Identity, *agent.Result)
- func (t *Turn) OnRunRevise(_ context.Context, _ agent.Identity, _ *agent.Result, nextAttempt int)
- func (t *Turn) OnRunStart(context.Context, agent.Identity, *agent.Request)
- func (t *Turn) Reply(ctx context.Context, promptID string, reply agent.UserReply) error
- func (t *Turn) RunID() string
- func (t *Turn) State() TurnState
- func (t *Turn) Wait(ctx context.Context) (*agent.Result, error)
- type TurnState
- type Visibility
Constants ¶
const HeaderDeliveryCursor = "session_delivery_cursor"
HeaderDeliveryCursor carries a confirmed delivery cursor in an envelope.
Variables ¶
var ( ErrSessionClosed = errdefs.NotAvailablef("runtime session: session is closed") ErrPromptUnknown = errdefs.NotFoundf("runtime session: prompt is unknown") ErrPromptDuplicate = errdefs.Conflictf("runtime session: prompt was already replied") ErrPromptClosed = errdefs.NotAvailablef("runtime session: prompt is closed") ErrSinkQueueFull = errdefs.BudgetExceededf("runtime session: sink queue is full") )
var ErrManagerClosed = errdefs.NotAvailablef("runtime session: manager is closed")
Functions ¶
func SubjectPromptRequested ¶
SubjectPromptRequested returns the run-scoped prompt request subject.
Types ¶
type AckMode ¶
type AckMode string
const ( // AckOnDelivery acknowledges a confirmed delivery only after Sink.OnDelta // returns nil. If the turn is interrupted while the callback is still // running, that delivery is outside the frozen acknowledged prefix. AckOnDelivery AckMode = "" // AckExplicit requires the authoritative sink to call Turn.Ack. The sink // may acknowledge the cursor currently offered to its OnDelta callback // before that callback returns. AckExplicit AckMode = "explicit" )
type AskUserFunc ¶
AskUserFunc is the turn-scoped user-prompt callback supplied to a Host.
type BaseSessionObserver ¶
type BaseSessionObserver struct{}
BaseSessionObserver provides no-op default implementations of every SessionObserver method.
func (BaseSessionObserver) OnSessionClosed ¶
func (BaseSessionObserver) OnSessionClosed(*Session, error)
OnSessionClosed is a no-op.
func (BaseSessionObserver) OnSessionClosing ¶
func (BaseSessionObserver) OnSessionClosing(*Session)
OnSessionClosing is a no-op.
func (BaseSessionObserver) OnSessionStarted ¶
func (BaseSessionObserver) OnSessionStarted(*Session, *Turn)
OnSessionStarted is a no-op.
func (BaseSessionObserver) OnTurnFinished ¶
OnTurnFinished is a no-op.
type CatalogProvider ¶
type CatalogProvider interface {
NewCatalog(ctx context.Context, instance *agent.Agent) (tool.Session, error)
}
CatalogProvider constructs the per-session tool catalog. The provider runs once per Session (on its first Start) and its result is attached to every turn's execution context, where session-scoped tools (tool_search) and the inference node's all_tools mode pick it up. The Session borrows the catalog.
The provider returns the session-scoped tool.Session (hosts typically use tool.Assembly.NewSession), so the dynamic injection view and the plain catalog share one contract.
type CatalogProviderFunc ¶
CatalogProviderFunc adapts a plain function to CatalogProvider.
func (CatalogProviderFunc) NewCatalog ¶
func (f CatalogProviderFunc) NewCatalog(ctx context.Context, instance *agent.Agent) (tool.Session, error)
NewCatalog implements CatalogProvider.
type DeliveryCursor ¶
type DeliveryCursor uint64
DeliveryCursor is a turn-global, contiguous confirmed-delivery position.
func DeliveryCursorFromEnvelope ¶
func DeliveryCursorFromEnvelope(env event.Envelope) (DeliveryCursor, error)
DeliveryCursorFromEnvelope reads the confirmed delivery cursor.
type HostFactory ¶
HostFactory constructs a fresh Host for one turn.
type HostFactoryFunc ¶
HostFactoryFunc adapts a function to HostFactory.
func (HostFactoryFunc) NewHost ¶
func (f HostFactoryFunc) NewHost(ctx context.Context, request HostRequest) (agent.Host, error)
NewHost implements HostFactory.
type HostRequest ¶
type HostRequest struct {
Key Key
RunID string
Interrupts <-chan agent.Interrupt
AskUser AskUserFunc
}
HostRequest contains the per-turn capabilities needed to construct a Host.
func (HostRequest) Validate ¶
func (r HostRequest) Validate() error
Validate checks the required host-construction contract.
type InstanceResolver ¶
InstanceResolver is the minimum borrowed deployment view needed by Manager.
type Key ¶
Key identifies one conversational session. AgentID is part of the identity: two agents using the same ContextID do not share session state.
type Lease ¶
type Lease struct {
// contains filtered or unexported fields
}
Lease keeps a shared Session retained by its Manager.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager shares Sessions by Key and reclaims unleased idle Sessions. It borrows its resolver, HostFactory, and event router and never closes them.
func NewManager ¶
func NewManager( resolver InstanceResolver, hostFactory HostFactory, router *event.Router, options ...ManagerOption, ) (*Manager, error)
NewManager constructs a Session manager over borrowed runtime dependencies.
func (*Manager) Close ¶
Close stops reclamation, refuses new leases, and closes every Session. Borrowed deployment, router, and host dependencies remain owned by Runtime.
func (*Manager) GetOrCreate ¶
GetOrCreate lazily creates a Session and returns an independent Lease.
type ManagerOption ¶
type ManagerOption func(*managerOptions) error
ManagerOption configures a Manager.
func WithCatalogProvider ¶
func WithCatalogProvider(provider CatalogProvider) ManagerOption
WithCatalogProvider wires a per-session tool catalog provider. When set, every Session created by this Manager builds one catalog on its first Start, attaches it to each turn's execution context, and closes it when the Session closes.
func WithCheckpointStore ¶
func WithCheckpointStore(store agent.CheckpointStore) ManagerOption
WithCheckpointStore wires the store used for end-to-end resume. It is required when WithResume is enabled.
func WithDeliveryConcurrency ¶
func WithDeliveryConcurrency(limit int) ManagerOption
WithDeliveryConcurrency bounds how many sink callbacks may be in flight concurrently for one sink.
func WithIdleTimeout ¶
func WithIdleTimeout(timeout time.Duration) ManagerOption
WithIdleTimeout sets how long an unleased, idle Session is retained.
func WithMaxSessions ¶
func WithMaxSessions(limit int) ManagerOption
WithMaxSessions bounds the number of distinct live sessions the manager retains. Values <= 0 leave the manager default (1024).
func WithResume ¶
func WithResume(enable bool) ManagerOption
WithResume enables session-level resume: each session key maps to a stable run id, checkpoints are loaded before Start, and committed checkpoints are deleted after completion.
func WithSessionObserver ¶
func WithSessionObserver(observer SessionObserver) ManagerOption
WithSessionObserver attaches a session-level lifecycle observer to every Session created by this Manager. See SessionObserver for the callback contract.
func WithSinkBufferSize ¶
func WithSinkBufferSize(size int) ManagerOption
WithSinkBufferSize sets the queue size used when SinkSpec.QueueSize is zero.
func WithSpeculativeBufferLimits ¶
func WithSpeculativeBufferLimits(events, bytes int) ManagerOption
WithSpeculativeBufferLimits bounds aggregate pending confirmed branch data per turn.
type PromptRequested ¶
type PromptRequested struct {
RunID string `json:"run_id"`
TurnID string `json:"turn_id"`
PromptID string `json:"prompt_id"`
Prompt agent.UserPrompt `json:"prompt"`
}
PromptRequested is published when a turn begins waiting for user input.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session owns conversational activity for one Key while borrowing all deployment and event-routing dependencies from the runtime.
type SessionObserver ¶
type SessionObserver interface {
// OnSessionStarted fires after Start successfully scheduled a new turn
// and before Start returns to its caller. turn is the running turn.
OnSessionStarted(session *Session, turn *Turn)
// OnSessionClosing fires exactly once when the Session begins closing,
// covering explicit close, idle timeout reclamation, and Manager
// shutdown. Active turns may still be finalizing at this point.
OnSessionClosing(session *Session)
// OnSessionClosed fires exactly once after closing completed and any
// active turn has been shut down and awaited. err is the close error,
// or nil on a clean close.
OnSessionClosed(session *Session, err error)
// OnTurnFinished fires when a turn reaches its terminal state.
// result and err are the same values Turn.Wait returns.
// It is called before Turn.Wait unblocks, so observers MUST NOT call
// Turn.Wait from this callback.
OnTurnFinished(session *Session, turn *Turn, result *agent.Result, err error)
}
SessionObserver observes session-level lifecycle transitions without affecting their outcome. It is the public hook for metrics, tracing, and accounting that wants the session view (Key, RunID, terminal outcome) rather than per-run agent events.
Concurrency contract:
- Every method is called synchronously from the goroutine performing the transition, outside Session and Manager locks.
- Implementations must return promptly and MUST NOT call back into Session or Manager methods; long-running side effects must be dispatched asynchronously by the observer itself.
- Implementations must be safe for concurrent use: SessionStarted and TurnFinished can be called from a turn goroutine while Closing and Closed run on a close/reclaim goroutine.
Embed BaseSessionObserver to satisfy the interface with no-op defaults when only a subset of the lifecycle is interesting.
type SinkSpec ¶
type SinkSpec struct {
ID string
Sink agent.StreamSink
QueueSize int
// DeliveryTimeout bounds each Sink.OnDelta call. Zero uses the 30-second
// runtime default; a sink that exceeds the deadline is detached.
DeliveryTimeout time.Duration
OnDetach func(error)
Visibility Visibility
Authority Authority
// AckMode controls when confirmed authoritative deliveries become part of
// the committable prefix. See AckOnDelivery and AckExplicit.
AckMode AckMode
MaxUnacked int
}
SinkSpec describes one independently buffered stream attachment.
type Turn ¶
type Turn struct {
// contains filtered or unexported fields
}
Turn is one asynchronous execution owned by a Session.
func (*Turn) Ack ¶
func (t *Turn) Ack(sinkID string, cursor DeliveryCursor) error
Ack cumulatively acknowledges confirmed deliveries from the authoritative explicit sink. It may be called from Sink.OnDelta for the cursor currently being offered to that callback.
func (*Turn) After ¶
func (t *Turn) After(_ context.Context, _ agent.Identity, _ *agent.Request, res *agent.Result) (agent.Decision, error)
After implements the turn-scoped interruption referee.
func (*Turn) CommitView ¶
func (t *Turn) CommitView(_ context.Context, _ agent.Identity, _ *agent.Request, res *agent.Result) (agent.CommitView, error)
CommitView implements the turn-scoped Committer projection.
func (*Turn) OnInterrupt ¶
OnInterrupt implements agent.Observer. Turn.finish owns logical completion.
func (*Turn) OnRunRevise ¶
func (t *Turn) OnRunRevise( _ context.Context, _ agent.Identity, _ *agent.Result, nextAttempt int, )
OnRunRevise moves commit authority to the next attempt while preserving turn-global delivery and acknowledgement cursors.
func (*Turn) OnRunStart ¶
OnRunStart implements agent.Observer.
type TurnState ¶
type TurnState string
TurnState is the externally observable lifecycle state of a Turn.
const ( TurnStarting TurnState = "starting" TurnRunning TurnState = "running" TurnInterrupting TurnState = "interrupting" TurnCompleted TurnState = "completed" TurnInterrupted TurnState = "interrupted" TurnCanceled TurnState = "canceled" TurnFailed TurnState = "failed" TurnAborted TurnState = "aborted" )
type Visibility ¶
type Visibility string
const ( VisibilityRaw Visibility = "" VisibilityConfirmed Visibility = "confirmed" )