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

binding

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: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachmentResourceReferences added in v0.1.57

func AttachmentResourceReferences(attachments []*Attachment) string

AttachmentResourceReferences exposes only server-verified resource metadata. It does not carry bytes, grant access, or turn arbitrary attachment URLs into resources.

func ContentMessageKey added in v0.1.9

func ContentMessageKey(messageID string) string

ContentMessageKey produces the explicit trace key for a concrete persisted user/assistant message id. Continuation should prefer this exact identity instead of hashing raw content text.

func MakeContentKey

func MakeContentKey(content string) string

MakeContentKey builds a stable key for text contents by hashing normalized content.

func ModelContentItems added in v0.1.57

func ModelContentItems(items []llm.ContentItem, attachments []*Attachment) []llm.ContentItem

ModelContentItems removes uploaded resource bytes from ordered model content without changing the stored attachment or the caller's content-item slice.

func NormalizeContent

func NormalizeContent(s string) string

NormalizeContent trims whitespace and, if content is valid JSON, returns its minified canonical form.

func ResolveTextImports added in v0.1.8

func ResolveTextImports(ctx context.Context, fs afs.Service, text, baseURI string) (string, error)

ResolveTextImports expands `$import(path)` directives embedded in a text blob (typically a prompt template loaded from a .tmpl/.md file). Path resolution is relative to the directory of baseURI — the same convention used by the YAML-node resolver in workspace/service/meta/imports.go.

Semantics:

  • A directive must occupy an entire line (ignoring leading/trailing whitespace). Inline text like "See $import(foo) below" is left alone.
  • Paths are relative. Absolute paths are rejected.
  • Imported files are resolved recursively to a bounded depth (8).
  • A visiting set prevents cycles.
  • `$$import(...)` is an escape: it becomes literal `$import(...)` in the output.

Ordering: this helper runs BEFORE any prompt template engine (Go text/ template, velty, …). Imported content may itself carry `{{...}}` or `$foo` directives — those are handled by the subsequent engine pass.

Returns the expanded text unchanged when no directive is present.

func ResolveTextImportsWithReader added in v0.1.57

func ResolveTextImportsWithReader(ctx context.Context, read func(context.Context, string) ([]byte, error), text, baseURI string) (string, error)

ResolveTextImportsWithReader preserves import syntax/limits while letting an owning document provider supply the original bytes.

func ToolResultLLMMessages

func ToolResultLLMMessages(msg *Message) []llm.Message

Types

type Attachment

type Attachment struct {
	Native bool   `yaml:"native,omitempty" json:"native,omitempty"`
	Name   string `yaml:"name,omitempty" json:"name,omitempty"`
	URI    string `yaml:"uri,omitempty" json:"uri,omitempty"`
	// ResourceURI is installed only after a current-user artifact check.
	ResourceURI string `yaml:"-" json:"-"`
	// Installed from the owned artifact manifest, not caller metadata.
	Role           string    `yaml:"-" json:"-"`
	ImageDetail    string    `yaml:"-" json:"-"`
	PresentationAt time.Time `yaml:"-" json:"-"`
	OmitModelBytes bool      `yaml:"-" json:"-"`
	StagingFolder  string    `yaml:"stagingFolder,omitempty" json:"stagingFolder,omitempty"`
	Mime           string    `yaml:"mime,omitempty" json:"mime,omitempty"`
	Content        string    `yaml:"content,omitempty" json:"content,omitempty"`
	Data           []byte    `yaml:"data,omitempty" json:"data,omitempty"`
	PayloadID      string    `yaml:"-" json:"-"`
}

func (*Attachment) MIMEType

func (a *Attachment) MIMEType() string

func (*Attachment) ResourceMetadataOnly added in v0.1.57

func (a *Attachment) ResourceMetadataOnly() bool

ResourceMetadataOnly applies only to server-verified uploaded resources. PDFs and ordinary images keep their existing provider presentation. Verified screenshots outside the active retention window keep only owned references.

func (*Attachment) Type

func (a *Attachment) Type() string

type Binding

type Binding struct {
	Task            Task                   `yaml:"task" json:"task"`
	Model           string                 `yaml:"model,omitempty" json:"model,omitempty"`
	Persona         Persona                `yaml:"persona,omitempty" json:"persona,omitempty"`
	History         History                `yaml:"history,omitempty" json:"history,omitempty"`
	Tools           Tools                  `yaml:"tools,omitempty" json:"tools,omitempty"`
	Meta            Meta                   `yaml:"meta,omitempty" json:"meta,omitempty"`
	SystemDocuments Documents              `yaml:"systemDocuments,omitempty" json:"systemDocuments,omitempty"`
	Documents       Documents              `yaml:"documents,omitempty" json:"documents,omitempty"`
	Flags           Flags                  `yaml:"flags,omitempty" json:"flags,omitempty"`
	Context         map[string]interface{} `yaml:"context,omitempty" json:"context,omitempty"`
	Skills          []skillproto.Metadata  `yaml:"skills,omitempty" json:"skills,omitempty"`
	SkillsPrompt    string                 `yaml:"skillsPrompt,omitempty" json:"skillsPrompt,omitempty"`
	// Elicitation contains a generic, prompt-friendly view of agent-required inputs
	// so templates can instruct the LLM to elicit missing data when necessary.
	Elicitation Elicitation `yaml:"elicitation,omitempty" json:"elicitation,omitempty"`
}

