Documentation
¶
Overview ¶
Package glue provides the public API for defining and running agents.
It is intentionally thin over the lower-level loop package. Users construct an Agent with NewAgent, open a named Session with Agent.Session, and drive turns with Session.Prompt. Tools are defined with NewTool, skills and roles are discovered from a WorkDir, and structured output is produced with Session.PromptJSON.
Provider implementations live in subpackages (providers/gemini, providers/codex, providers/nvidia, providers/openrouter, with the shared OpenAI-compatible core in providers/openaicompat and a driver-style registry in providers). Session persistence is provided by stores subpackages (stores/file for the simple default, stores/sqlite for cross-session FTS5 search). Reusable tools live under tools (tools/fs, tools/git, tools/shell, tools/coding, tools/mcp).
Normalized message and event types are re-exported here so that callers only need to import "github.com/erain/glue". For a guided, end-to-end walkthrough of building an agent, see docs/building-agents.md.
Index ¶
- Constants
- Variables
- type Agent
- type AgentOptions
- type AllowAll
- type Compactor
- type CompactorFunc
- type ContentPart
- type ContentType
- type DenyAll
- type Event
- type EventType
- type ExecCommand
- type ExecResult
- type Executor
- type FailoverAttempt
- type FailoverError
- type Hook
- type ImageContent
- type ListSessionsOptions
- type LocalExecutor
- type Message
- type MessageRole
- type Permission
- type PermissionDecision
- type PermissionRequest
- type ProjectContext
- type PromptOption
- func WithEvents(handler func(Event)) PromptOption
- func WithJSONSchema(schema any) PromptOption
- func WithMaxTurns(maxTurns int) PromptOption
- func WithModel(model string) PromptOption
- func WithPermission(permission Permission) PromptOption
- func WithProviderOptions(options map[string]any) PromptOption
- func WithRole(role string) PromptOption
- func WithStreamWriter(w io.Writer) PromptOption
- func WithSystemPrompt(systemPrompt string) PromptOption
- func WithToolLogger(w io.Writer) PromptOption
- func WithTools(tools []Tool) PromptOption
- type PromptResult
- type Provider
- type ProviderEvent
- type ProviderEventType
- type ProviderRequest
- type RememberScope
- type Role
- type SearchHit
- type SearchOption
- type SearchOptions
- type Searcher
- type Session
- func (s *Session) ID() string
- func (s *Session) Messages() []Message
- func (s *Session) Prompt(ctx context.Context, text string, options ...PromptOption) (PromptResult, error)
- func (s *Session) PromptJSON(ctx context.Context, text string, outPtr any, options ...PromptOption) (PromptResult, error)
- func (s *Session) Search(ctx context.Context, query string, opts ...SearchOption) ([]SearchHit, error)
- func (s *Session) Skill(ctx context.Context, name string, args any, options ...PromptOption) (PromptResult, error)
- func (s *Session) State() SessionState
- func (s *Session) Subscribe(handler func(Event)) func()
- type SessionLister
- type SessionOption
- type SessionState
- type SessionSummary
- type Skill
- type StopReason
- type Store
- type SubagentOptions
- type SummarizingCompactor
- type Tool
- type ToolCall
- type ToolExecutor
- type ToolResult
- type ToolSpec
- type Usage
Constants ¶
const ( DefaultSearchLimit = 20 MaxSearchLimit = 100 )
Search-related limits. Exported so callers can size paging.
const ( RememberNever = loop.RememberNever RememberSession = loop.RememberSession RememberSessionTarget = loop.RememberSessionTarget RememberForever = loop.RememberForever )
RememberScope constants re-exported from package loop.
const ( MessageRoleUser = loop.MessageRoleUser MessageRoleAssistant = loop.MessageRoleAssistant MessageRoleTool = loop.MessageRoleTool )
MessageRole constants re-exported from package loop.
const ( ContentTypeText = loop.ContentTypeText ContentTypeThinking = loop.ContentTypeThinking ContentTypeImage = loop.ContentTypeImage ContentTypeToolCall = loop.ContentTypeToolCall )
ContentType constants re-exported from package loop.
const ( StopReasonStop = loop.StopReasonStop StopReasonLength = loop.StopReasonLength StopReasonToolUse = loop.StopReasonToolUse StopReasonError = loop.StopReasonError StopReasonCanceled = loop.StopReasonCanceled StopReasonMaxTurns = loop.StopReasonMaxTurns )
StopReason constants re-exported from package loop.
const ( EventLoopStart = loop.EventLoopStart EventLoopEnd = loop.EventLoopEnd EventTurnStart = loop.EventTurnStart EventTurnEnd = loop.EventTurnEnd EventMessageStart = loop.EventMessageStart EventMessageEnd = loop.EventMessageEnd EventTextDelta = loop.EventTextDelta EventToolStart = loop.EventToolStart EventToolEnd = loop.EventToolEnd EventError = loop.EventError )
EventType constants re-exported from package loop.
const ( ProviderEventStart = loop.ProviderEventStart ProviderEventTextDelta = loop.ProviderEventTextDelta ProviderEventThinkingDelta = loop.ProviderEventThinkingDelta ProviderEventToolCall = loop.ProviderEventToolCall ProviderEventDone = loop.ProviderEventDone ProviderEventError = loop.ProviderEventError )
ProviderEventType constants re-exported from package loop.
const DefaultExecMaxOutputBytes = 64 * 1024
DefaultExecMaxOutputBytes is the per-stream output cap used by LocalExecutor when ExecCommand.MaxOutputBytes is zero.
const DefaultSummarizingSystemPrompt = `` /* 580-byte string literal not displayed */
DefaultSummarizingSystemPrompt is the instruction the SummarizingCompactor sends to the provider when no override is configured. The prompt biases for fact retention over polish.
const SessionStateVersion = 1
SessionStateVersion is the on-disk version tag for SessionState.
Variables ¶
var ErrSearchNotSupported = errors.New("glue: store does not support search")
ErrSearchNotSupported is returned when the active Store does not implement Searcher. Callers can fall back gracefully (e.g. show "search not configured" in a UI).
var ErrSkipTool = loop.ErrSkipTool
ErrSkipTool re-exported from package loop.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent owns shared configuration and an in-memory session map.
func NewAgent ¶
func NewAgent(options AgentOptions) *Agent
NewAgent creates an agent. When AgentOptions.Store is set, sessions are loaded from and saved to that store; otherwise sessions are in-memory. The Provider must be supplied for Session.Prompt to succeed.
func (*Agent) SearchSessions ¶
func (a *Agent) SearchSessions(ctx context.Context, query string, opts ...SearchOption) ([]SearchHit, error)
SearchSessions returns FTS-ranked hits across all sessions stored by the agent's Store. Returns ErrSearchNotSupported if the active store does not implement Searcher.
query is passed straight through to the underlying Searcher. For the SQLite/FTS5 backend the syntax is FTS5's MATCH expression — a bare word matches that word; quoted phrases match exactly; AND / OR / NOT are supported.
func (*Agent) Session ¶
Session returns an existing session by id, or creates a new one. When the agent has a configured Store, an existing on-disk state is loaded into the new in-memory session. Empty ids resolve to the default session ("default").
func (*Agent) ToolCatalog ¶
ToolCatalog returns a cloned provider-visible catalog of the agent's configured tools, including permission metadata for hosts that need to display or expose the tool surface without starting a session.
type AgentOptions ¶
type AgentOptions struct {
Provider Provider
Model string
SystemPrompt string
Tools []Tool
Options map[string]any
MaxTurns int
Store Store
WorkDir string
Skills map[string]Skill
Roles []Role
Role string
Permission Permission
Hooks []Hook
// Compactor, if non-nil and CompactionThreshold > 0, is invoked
// before every prompt whenever the in-memory transcript has more
// than CompactionThreshold messages. The compactor's output replaces
// the in-memory transcript before [loop.Run] is called and is
// persisted by the next save.
Compactor Compactor
CompactionThreshold int
}
AgentOptions configures a Glue agent.
All fields are wired. When WorkDir is set, the agent loads `<WorkDir>/AGENTS.md` (non-fatal if missing), discovers Markdown skills under `<WorkDir>/.agents/skills/<name>/SKILL.md`, and discovers Markdown roles under `<WorkDir>/roles/*.md`. Programmatic entries supplied via Skills and Roles are merged with the on-disk catalog; programmatic entries win on name collision.
Role is the agent-default role applied to every prompt unless overridden at session or call level. Effective role precedence is call (WithRole) > session (WithSessionRole) > agent (Role). Effective model precedence is call (WithModel) > effective role's Model > Model.
type AllowAll ¶
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type Compactor ¶
Compactor rewrites a session transcript before it is sent to the provider. Implementations should preserve the user's most recent intent and the assistant context that depends on it; older turns can be dropped, summarized, or replaced. Compactors must not mutate the input slice; they return a new slice.
func KeepRecentMessages ¶
KeepRecentMessages returns a Compactor that keeps the last n messages of a transcript and replaces everything older with a single system-style summary message that records how many turns were dropped.
This is the simplest useful compaction policy: it has no token model and never calls a provider. It is appropriate when a session is allowed to accumulate but the caller can tolerate losing older context past a fixed window.
n must be positive. If the input transcript has n or fewer messages, the compactor returns it unchanged.
type CompactorFunc ¶
CompactorFunc adapts a function to the Compactor interface.
type ContentPart ¶
type ContentPart = loop.ContentPart
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type ContentType ¶
type ContentType = loop.ContentType
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type DenyAll ¶
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type Event ¶
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type EventType ¶
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type ExecCommand ¶
type ExecCommand struct {
// Argv is the executable plus arguments. It must be non-empty and
// is never interpreted through a shell.
Argv []string
// Dir, when non-empty, is the child process working directory.
Dir string
// Env is the exact child environment. Nil means inherit no
// environment from the agent process.
Env []string
// Stdin, when non-nil, is connected to the child process stdin.
Stdin io.Reader
// Timeout limits this command independently from the caller's
// context. Zero means no executor-level timeout.
Timeout time.Duration
// MaxOutputBytes caps stdout and stderr independently. Zero uses
// DefaultExecMaxOutputBytes.
MaxOutputBytes int
}
ExecCommand describes one argv-style command execution request.
type ExecResult ¶
ExecResult is the captured result of one command execution.
type Executor ¶
type Executor interface {
Run(ctx context.Context, cmd ExecCommand) (ExecResult, error)
}
Executor abstracts command execution for shell-capable tools. The default implementation, LocalExecutor, runs commands on the local machine; sandboxed or remote executors can implement the same interface without changing tool code.
type FailoverAttempt ¶
FailoverAttempt is one provider's result inside a FailoverError.
type FailoverError ¶
type FailoverError struct {
Attempts []FailoverAttempt
}
FailoverError aggregates per-provider failures from a WithFailover stream attempt. It implements error and exposes Attempts so callers can inspect each provider's outcome.
func (*FailoverError) Error ¶
func (e *FailoverError) Error() string
type Hook ¶
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type ImageContent ¶
type ImageContent = loop.ImageContent
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type ListSessionsOptions ¶
type ListSessionsOptions struct {
// Prefix restricts results to session ids beginning with Prefix.
Prefix string
// Limit caps returned rows. Non-positive values use the store default.
Limit int
// Offset skips rows after filtering and ordering. Negative values are
// treated as zero.
Offset int
}
ListSessionsOptions filters and pages a session history listing.
type LocalExecutor ¶
type LocalExecutor struct{}
LocalExecutor runs commands on the local machine with os/exec. It is intentionally not a sandbox.
func (LocalExecutor) Run ¶
func (LocalExecutor) Run(ctx context.Context, cmd ExecCommand) (ExecResult, error)
Run implements Executor.
type Message ¶
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type MessageRole ¶
type MessageRole = loop.MessageRole
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type Permission ¶
type Permission = loop.Permission
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type PermissionDecision ¶
type PermissionDecision = loop.PermissionDecision
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type PermissionRequest ¶
type PermissionRequest = loop.PermissionRequest
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type ProjectContext ¶
ProjectContext is the WorkDir-loaded state injected by LoadContext. AgentsMD is appended to the system prompt; Skills are exposed via Session.Skill; Roles are looked up by name during prompt configuration.
func LoadContext ¶
func LoadContext(workDir string) (ProjectContext, error)
LoadContext loads AGENTS.md (non-fatal if missing) and skills under `<workDir>/.agents/skills/<name>/SKILL.md`. An empty workDir returns an empty context.
type PromptOption ¶
type PromptOption func(*promptConfig)
PromptOption configures one Session.Prompt invocation.
func WithEvents ¶
func WithEvents(handler func(Event)) PromptOption
WithEvents registers a per-prompt event handler. It receives every loop event for that prompt in addition to any session-scoped subscribers installed via Session.Subscribe.
func WithJSONSchema ¶
func WithJSONSchema(schema any) PromptOption
WithJSONSchema attaches a JSON Schema for Session.PromptJSON. The schema may be passed as a Go value (map / struct), a json.RawMessage, a []byte, or a string; bytes/string forms are JSON-decoded once. When the active provider supports structured output, the schema is forwarded as the provider's structured-response config (Gemini: `response_json_schema`).
func WithMaxTurns ¶
func WithMaxTurns(maxTurns int) PromptOption
WithMaxTurns overrides the loop max-turn guard for one prompt.
func WithModel ¶
func WithModel(model string) PromptOption
WithModel overrides the model for one prompt. When set, this beats any role's Model and the agent's Model.
func WithPermission ¶
func WithPermission(permission Permission) PromptOption
WithPermission overrides the agent's Permission implementation for one prompt. Passing nil explicitly disables permission handling for that prompt, so side-effecting tools are denied by the loop.
func WithProviderOptions ¶
func WithProviderOptions(options map[string]any) PromptOption
WithProviderOptions replaces provider options for one prompt.
func WithRole ¶
func WithRole(role string) PromptOption
WithRole overrides the effective role for one prompt. The named role must exist in AgentOptions.Roles or the loaded WorkDir context, or the prompt fails with a typed error.
func WithStreamWriter ¶
func WithStreamWriter(w io.Writer) PromptOption
WithStreamWriter mirrors EventTextDelta.Delta to w on every prompt event. Composes additively with WithEvents and other event-related options — installing one does not displace any other.
Errors from the writer are silently dropped: this is a convenience option, not a delivery-guaranteed pipe. Callers that need backpressure or error visibility should register a custom WithEvents handler instead.
A nil writer is a no-op so callers can pass conditional writers without branching.
func WithSystemPrompt ¶
func WithSystemPrompt(systemPrompt string) PromptOption
WithSystemPrompt overrides the agent system prompt for one prompt.
func WithToolLogger ¶
func WithToolLogger(w io.Writer) PromptOption
WithToolLogger mirrors EventToolStart events to w as "[tool] <name>\n". Composes additively with other event-related options. Errors from the writer are silently dropped; nil w is a no-op.
func WithTools ¶
func WithTools(tools []Tool) PromptOption
WithTools replaces the agent tools for one prompt.
type PromptResult ¶
type PromptResult struct {
// Text concatenates all text parts of the final assistant message.
Text string
// Message is the final assistant message of this run, cloned. Nil if no
// assistant message was produced.
Message *Message
// NewMessages contains every message produced during this run, in append
// order (assistant + tool messages, possibly across multiple turns).
NewMessages []Message
// Messages is a snapshot of the full session transcript after this run.
Messages []Message
}
PromptResult is returned by Session.Prompt.
type Provider ¶
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
func WithFailover ¶
WithFailover returns a Provider that tries each underlying provider in order until one accepts a Stream. Failure modes that trigger fallover:
- the underlying Stream call returns a non-nil error before any event is emitted;
- the underlying stream's first event is a ProviderEventError;
- the underlying stream closes immediately with no events.
Once any non-error event is observed the wrapper commits to that provider for the rest of the turn — it does not recover mid-stream. This preserves the loop's "no half-streamed transcripts on retry" invariant.
Callers that want env-key probing (skip provider X when its API key is unset) should pre-filter via [providers.KeyAvailable] from github.com/erain/glue/providers and pass only the candidates whose keys are present.
Returns a typed error implementing FailoverError when all providers fail; use errors.As to inspect per-provider attempts.
type ProviderEvent ¶
type ProviderEvent = loop.ProviderEvent
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type ProviderEventType ¶
type ProviderEventType = loop.ProviderEventType
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type ProviderRequest ¶
type ProviderRequest = loop.ProviderRequest
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type RememberScope ¶
type RememberScope = loop.RememberScope
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type Role ¶
Role is a named instruction profile with an optional model override. Roles are loaded from `<WorkDir>/roles/*.md` (with `name:`, `description:`, `model:` frontmatter) or supplied via AgentOptions.Roles.
type SearchHit ¶
type SearchHit struct {
// SessionID identifies which session this message lives in.
SessionID string
// Index is the ordinal position of the message within its session
// (zero-based).
Index int
// Role is the message author role.
Role MessageRole
// Snippet is a Searcher-supplied excerpt with highlighting around
// the matched terms (FTS5's snippet() output for the SQLite
// backend; markers are << and >>).
Snippet string
// Score is the implementation-specific relevance score. For the
// SQLite/FTS5 backend this is BM25 — lower is better.
Score float64
// Timestamp is the message's CreatedAt (or the session updated_at
// if the message had no per-message timestamp).
Timestamp time.Time
}
SearchHit is one row returned by a Searcher.
type SearchOption ¶
type SearchOption func(*SearchOptions)
SearchOption configures a SearchOptions via functional-options.
func WithLimit ¶
func WithLimit(n int) SearchOption
WithLimit overrides SearchOptions.Limit. Non-positive values fall back to DefaultSearchLimit; values > MaxSearchLimit are clamped.
func WithOffset ¶
func WithOffset(n int) SearchOption
WithOffset overrides SearchOptions.Offset. Negative values are treated as zero.
func WithSessionID ¶
func WithSessionID(id string) SearchOption
WithSessionID restricts the search to a single session.
func WithSince ¶
func WithSince(t time.Time) SearchOption
WithSince sets the lower time bound (inclusive).
func WithUntil ¶
func WithUntil(t time.Time) SearchOption
WithUntil sets the upper time bound (inclusive).
type SearchOptions ¶
type SearchOptions struct {
// SessionID restricts results to one session. Empty means
// "across all sessions".
SessionID string
// Limit caps the number of hits returned. Zero falls back to
// DefaultSearchLimit; values larger than MaxSearchLimit are
// clamped silently.
Limit int
// Offset skips this many hits. Useful for paging.
Offset int
// Since restricts results to messages with timestamps ≥ Since.
// Zero means no lower bound.
Since time.Time
// Until restricts results to messages with timestamps ≤ Until.
// Zero means no upper bound.
Until time.Time
}
SearchOptions controls a Searcher.Search call. Zero values mean "no filter" for SessionID / Since / Until, "default" for Limit (20), and zero Offset.
type Searcher ¶
type Searcher interface {
Search(ctx context.Context, query string, opts SearchOptions) ([]SearchHit, error)
}
Searcher is the optional capability a Store may implement to support cross-session content search. Stores that do not implement Searcher cause Agent.SearchSessions and Session.Search to return ErrSearchNotSupported.
Designed in docs/adr/0007-memory-layer.md §3.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is an in-memory conversation with an Agent. Sessions are goroutine-safe but a single session executes one Session.Prompt at a time.
func (*Session) Prompt ¶
func (s *Session) Prompt(ctx context.Context, text string, options ...PromptOption) (PromptResult, error)
Prompt sends a user message through the agent loop and stores the resulting transcript in memory.
func (*Session) PromptJSON ¶
func (s *Session) PromptJSON(ctx context.Context, text string, outPtr any, options ...PromptOption) (PromptResult, error)
PromptJSON sends a prompt and decodes the assistant's final text into outPtr, which must be a non-nil pointer. It augments the user prompt with JSON-only instructions so non-Gemini providers can still produce parseable output, and sets `response_mime_type: application/json` on the provider request. When WithJSONSchema is provided, the schema is also forwarded as `response_json_schema`.
V1 validation is intentionally limited to JSON decoding into the caller's Go type; full JSON Schema validation is out of scope.
func (*Session) Search ¶
func (s *Session) Search(ctx context.Context, query string, opts ...SearchOption) ([]SearchHit, error)
Search restricts Agent.SearchSessions to this session. Any WithSessionID in opts is overridden with this session's id.
func (*Session) Skill ¶
func (s *Session) Skill(ctx context.Context, name string, args any, options ...PromptOption) (PromptResult, error)
Skill renders the named skill (looked up from AgentOptions.Skills or the agent's WorkDir context), appends args as JSON, and runs the result through Session.Prompt. Unknown skill names return a typed error.
func (*Session) State ¶
func (s *Session) State() SessionState
State returns a snapshot of the durable session state.
type SessionLister ¶
type SessionLister interface {
ListSessions(ctx context.Context, opts ListSessionsOptions) ([]SessionSummary, error)
}
SessionLister is an optional store capability for provider-free session history browsers.
type SessionOption ¶
type SessionOption func(*sessionConfig)
SessionOption configures a session at creation time.
func WithSessionRole ¶
func WithSessionRole(role string) SessionOption
WithSessionRole sets the session-default role used when no per-call WithRole is provided.
type SessionState ¶
type SessionState struct {
Version int `json:"version"`
ID string `json:"id"`
Messages []Message `json:"messages,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
SessionState is the durable representation of a session.
type SessionSummary ¶
type SessionSummary struct {
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Messages int `json:"messages"`
UserMessages int `json:"user_messages"`
AssistantMessages int `json:"assistant_messages"`
}
SessionSummary is provider-free metadata about one stored session.
type Skill ¶
Skill is a Markdown-defined reusable prompt loaded from `<WorkDir>/.agents/skills/<name>/SKILL.md` or supplied directly via AgentOptions.Skills.
type StopReason ¶
type StopReason = loop.StopReason
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type Store ¶
type Store interface {
Load(ctx context.Context, id string) (SessionState, bool, error)
Save(ctx context.Context, id string, state SessionState) error
Delete(ctx context.Context, id string) error
}
Store persists Glue session state. Implementations are expected to be goroutine-safe across distinct session ids; concurrent calls for the same id within a single session are serialized by the session itself.
Load returns found=false when the id is not present, with a zero-valued SessionState and a nil error. Save must be atomic against partial writes. Delete must be idempotent — removing a missing id is a no-op success.
type SubagentOptions ¶
type SubagentOptions struct {
// Name is the model-visible tool name.
Name string
// Description is the model-visible tool description.
Description string
// Agent is the child agent invoked when the tool runs. Required.
Agent *Agent
// SessionID is an optional prefix for generated child session ids.
// Each tool instance and tool call appends a generated suffix so calls
// use isolated transcripts. Empty uses "subagent:<Name>".
SessionID string
// MaxTurns optionally overrides the child prompt's loop turn budget.
// Zero uses the child agent/default loop budget.
MaxTurns int
// SystemPrompt optionally overrides the child agent system prompt for
// each delegated prompt.
SystemPrompt string
}
SubagentOptions configures SubagentTool.
type SummarizingCompactor ¶
type SummarizingCompactor struct {
// Provider streams the summary. Required.
Provider Provider
// Model is the model id used for the summary call. When empty the
// provider's default applies.
Model string
// TargetTokens is the soft cap: when the estimated transcript size
// is below this value the compactor returns its input unchanged.
// Zero or negative falls back to the default (8000).
TargetTokens int
// KeepRecent is the number of most-recent messages retained
// verbatim. Zero or negative falls back to the default (8). When
// the input transcript has KeepRecent or fewer messages the
// compactor returns it unchanged regardless of TargetTokens.
KeepRecent int
// SystemPrompt is the instruction sent to the summarizer. When
// empty [DefaultSummarizingSystemPrompt] is used.
SystemPrompt string
}
SummarizingCompactor is a token-aware Compactor that summarizes older transcript messages by calling the configured Provider. It replaces older messages with a single assistant-role marker whose text content is the summary and whose metadata records the compaction.
SummarizingCompactor is the token-aware drop-in anticipated by ADR-0002 and designed in ADR-0007 §1. It composes with — and does not replace — KeepRecentMessages; callers pick the policy that matches their agent's lifetime.
Provider must be set. The compactor calls Provider.Stream once per invocation with a single user message containing the formatted transcript-to-summarize.
Token estimation is intentionally a heuristic in v0.1: a word-count-based proxy that does not need to match any specific tokenizer. A later PR can swap the implementation without changing this type's public surface.
Errors from the underlying provider propagate. The compactor does not silently fall back to dropping context; callers that want a degraded-mode behavior should wire a CompactorFunc that tries SummarizingCompactor first and falls back to KeepRecentMessages explicitly.
type Tool ¶
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
func NewTool ¶
NewTool builds a Tool whose executor decodes ToolCall.Arguments into a typed Go value before invoking fn. Empty arguments decode as the zero value of T. JSON decode failures surface to the model as an error ToolResult — matching the existing manual pattern — so a malformed call does not crash the loop.
Callers still supply spec.Parameters (a JSON Schema). Schema generation from T is intentionally out of scope.
func SubagentTool ¶
func SubagentTool(opts SubagentOptions) (Tool, error)
SubagentTool exposes a child Agent as a Tool. Each tool call creates a fresh child session, forwards only the explicit prompt argument, and returns the child agent's final text as the tool result. Child prompt failures become model-visible error results except for context cancellation/deadline errors, which are returned as Go errors so the parent loop stops promptly.
type ToolCall ¶
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type ToolExecutor ¶
type ToolExecutor = loop.ToolExecutor
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
type ToolResult ¶
type ToolResult = loop.ToolResult
Re-export the loop package's normalized types as part of the public API so callers only need to import `glue`.
func ErrorResult ¶
func ErrorResult(err error) ToolResult
ErrorResult wraps an error in a ToolResult tagged with IsError=true so the model sees it as a tool failure rather than the loop crashing. The error's Error() string becomes the visible text.
func TextResult ¶
func TextResult(s string) ToolResult
TextResult wraps a string in a ToolResult with a single text content part. Use it from tool executors when the tool succeeds with textual output.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
agents
|
|
|
glue-review
command
Command glue-review is a free, local pre-push branch reviewer built on the Glue agent harness.
|
Command glue-review is a free, local pre-push branch reviewer built on the Glue agent harness. |
|
peggy
Package peggy is a long-running personal-assistant agent built on the glue framework.
|
Package peggy is a long-running personal-assistant agent built on the glue framework. |
|
peggy/channels/telegram
Package telegram is the Telegram-bot channel adapter for Peggy.
|
Package telegram is the Telegram-bot channel adapter for Peggy. |
|
peggy/cmd/peggy
command
Command peggy is the CLI entry point for the personal-assistant agent.
|
Command peggy is the CLI entry point for the personal-assistant agent. |
|
peggy/cmd/peggy-telegram
command
Command peggy-telegram is the binary form of the Telegram channel adapter.
|
Command peggy-telegram is the binary form of the Telegram channel adapter. |
|
Package cli provides small helpers downstream agents share with the canonical cmd/glue runner.
|
Package cli provides small helpers downstream agents share with the canonical cmd/glue runner. |
|
cmd
|
|
|
glue
command
Command glue is the local CLI runner for Glue agents.
|
Command glue is the local CLI runner for Glue agents. |
|
glue/tui
Package tui implements the interactive multi-turn terminal interface for `glue run`.
|
Package tui implements the interactive multi-turn terminal interface for `glue run`. |
|
Package daemon serves local Glue sessions over the ADR-0010 HTTP+SSE protocol.
|
Package daemon serves local Glue sessions over the ADR-0010 HTTP+SSE protocol. |
|
examples
|
|
|
echo-provider
Package echo is a minimal example of a custom Glue provider.
|
Package echo is a minimal example of a custom Glue provider. |
|
local-agent
command
Command local-agent is a small Gemini-backed CLI built directly on the glue library.
|
Command local-agent is a small Gemini-backed CLI built directly on the glue library. |
|
Package loop contains Glue's provider-agnostic agent loop.
|
Package loop contains Glue's provider-agnostic agent loop. |
|
Package prompts provides a small versioned-prompt loader that wraps an embed.FS rooted at a directory of `<name>.md` files.
|
Package prompts provides a small versioned-prompt loader that wraps an embed.FS rooted at a directory of `<name>.md` files. |
|
Package providers exposes a small driver-style registry of provider constructors.
|
Package providers exposes a small driver-style registry of provider constructors. |
|
codex
Package codex is a glue.Provider that routes through the Codex Responses endpoint at chatgpt.com/backend-api/codex/responses, authenticated with a ChatGPT subscription via OAuth tokens read from the upstream Codex CLI's auth.json (run "codex login" once outside glue).
|
Package codex is a glue.Provider that routes through the Codex Responses endpoint at chatgpt.com/backend-api/codex/responses, authenticated with a ChatGPT subscription via OAuth tokens read from the upstream Codex CLI's auth.json (run "codex login" once outside glue). |
|
codex/auth
Package auth handles ChatGPT-subscription OAuth tokens for the providers/codex transport.
|
Package auth handles ChatGPT-subscription OAuth tokens for the providers/codex transport. |
|
gemini
Package gemini adapts Google's Gemini API to Glue's provider interface using the google.golang.org/genai SDK.
|
Package gemini adapts Google's Gemini API to Glue's provider interface using the google.golang.org/genai SDK. |
|
nvidia
Package nvidia implements a Glue provider for the NVIDIA build inference API (https://build.nvidia.com), which exposes an OpenAI-compatible chat-completions endpoint at https://integrate.api.nvidia.com/v1.
|
Package nvidia implements a Glue provider for the NVIDIA build inference API (https://build.nvidia.com), which exposes an OpenAI-compatible chat-completions endpoint at https://integrate.api.nvidia.com/v1. |
|
openaicompat
Package openaicompat implements the shared streaming, tool-call, and convert logic for OpenAI-style chat-completions endpoints used by the concrete providers under providers/.
|
Package openaicompat implements the shared streaming, tool-call, and convert logic for OpenAI-style chat-completions endpoints used by the concrete providers under providers/. |
|
openrouter
Package openrouter implements a Glue provider for OpenRouter (https://openrouter.ai), an OpenAI-compatible aggregator that routes requests across many underlying model providers.
|
Package openrouter implements a Glue provider for OpenRouter (https://openrouter.ai), an OpenAI-compatible aggregator that routes requests across many underlying model providers. |
|
stores
|
|
|
file
Package file provides a local JSON-backed session store for Glue.
|
Package file provides a local JSON-backed session store for Glue. |
|
sqlite
Package sqlite provides a SQLite-backed glue.Store with FTS5 over message text.
|
Package sqlite provides a SQLite-backed glue.Store with FTS5 over message text. |
|
tools
|
|
|
coding
Package coding assembles the reusable local coding-agent tool bundle.
|
Package coding assembles the reusable local coding-agent tool bundle. |
|
fs
Package fs provides filesystem helpers and tool factories that agents can register without reinventing path safety, output truncation, or the sensitive-file blocklist.
|
Package fs provides filesystem helpers and tool factories that agents can register without reinventing path safety, output truncation, or the sensitive-file blocklist. |
|
git
Package git provides git tool factories and shell-out helpers that agents can register without re-implementing PATH lookup, timeout management, or pathspec construction.
|
Package git provides git tool factories and shell-out helpers that agents can register without re-implementing PATH lookup, timeout management, or pathspec construction. |
|
mcp
Package mcp implements the client foundation for consuming Model Context Protocol servers from glue hosts.
|
Package mcp implements the client foundation for consuming Model Context Protocol servers from glue hosts. |
|
shell
Package shell provides permission-gated command execution tools for agents that explicitly opt into local coding workflows.
|
Package shell provides permission-gated command execution tools for agents that explicitly opt into local coding workflows. |