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

sessbind

package
v0.4.43 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const SubagentModelWildcardKey agentkit.AgentID = "sub:*"

SubagentModelWildcardKey is the global models key that applies to every in-process subagent without a more specific entry. Written by `/submodel * <model>`; it never affects the main agent.

Variables

Priority lists every level coarse-to-fine. Resolution walks it in reverse so finer scopes win. It is the single ordering shared by every binding kind (agent, model, …), replacing per-kind if-chains.

Functions

func AgentBind

AgentBind returns the per-session agent override, or "" when unset.

func ChannelAgentBind added in v0.4.18

func ChannelAgentBind(ctx context.Context, store agentkit.SessionStore, ws workspace.Service, entryKey agentkit.SessionID) (agentkit.AgentID, error)

ChannelAgentBind returns the channel default for entryKey (stable delivery / active-entry id). Falls back to legacy local:runtime.json when tenant-scoped.

func ChannelModelBind added in v0.4.35

func ChannelModelBind(ctx context.Context, store agentkit.SessionStore, entryKey agentkit.SessionID) (string, error)

ChannelModelBind returns the channel default model for entryKey, or "" when unset. Mirrors ChannelAgentBind so agent and model share the same level stack.

func GlobalAgentBind

func GlobalAgentBind(ctx context.Context, ws workspace.Service) (agentkit.AgentID, error)

GlobalAgentBind returns the workspace-wide default agent id, or "" when unset.

func GlobalModelBind

func GlobalModelBind(ctx context.Context, ws workspace.Service, agentID agentkit.AgentID) (string, error)

GlobalModelBind returns the global default model for agentID, or "" when unset.

func GlobalModelBinds added in v0.3.59

func GlobalModelBinds(ctx context.Context, ws workspace.Service) (map[string]string, error)

GlobalModelBinds returns every entry in global:runtime.json models, or nil when unset. Commands use it to list configured overrides.

func ModelBind

func ModelBind(ctx context.Context, store agentkit.SessionStore, id agentkit.SessionID) (string, error)

ModelBind returns the per-session model override, or "" when unset.

func ResolveAgentID

func ResolveAgentID(
	ctx context.Context,
	store agentkit.SessionStore,
	ws workspace.Service,
	sessionID agentkit.SessionID,
	entryKey agentkit.SessionID,
	eventAgent agentkit.AgentID,
) (effective, sessionBind, channelBind, globalBind agentkit.AgentID, err error)

ResolveAgentID applies the shared level stack (session, user, thread, channel, global), then an explicit event agent id. The bind results are the stored values at each legacy level (session/channel/global) so existing callers and renderers keep working; thread/user are surfaced only through BindStack.

func ResolveEffectiveModel

func ResolveEffectiveModel(
	ctx context.Context,
	store agentkit.SessionStore,
	ws workspace.Service,
	sessionID agentkit.SessionID,
	agentID agentkit.AgentID,
	defaultModel string,
) (effective, sessionOverride, globalOverride string, err error)

ResolveEffectiveModel applies the shared level stack (session, user, thread, channel, global-per-agent), then defaultModel. Agent and model therefore use the identical level order and key computation; only the value/storage differ.

func ResolveSubagentModel added in v0.3.59

func ResolveSubagentModel(
	ctx context.Context,
	ws workspace.Service,
	parentAgentID agentkit.AgentID,
	childAgentID agentkit.AgentID,
	defModel string,
) string

ResolveSubagentModel resolves the model for an in-process subagent step.

Priority (definition author > explicit subagent config > general default > fallback):

  1. defModel — agents/<name>.md `model:` is a capability contract authored together with the prompt and modalities; runtime overrides never win.
  2. global models[<childAgentID>] — the explicit per-subagent config written by `/submodel <name> <model>`.
  3. global models[SubagentModelWildcardKey] — the all-subagents policy written by `/submodel * <model>`; main agent is unaffected.
  4. global models[<parentAgentID>] — the parent agent's `/model -g` choice, the general default specific keys refine.

defModel is also the final fallback when nothing else is set. Neither the child session's bind nor the parent conversation's session bind participate: per-delegation ids have no /model entry point, and the user's in-conversation /model targets the main agent only — subagent models are explicit config, not implicit inheritance.

func RuntimeStore

RuntimeStore returns the session runtime overlay capability when present.

func SetChannelAgentBind added in v0.4.18

func SetChannelAgentBind(ctx context.Context, store agentkit.SessionStore, ws workspace.Service, entryKey agentkit.SessionID, agent agentkit.AgentID) error

SetChannelAgentBind sets or clears the channel default for entryKey.

func SetChannelModelBind added in v0.4.35

func SetChannelModelBind(ctx context.Context, store agentkit.SessionStore, entryKey agentkit.SessionID, model string) error

SetChannelModelBind sets or clears the channel default model for entryKey.

func SetGlobalAgentBind

func SetGlobalAgentBind(ctx context.Context, ws workspace.Service, agent agentkit.AgentID) error

SetGlobalAgentBind sets or clears the workspace-wide default agent id.

func SetGlobalModelBind

func SetGlobalModelBind(ctx context.Context, ws workspace.Service, agentID agentkit.AgentID, model string) error

SetGlobalModelBind sets or clears the global default model for agentID.

func SetSessionAgentBind

func SetSessionAgentBind(ctx context.Context, store agentkit.SessionStore, id agentkit.SessionID, agent agentkit.AgentID) error

SetSessionAgentBind sets or clears the per-session agent override.

func SetSessionModelBind

func SetSessionModelBind(ctx context.Context, store agentkit.SessionStore, id agentkit.SessionID, model string) error

SetSessionModelBind sets or clears the per-session model override.

