toolcontext

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package toolcontext owns the request-scoped identity and lifecycle shared by every Memoh tool transport. It is independent of MCP, ACP, and native tool protocols so those adapters can all bind work to the same agent run.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind(callbackCtx context.Context, session Session) (context.Context, context.CancelFunc)

Bind gives a tool callback the owning run's request-scoped values and makes it stop when either the callback or the run stops. The run context is the authoritative source of tenant, identity, trace, and other turn values; transport callback contexts contribute their independent cancellation.

func ValidateRuntimeGuard

func ValidateRuntimeGuard(ctx context.Context, session Session) error

ValidateRuntimeGuard performs the last ownership check immediately before a tool effect. The check remains bound to both the request and owning run.

Types

type Session

type Session struct {
	BotID             string
	ChatID            string
	RuntimeID         string
	RuntimeToken      string `json:"-"`
	SessionID         string
	RunID             string
	ToolCallID        string
	SessionType       string
	RouteID           string
	ChannelIdentityID string
	SessionToken      string `json:"-"`
	CurrentPlatform   string
	ReplyTarget       string
	ConversationType  string
	// ReasoningStoredEffort and ReasoningRequestedEffort are unresolved turn
	// inputs. A tool that selects another model must resolve them against that
	// model instead of inheriting the parent runtime's provider-specific result.
	ReasoningStoredEffort    string
	ReasoningRequestedEffort string
	CanRequestUserInput      bool
	CanListUserInput         bool
	IsSubagent               bool
	RuntimeActive            bool
	// RequireActiveRun declares that this session's tool surface exists only
	// for the duration of a runtime turn. Workspace tool-gateway mounts set it;
	// the general HTTP tool API remains available outside a turn.
	RequireActiveRun          bool
	SupportsImageInput        bool
	SupportsFileInput         bool
	ContextBudgetMaxTokens    int
	ContextToolExchangePolicy *contextfrag.ToolExchangePolicy
	RuntimeFence              runtimefence.Fence          `json:"-"`
	RunContext                context.Context             `json:"-"`
	RuntimeGuard              func(context.Context) error `json:"-"`
}

Session carries request-scoped identity and runtime ownership for tool execution. Runtime-only fields remain process-local and are never serialized.

func Merge

func Merge(base, latest Session) Session

Merge overlays every non-empty field of latest onto base; boolean capabilities are sticky-true. ToolCallID is excluded on purpose: it is per-call and assigned by the caller after merging.

Jump to

Keyboard shortcuts

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