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

clienttool

package
v0.1.58 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package clienttool carries request-scoped frontend tools without modifying a backend registry. The protocol layer persists definitions and pending calls.

Index

Constants

View Source
const ContentMIME = "application/vnd.ag-ui.content+json"
View Source
const ItemsMIME = "application/vnd.ag-ui.llm-items+json"
View Source
const ToolErrorMIME = "application/vnd.ag-ui.tool-error"

Variables

This section is empty.

Functions

func ContentText

func ContentText(items []llm.ContentItem) string

func FormatDependencyResult

func FormatDependencyResult(dependency Dependency, result ChildResult) (string, string, error)

FormatDependencyResult mirrors the public agents:run result shape, never the QueryOutput agent/config/auth/render data. Waiting children cannot complete it.

func MapContent

func MapContent(raw json.RawMessage) ([]llm.ContentItem, error)

MapContent preserves part order and source semantics without fetching URLs or resolving provider-owned file handles. Providers decide which assets they can consume; raw protocol metadata remains carried in each mapped item's metadata.

func WithContinuationDependency

func WithContinuationDependency(ctx context.Context, dependency Dependency) context.Context

WithContinuationDependency carries a trusted dependency loaded from durable protocol state. HTTP forwarded properties must never directly populate it.

func WithDetachedContinuation

func WithDetachedContinuation(ctx context.Context, continuation DetachedContinuation) context.Context

func WithExecutingCall

func WithExecutingCall(ctx context.Context, call PendingCall) context.Context

func WithSession

func WithSession(ctx context.Context, session *Session) context.Context

Types

type ChildResult

type ChildResult struct {
	Content        string
	Status         string
	ConversationID string
	TurnID         string
	Error          string
}

type Dependency

type Dependency struct {
	ID                  string        `json:"id"`
	ParentCall          PendingCall   `json:"parentCall"`
	ChildConversationID string        `json:"childConversationId"`
	ChildTurnID         string        `json:"childTurnId"`
	ChildAgentID        string        `json:"childAgentId,omitempty"`
	ExecutionMode       string        `json:"executionMode,omitempty"`
	ResultAdapter       ResultAdapter `json:"resultAdapter"`
	Waiting             bool          `json:"waiting"`
}

Dependency is a causal waiting edge. ParentCall is the existing backend tool call to complete after the child turn succeeds; it is never a frontend tool.

func ContinuationDependencyFromContext

func ContinuationDependencyFromContext(ctx context.Context) (Dependency, bool)

type DetachedContinuation

type DetachedContinuation struct {
	ChildConversationID  string
	ChildTurnID          string
	ParentConversationID string
	ParentTurnID         string
	ParentProtocolRunID  string
	ExecutionMode        string
}

DetachedContinuation is trusted host authority loaded from a principal-scoped internal detached protocol admission. A native conversation link alone does not prove that a child was detached.

func DetachedContinuationFromContext

func DetachedContinuationFromContext(ctx context.Context) (DetachedContinuation, bool)

type PendingCall

type PendingCall struct {
	// DeadlineAt is assigned by the server at deferral, or by the explicit
	// legacy recovery policy below. It is never extended by reconnect.
	// RecoveryObservedAt marks legacy grace; it is not the original admission time.
	RecoveryObservedAt string                 `json:"recoveryObservedAt,omitempty"`
	DeadlineAt         string                 `json:"deadlineAt,omitempty"`
	Metadata           json.RawMessage        `json:"metadata,omitempty"`
	ProtocolID         string                 `json:"protocolId,omitempty"`
	ID                 string                 `json:"id"`
	Name               string                 `json:"name"`
	Arguments          map[string]interface{} `json:"arguments"`
	ToolMessageID      string                 `json:"toolMessageId"`
	AssistantMessageID string                 `json:"assistantMessageId"`
	ConversationID     string                 `json:"conversationId"`
	TurnID             string                 `json:"turnId"`
	Iteration          int                    `json:"iteration"`
}

func ExecutingCallFromContext

func ExecutingCallFromContext(ctx context.Context) (PendingCall, bool)

type ResultAdapter

type ResultAdapter string
const AgentRunResultV1 ResultAdapter = "agently.agents.run.v1"

type Session

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

func FromContext

func FromContext(ctx context.Context) *Session

func NewSession

func NewSession(definitions []llm.ToolDefinition) (*Session, error)

func (*Session) Defer

func (s *Session) Defer(id, name string, args map[string]interface{}, persist func() (PendingCall, error)) (PendingCall, error)

Defer reserves a call id and serializes persistence. Duplicate identical calls reuse the original records; conflicting calls and persistence errors poison this session so the agent loop cannot treat a swallowed executor error as success.

func (*Session) DeferForTurn

func (s *Session) DeferForTurn(conversationID, turnID, id, name string, args map[string]interface{}, persist func() (PendingCall, error)) (PendingCall, error)

func (*Session) Definitions

func (s *Session) Definitions() []llm.ToolDefinition

func (*Session) Error

func (s *Session) Error() error

func (*Session) ErrorForTurn

func (s *Session) ErrorForTurn(conversationID, turnID string) error

func (*Session) Lookup

func (s *Session) Lookup(name string) (llm.ToolDefinition, bool)

func (*Session) MarkDependencyWaiting

func (s *Session) MarkDependencyWaiting(id string) error

func (*Session) Metadata

func (s *Session) Metadata(name string) json.RawMessage

func (*Session) Pending

func (s *Session) Pending() []PendingCall

func (*Session) PendingForSubtree

func (s *Session) PendingForSubtree(conversationID, turnID string) []PendingCall

func (*Session) PendingForTurn

func (s *Session) PendingForTurn(conversationID, turnID string) []PendingCall

func (*Session) RecordError

func (s *Session) RecordError(err error)

func (*Session) RecordErrorForTurn

func (s *Session) RecordErrorForTurn(conversationID, turnID string, err error)

func (*Session) RegisterDependency

func (s *Session) RegisterDependency(dependency Dependency) error

func (*Session) RestrictManaged

func (s *Session) RestrictManaged(managed, allowed map[string]bool)

RestrictManaged applies server-resolved tool/bundle selection before the model sees managed frontend tools. It cannot be invoked by browser wire metadata.

func (*Session) SetMetadata

func (s *Session) SetMetadata(name string, metadata json.RawMessage) error

Definition metadata is presentation/routing data, never backend authority or provider instruction. Keep it lossless alongside request-scoped definitions.

func (*Session) ValidateBackend

func (s *Session) ValidateBackend(definitions []llm.ToolDefinition) error

func (*Session) WaitingDependencies

func (s *Session) WaitingDependencies(conversationID, turnID string) []Dependency

func (*Session) WaitingOnCall

func (s *Session) WaitingOnCall(conversationID, turnID, callID string) bool

Jump to

Keyboard shortcuts

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