func ValidateCwd added in v0.4.38

func ValidateCwd(ctx context.Context, ws workspace.Service, path string) (string, error)

ValidateCwd resolves using the host workspace policy and requires an existing directory. It never creates a directory or changes the process working directory.

Types

type AgentBinding added in v0.4.35

type AgentBinding struct{}

AgentBinding is the Binding for the default-agent override.

func (AgentBinding) Key added in v0.4.35

func (AgentBinding) Key() string

func (AgentBinding) Read added in v0.4.35

func (AgentBinding) Write added in v0.4.35

type BindStack added in v0.4.35

type BindStack struct {
	Keys rctx.BindKeys
	WS   workspace.Service
}

BindStack is the keys a single resolution reads across every level.

func StackFromContext added in v0.4.35

func StackFromContext(ctx context.Context, ws workspace.Service) BindStack

StackFromContext builds the level stack for the current turn: keys from rctx.BindKeysFromContext plus the workspace handle.

func (BindStack) Effective added in v0.4.35

func (s BindStack) Effective(ctx context.Context, store agentkit.SessionStore, kind Binding) (effective string, hits map[Level]string, err error)

Effective resolves value across Priority (fine wins), returning the winner and the raw hit at every level (named in the map so callers can render "session override / channel override / …" uniformly). A level whose key is empty (e.g. Thread on a non-topic delivery) is skipped, not treated as unset.

func (BindStack) EffectiveWithLevel added in v0.4.35

func (s BindStack) EffectiveWithLevel(ctx context.Context, store agentkit.SessionStore, kind Binding) (effective string, winner Level, hits map[Level]string, err error)

EffectiveWithLevel is Effective plus the winning level (LevelNone when nothing is set), so callers can report which scope actually won instead of guessing from a non-empty finer hit.

func (BindStack) Set added in v0.4.35

func (s BindStack) Set(ctx context.Context, store agentkit.SessionStore, kind Binding, level Level, value string) error

Set writes value at level, resolving the level's key from the stack.

func (BindStack) WithChannel added in v0.4.35

func (s BindStack) WithChannel(channel agentkit.SessionID) BindStack

WithChannel overrides the channel key when non-empty (legacy callers pass an explicit entry key; the turn-derived channel key is kept otherwise).

func (BindStack) WithSession added in v0.4.35

func (s BindStack) WithSession(session agentkit.SessionID) BindStack

StackWithKeys overrides stack keys, e.g. an explicit session id or a caller-provided channel entry key.

type Binding added in v0.4.35

type Binding interface {
	// Key is a stable identifier for the kind ("agent", "model"), used in
	// messages and storage keys.
	Key() string
	// Read returns the value stored at level for key, or "" when unset.
	Read(ctx context.Context, level Level, key agentkit.SessionID, ws workspace.Service, store agentkit.SessionStore) (string, error)
	// Write stores value at level for key ("" clears).
	Write(ctx context.Context, level Level, key agentkit.SessionID, ws workspace.Service, store agentkit.SessionStore, value string) error
}

Binding identifies one dynamic-override kind. Kinds share the level stack, the key computation (rctx.BindKeys) and the priority order; only the value type and per-kind storage differ.

type ChannelRuntimeData added in v0.4.18

type ChannelRuntimeData struct {
	AgentID agentkit.AgentID `json:"agentId,omitempty"`
}

ChannelRuntimeData holds channel-scoped dynamic overrides.

type CwdBinding added in v0.4.38

type CwdBinding struct{}

CwdBinding shares session/channel keys with the catalog commands. No global, thread or user override is exposed for cwd.

func (CwdBinding) Key added in v0.4.38

func (CwdBinding) Key() string

func (CwdBinding) Read added in v0.4.38

func (CwdBinding) Write added in v0.4.38

type GlobalRuntimeData

type GlobalRuntimeData struct {
	AgentID agentkit.AgentID  `json:"agentId,omitempty"`
	Models  map[string]string `json:"models,omitempty"`
}

GlobalRuntimeData holds workspace-wide dynamic overrides.

type Level added in v0.4.35

type Level int

Level is one rung of the dynamic-binding stack, coarse to fine. Thread and User are mutually exclusive siblings: a delivery id carries :t: or :u:, not both, so at most one of them is ever present in a turn's BindKeys.

const (
	LevelGlobal Level = iota
	LevelChannel
	LevelThread
	LevelUser
	LevelSession
)
const LevelNone Level = -1

LevelNone marks "no level set a value".

func HitsFor added in v0.4.35

func HitsFor(hits map[Level]string) []Level

HitsFor renders non-empty hits in Priority order (fine first) for uniform "override" listings across binding kinds.

func ResolveModelBinding added in v0.4.35

func ResolveModelBinding(
	ctx context.Context,
	store agentkit.SessionStore,
	ws workspace.Service,
	sessionID agentkit.SessionID,
	agentID agentkit.AgentID,
	defaultModel string,
) (effective string, winner Level, hits map[Level]string, err error)

ResolveModelBinding is ResolveEffectiveModel plus the winning level and the full hit map, so the /model command can report which scope won rather than inferring it from a non-empty finer hit.

func (Level) String added in v0.4.35

func (l Level) String() string

type ModelBinding added in v0.4.35

type ModelBinding struct{ AgentID agentkit.AgentID }

ModelBinding is the Binding for the per-session default-model override. The global level is per-agent (models[<agentId>] in the workspace runtime file), so it carries its own key handling.

func (ModelBinding) Key added in v0.4.35

func (ModelBinding) Key() string

func (ModelBinding) Read added in v0.4.35

func (ModelBinding) Write added in v0.4.35

Jump to

Keyboard shortcuts

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