prompt

package
v1.0.0-beta.9 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package prompt provides fragment-based system prompt assembly for agentic loops. Prompts are composed from ordered fragments filtered by role, provider, and runtime conditions. Inspired by semdragon's promptmanager but simplified for semteams' architecture.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssembledPrompt

type AssembledPrompt struct {
	SystemMessage string   // Composed system prompt
	FragmentsUsed []string // Fragment IDs included (for observability)
}

AssembledPrompt is the output of the assembly process.

func Assemble

func Assemble(registry *Registry, ctx *AssemblyContext) AssembledPrompt

Assemble composes a system prompt from registry fragments filtered by context. Fragments are ordered by category then priority, and their content is concatenated with double newlines between sections.

type AssemblyContext

type AssemblyContext struct {
	// Agent identity
	Role     string // Agent role (general, architect, editor, reviewer, explorer, etc.)
	LoopID   string
	Depth    int // Nesting depth (0 = top-level)
	MaxDepth int

	// Task info
	Prompt       string   // User's original prompt
	WorkflowSlug string   // Optional workflow identifier
	WorkflowStep string   // Current step in workflow
	Tools        []string // Available tool names

	// Runtime state
	Iteration     int
	MaxIterations int
	ParentLoopID  string // Non-empty if this is a child agent

	// Provider hint for formatting
	Provider string // "anthropic", "openai", "ollama", etc.
}

AssemblyContext provides runtime information for fragment filtering and dynamic content generation.

type Category

type Category int

Category determines the order of fragments in the assembled prompt. Lower values appear earlier. Categories provide semantic grouping without requiring knowledge of specific fragment content.

const (
	// CategorySystem contains core identity and behavioral constraints.
	CategorySystem Category = 0
	// CategoryRole contains role-specific instructions (architect, editor, reviewer, etc.).
	CategoryRole Category = 100
	// CategoryTools contains tool usage guidance and restrictions.
	CategoryTools Category = 200
	// CategoryDomain contains domain context (project knowledge, entity relationships).
	CategoryDomain Category = 300
	// CategoryConstraints contains guardrails, budget limits, safety rules.
	CategoryConstraints Category = 400
	// CategoryContext contains runtime context (prior conversation, dependencies).
	CategoryContext Category = 500
)

type Fragment

type Fragment struct {
	ID       string   // Unique identifier for observability
	Category Category // Determines ordering (lower = earlier)
	Priority int      // Ordering within category (lower = earlier)
	Content  string   // Static content (used when ContentFunc is nil)

	// ContentFunc generates content dynamically at assembly time.
	// Takes precedence over Content when non-nil.
	ContentFunc func(ctx *AssemblyContext) string

	// Condition determines whether this fragment is included.
	// When nil, the fragment is always included.
	Condition func(ctx *AssemblyContext) bool

	// Roles restricts this fragment to specific agent roles.
	// Empty means all roles.
	Roles []string
}

Fragment is an atomic unit of prompt content that can be conditionally included and ordered by category during assembly.

func DefaultFragments

func DefaultFragments() []Fragment

DefaultFragments returns the base set of prompt fragments used by all agents. These provide the core behavioral framework. Role-specific fragments should be added separately via the registry.

type Registry

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

Registry holds prompt fragments and filters them by context at assembly time.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty fragment registry.

func (*Registry) Add

func (r *Registry) Add(f Fragment)

Add registers a fragment. Thread-safe.

func (*Registry) AddAll

func (r *Registry) AddAll(fragments []Fragment)

AddAll registers multiple fragments.

func (*Registry) GetForContext

func (r *Registry) GetForContext(ctx *AssemblyContext) []Fragment

GetForContext returns fragments matching the given context, ordered by category (ascending) then priority (ascending) within each category.

func (*Registry) Upsert

func (r *Registry) Upsert(f Fragment)

Upsert replaces the fragment with the same ID or appends a new one. Callers layer KV-backed personas on top of DefaultFragments via this — a stored persona with ID "role-researcher" overrides the in-code researcher fragment without forcing a rebuild of the registry.

func (*Registry) UpsertAll

func (r *Registry) UpsertAll(fragments []Fragment)

UpsertAll applies Upsert for each fragment under a single lock acquire. Preferred over a loop of Upsert calls when loading a batch of overrides.

Jump to

Keyboard shortcuts

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