func (*Binding) ContextJSON

func (b *Binding) ContextJSON() string

ContextJSON returns a stable JSON rendering of binding context for prompts. Templates should prefer this over printing the raw map to avoid Go's map[...] format.

func (*Binding) Data

func (b *Binding) Data() map[string]interface{}

func (*Binding) SystemBinding

func (b *Binding) SystemBinding() *Binding

type Document

type Document struct {
	// RefreshOnContinuation marks current trusted documents for anchored publication.
	// It is never restored from persisted transcript documents.
	RefreshOnContinuation bool              `yaml:"-" json:"-"`
	Title                 string            `yaml:"title,omitempty" json:"title,omitempty"`
	PageContent           string            `yaml:"pageContent,omitempty" json:"pageContent,omitempty"`
	SourceURI             string            `yaml:"sourceURI,omitempty" json:"sourceURI,omitempty"`
	Score                 float64           `yaml:"score,omitempty" json:"score,omitempty"`
	MimeType              string            `yaml:"mimeType,omitempty" json:"mimeType,omitempty"`
	Metadata              map[string]string `yaml:"metadata,omitempty" json:"metadata,omitempty"`
}

type Documents

type Documents struct {
	Items []*Document `yaml:"items,omitempty" json:"items,omitempty"`
}

type Elicitation

type Elicitation struct {
	Required bool                   `yaml:"required,omitempty" json:"required,omitempty"`
	Missing  []string               `yaml:"missing,omitempty" json:"missing,omitempty"`
	Message  string                 `yaml:"message,omitempty" json:"message,omitempty"`
	Schema   map[string]interface{} `yaml:"schema,omitempty" json:"schema,omitempty"`
	// SchemaJSON is a pre-serialized JSON of Schema for templates without JSON helpers
	SchemaJSON string `yaml:"schemaJSON,omitempty" json:"schemaJSON,omitempty"`
}

Elicitation is a generic holder for required-input prompts used by templates. It intentionally avoids coupling to agent plan types.

type Flags

type Flags struct {
	CanUseTool   bool `yaml:"canUseTool,omitempty" json:"canUseTool,omitempty"`
	CanStream    bool `yaml:"canStream,omitempty" json:"canStream,omitempty"`
	IsMultimodal bool `yaml:"isMultimodal,omitempty" json:"isMultimodal,omitempty"`
	IsSystem     bool `yaml:"isSystemPath,omitempty" json:"isSystemPath,omitempty"`
	// HasMessageOverflow indicates that a message content (tool result or otherwise)
	// exceeded the preview limit and the binding may expose message helpers.
	HasMessageOverflow bool `yaml:"hasMessageOverflow,omitempty" json:"hasMessageOverflow,omitempty"`
	// MaxOverflowBytes records the maximum original byte size of any
	// message that triggered overflow in this binding (history or tool
	// results). When zero, no size information was recorded.
	MaxOverflowBytes int `yaml:"maxOverflowBytes,omitempty" json:"maxOverflowBytes,omitempty"`
}

type History

type History struct {
	// Past contains committed conversation turns in chronological order.
	Past []*Turn `yaml:"past,omitempty" json:"past,omitempty"`

	// Current holds the in-flight turn for the ongoing request
	// (React loop step). It is intentionally separated from Past
	// so we can distinguish persisted history from the current
	// LLM call context.
	Current *Turn `yaml:"current,omitempty" json:"current,omitempty"`

	// CurrentTurnID, when non-empty, carries the id of the in-flight
	// turn associated with the Current messages. It is typically
	// aligned with memory.TurnMeta.TurnID and is provided for
	// observability and explicitness; Past remains the committed
	// transcript.
	CurrentTurnID string `yaml:"currentTurnID,omitempty" json:"currentTurnID,omitempty"`

	// Messages is a legacy flat view of persisted history kept for
	// template compatibility and internal tooling. New code should
	// prefer Past/Current and helper methods.
	Messages []*Message `yaml:"messages,omitempty" json:"messages,omitempty"`

	LastResponse *Trace            `yaml:"lastResponse,omitempty" json:"lastResponse,omitempty"`
	Traces       map[string]*Trace `yaml:"traces,omitempty" json:"traces,omitempty"`
	ToolExposure string
}

func (*History) LLMMessages

func (h *History) LLMMessages() []llm.Message

LLMMessages flattens history turns into a chronological slice of llm.Messages. When Past/Current are present, they are used as the source; otherwise the legacy flat Messages field is used.

type Kind

type Kind string
const (
	KindResponse Kind = "resp"
	KindToolCall Kind = "op"
	KindContent  Kind = "content"
)

func (Kind) IsContent

func (k Kind) IsContent() bool

