binding

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeContentKey

func MakeContentKey(content string) string

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

func NormalizeContent

func NormalizeContent(s string) string

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

func ToolResultLLMMessages

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

Types

type Attachment

type Attachment struct {
	Name          string `yaml:"name,omitempty" json:"name,omitempty"`
	URI           string `yaml:"uri,omitempty" json:"uri,omitempty"`
	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"`
}

func (*Attachment) MIMEType

func (a *Attachment) MIMEType() string

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"`
	// 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 {
	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 {
	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.
	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

type Task

type Task struct {
	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