agentctx

package
v0.67.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const MaxCallDepth = 4

MaxCallDepth bounds synchronous Session/delegate nesting. Raise it only when real workflows need deeper collaboration and root turn budgets still bound the resulting fan-out safely.

View Source
const MaxTotalSessionCalls = 16

MaxTotalSessionCalls bounds sibling fan-out across one root turn. Raise it only when measured workflows need more focused calls and the root timeout remains a sufficient aggregate cost bound.

Variables

This section is empty.

Functions

func BindSessionCallTarget

func BindSessionCallTarget(ctx context.Context, targetSessionID string) (context.Context, error)

BindSessionCallTarget adds a target resolved after call entry (session.create). Binding the current tail is idempotent for known-target send paths.

func ChannelFromContext

func ChannelFromContext(ctx context.Context) (string, bool)

ChannelFromContext returns the current chat channel when present.

func EnterSessionCall

func EnterSessionCall(ctx context.Context, sourceSessionID, targetSessionID string) (context.Context, error)

EnterSessionCall increments nesting and optionally appends a known target. sourceSessionID seeds a top-level chain; inherited chains already contain it.

func ExcludedToolsFromContext

func ExcludedToolsFromContext(ctx context.Context) []string

ExcludedToolsFromContext returns the per-run excluded tool names when present.

func SystemOverrideFromContext

func SystemOverrideFromContext(ctx context.Context) (string, bool)

SystemOverrideFromContext returns the per-run system prompt override when present.

func TurnIDFromContext

func TurnIDFromContext(ctx context.Context) string

TurnIDFromContext returns the current turn's identifier, or "" outside a turn.

func WithChannel

func WithChannel(ctx context.Context, channel string) context.Context

WithChannel returns a child context that carries the current chat channel.

func WithChatBinding

func WithChatBinding(ctx context.Context, binding ChatBinding) context.Context

WithChatBinding returns a child context carrying the durable chat binding this turn entered through.

func WithExcludedTools

func WithExcludedTools(ctx context.Context, names ...string) context.Context

WithExcludedTools returns a child context that hides the named tools for a single run.

func WithSessionCallBudget

func WithSessionCallBudget(ctx context.Context) context.Context

WithSessionCallBudget allocates the shared call counter at a root runtime turn. Nested turns retain the same pointer through context inheritance.

func WithSystemOverride

func WithSystemOverride(ctx context.Context, system string) context.Context

WithSystemOverride returns a child context that carries a per-run system prompt override.

func WithTurnID

func WithTurnID(ctx context.Context, turnID string) context.Context

WithTurnID returns a child context carrying an identifier unique to one chat turn. The runtime mints it once per Chat call; consumers use it only to tell two turns apart, never to order them.

func WithoutChatBinding

func WithoutChatBinding(ctx context.Context) context.Context

WithoutChatBinding returns a child context with no chat binding, whatever the parent carried.

A delegate (or any other nested run) inherits its parent's context, and the parent may be a Telegram or group turn. The binding is the authority to rotate and compact THAT chat's session, so inheriting it would let a delegate — whose own turn nobody is watching and whose task text can come from a tool result — reset the conversation that spawned it.

Types

type ChatBinding

type ChatBinding struct {
	// Main marks a DM pinned to its user's singleton main session. Every other
	// chat (group, private channel) resolves through the channel binding below.
	Main bool
	// Channel is the durable session channel of a non-main chat binding.
	Channel string
	// SessionKey is the chat's derived key, kept for legacy key-as-id lookups.
	SessionKey string
}

ChatBinding describes the durable channel binding a chat turn entered through. Only the chat channel adapters attach it, so its absence is the signal that a turn is not channel-backed: Web/API sends, webhooks, and scheduler/task/delegate runs all leave it unset and therefore fail closed in consumers that require a durable chat.

It exists because a session row cannot answer the question. The Web UI can open the very same main session a DM is pinned to (`POST /sessions` with kind=main), and `ctx_conversation.channel` records whichever surface created the row first, so neither the session id nor its channel distinguishes a Telegram turn from a browser tab on the same session. The entry adapter does know, and this is how it says so.

func ChatBindingFromContext

func ChatBindingFromContext(ctx context.Context) (ChatBinding, bool)

ChatBindingFromContext returns the durable chat binding of the current turn. The bool is false for any turn that did not enter through a chat channel.

type SessionCall

type SessionCall struct {
	Depth    int
	Ancestry []string
}

SessionCall is the live synchronous Session-call chain. It is deliberately context-only: the caller and every child die together, so persistence would create replay risk rather than durability.

func SessionCallFromContext

func SessionCallFromContext(ctx context.Context) (SessionCall, bool)

SessionCallFromContext returns a defensive copy of the active call chain.

Jump to

Keyboard shortcuts

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