func (Kind) IsResponse

func (k Kind) IsResponse() bool

func (Kind) IsToolCall

func (k Kind) IsToolCall() bool

Kind helpers

func (Kind) Key

func (k Kind) Key(raw string) string

Key produces a stable map key for the given raw value based on the Kind. - For KindResponse and KindToolCall, it trims whitespace and returns the id/opId. - For KindContent, it derives a hash key from normalized content.

type Message

type Message struct {
	ContentItems []llm.ContentItem `yaml:"contentItems,omitempty" json:"contentItems,omitempty"`
	Kind         MessageKind       `yaml:"kind,omitempty" json:"kind,omitempty"`
	Role         string            `yaml:"role,omitempty" json:"role,omitempty"`
	MimeType     string            `yaml:"mimeType,omitempty" json:"mimeType,omitempty"`
	Content      string            `yaml:"content,omitempty" json:"content,omitempty"`
	Attachment   []*Attachment     `yaml:"attachment,omitempty" json:"attachment,omitempty"`
	CreatedAt    time.Time         `yaml:"createdAt,omitempty" json:"createdAt,omitempty"`

	ID string `yaml:"id,omitempty" json:"id,omitempty"`

	// Optional tool metadata for tool result messages.
	ToolError   string                 `yaml:"toolError,omitempty" json:"toolError,omitempty"`
	ToolOpID    string                 `yaml:"toolOpId,omitempty" json:"toolOpId,omitempty"`
	ToolName    string                 `yaml:"toolName,omitempty" json:"toolName,omitempty"`
	ToolArgs    map[string]interface{} `yaml:"toolArgs,omitempty" json:"toolArgs,omitempty"`
	ToolTraceID string                 `yaml:"toolTraceId,omitempty" json:"toolTraceId,omitempty"`
}

func (*Message) ToLLM

func (m *Message) ToLLM() llm.Message

ToLLM converts a prompt.Message into an llm.Message, preserving attachments and role. It sorts attachments by URI to ensure deterministic ordering when multiple attachments are present.

type MessageKind

type MessageKind string

MessageKind classifies high-level message semantics in history for LLM binding purposes.

const (
	MessageKindChatUser      MessageKind = "chat_user"
	MessageKindChatAssistant MessageKind = "chat_assistant"
	MessageKindToolResult    MessageKind = "tool_result"
	MessageKindElicitPrompt  MessageKind = "elicit_prompt"
	MessageKindElicitAnswer  MessageKind = "elicit_answer"
)

type Meta

type Meta struct {
	Model string `yaml:"model,omitempty" json:"model,omitempty"`
}

type Persona

type Persona struct {
	Role    string `yaml:"role,omitempty"  json:"role,omitempty"`
	Actor   string `yaml:"actor,omitempty" json:"actor,omitempty"`
	Summary string `yaml:"summary,omitempty" json:"summary,omitempty"`
}

type Prompt

type Prompt struct {
	Text   string `yaml:"text,omitempty" json:"text,omitempty"`
	URI    string `yaml:"uri,omitempty" json:"uri,omitempty"`
	Engine string `yaml:"engine,omitempty" json:"engine,omitempty"`
	// contains filtered or unexported fields
}

func (*Prompt) Generate

func (a *Prompt) Generate(ctx context.Context, binding *Binding) (string, error)

func (*Prompt) Init

func (a *Prompt) Init(ctx context.Context) error

func (Prompt) MarshalJSON added in v0.1.44

func (a Prompt) MarshalJSON() ([]byte, error)

func (Prompt) MarshalYAML added in v0.1.44

func (a Prompt) MarshalYAML() (interface{}, error)

func (*Prompt) UnmarshalJSON added in v0.1.44

func (a *Prompt) UnmarshalJSON(data []byte) error

func (*Prompt) UnmarshalYAML added in v0.1.44

func (a *Prompt) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML accepts both the legacy scalar prompt text and the prompt object shape with text, uri, and engine fields.

type Task

type Task struct {
	ContentItems []llm.ContentItem `yaml:"contentItems,omitempty" json:"contentItems,omitempty"`
	Prompt       string            `yaml:"prompt,omitempty" json:"prompt,omitempty"`
	Attachments  []*Attachment     `yaml:"attachments,omitempty" json:"attachments,omitempty"`
}

type Tools

type Tools struct {
	Signatures []*llm.ToolDefinition `yaml:"signatures,omitempty" json:"signatures,omitempty"`
}

type Trace

type Trace struct {
	ID   string
	Kind Kind
	At   time.Time
}

func (*Trace) IsValid

func (t *Trace) IsValid() bool

IsValid reports whether the trace carries a usable anchor. A valid anchor must have a non-zero time; ID may be empty when provider continuation by response id is not used.

type Turn

type Turn struct {
	ID        string     `yaml:"id,omitempty" json:"id,omitempty"`
	StartedAt time.Time  `yaml:"startedAt,omitempty" json:"startedAt,omitempty"`
	Messages  []*Message `yaml:"messages,omitempty" json:"messages,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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