Documentation
¶
Index ¶
- Constants
- func BuildContext(sessionID string, turnNumber int, workingDirectory string, ...) map[string]string
- func BuildContextWithGit(sessionID string, turnNumber int, workingDirectory string, ...) map[string]string
- func BuildProviderRequest(canonicalPrompt CacheSafePrompt, model types.ModelIdentifier, ...) types.APIRequest
- func BuildProviderRequestWithAppendPrompt(ctx context.Context, builder *Builder, sessionID types.SessionID, ...) (types.APIRequest, error)
- func BuildProviderRequestWithHints(canonicalPrompt CacheSafePrompt, model types.ModelIdentifier, ...) types.APIRequest
- func BuildProviderToolDefinitions(tools map[string]tool.Tool) []types.APIToolDefinition
- func BuildProviderToolDefinitionsWithHints(tools map[string]tool.Tool, hints map[string]string) []types.APIToolDefinition
- func HashTools(tools map[string]tool.Tool) string
- func SeshatCoreStablePrompt() string
- type Assembler
- type BuildInput
- type BuildResult
- type Builder
- func (b *Builder) BuildCacheSafeParams(ctx context.Context, input FetchSystemPromptPartsInput) (CacheSafeParams, error)
- func (b *Builder) BuildCanonicalPrompt(ctx context.Context, sessionID types.SessionID, turnNumber int, ...) (CacheSafePrompt, error)
- func (b *Builder) BuildSystemPrompt(ctx context.Context, sessionID types.SessionID, turnNumber int, ...) (string, error)
- func (b *Builder) ClearStaleEntries() int
- func (b *Builder) FetchSystemPromptParts(ctx context.Context, input FetchSystemPromptPartsInput) (SystemPromptParts, error)
- func (b *Builder) GetCacheSize() int
- func (b *Builder) InvalidateByToolHash(toolHash string)
- func (b *Builder) InvalidateCache()
- func (b *Builder) InvalidateSectionCache(sectionNames []string)
- type BuilderConfig
- type CacheEntry
- type CacheHitResult
- type CacheSafeParams
- type CacheSafePrompt
- type ExecutionStage
- type FetchSystemPromptPartsInput
- type PromptCache
- func (c *PromptCache) ClearStaleEntries() int
- func (c *PromptCache) GetSectionCache(sectionNames []string, tools map[string]tool.Tool, model types.ModelIdentifier, ...) (*CacheHitResult, bool)
- func (c *PromptCache) InvalidateAll()
- func (c *PromptCache) InvalidateByToolHash(toolHash string)
- func (c *PromptCache) InvalidateSectionCache(sectionNames []string)
- func (c *PromptCache) SetSectionCache(sectionNames []string, content string, tools map[string]tool.Tool, ...)
- func (c *PromptCache) Size() int
- type Section
- type SectionType
- type SystemPromptParts
Constants ¶
const SystemPromptDynamicBoundary = "__SYSTEM_PROMPT_DYNAMIC_BOUNDARY__"
SystemPromptDynamicBoundary is a structural marker, not rendered prompt text. Everything before it belongs to the stable prefix; everything after it is treated as dynamic runtime context.
Variables ¶
This section is empty.
Functions ¶
func BuildContext ¶
func BuildContext(sessionID string, turnNumber int, workingDirectory string, availableTools []string) map[string]string
BuildContext builds context information for the prompt
func BuildContextWithGit ¶
func BuildContextWithGit(sessionID string, turnNumber int, workingDirectory string, availableTools []string, gitRoot string, gitBranch string) map[string]string
BuildContextWithGit builds context information including git context
func BuildProviderRequest ¶
func BuildProviderRequest( canonicalPrompt CacheSafePrompt, model types.ModelIdentifier, messages []types.Message, tools map[string]tool.Tool, maxTokens int, stream bool, ) types.APIRequest
BuildProviderRequest converts a canonical prompt plus a tool map into the provider-facing API request shape used by Seshat.
func BuildProviderRequestWithAppendPrompt ¶
func BuildProviderRequestWithAppendPrompt( ctx context.Context, builder *Builder, sessionID types.SessionID, turnNumber int, workingDirectory string, parts SystemPromptParts, appendPrompt *string, messages []types.Message, tools map[string]tool.Tool, model types.ModelIdentifier, maxTokens int, stream bool, ) (types.APIRequest, error)
BuildProviderRequestWithAppendPrompt bridges canonical prompt assembly and the provider-facing request model. Session/query code goes through this helper so the provider sees the same prompt split that prompt assembly already computed, instead of rebuilding a second system prompt shape later in the stack.
func BuildProviderRequestWithHints ¶
func BuildProviderRequestWithHints( canonicalPrompt CacheSafePrompt, model types.ModelIdentifier, messages []types.Message, tools map[string]tool.Tool, toolHints map[string]string, maxTokens int, stream bool, ) types.APIRequest
func BuildProviderToolDefinitions ¶
func BuildProviderToolDefinitions(tools map[string]tool.Tool) []types.APIToolDefinition
BuildProviderToolDefinitions builds a stable provider-facing tool surface. We only expose canonical primary names here: aliases are a runtime lookup convenience, but sending them to the provider would make the prompt surface unstable and drift away from the execution contract.
func BuildProviderToolDefinitionsWithHints ¶
func BuildProviderToolDefinitionsWithHints(tools map[string]tool.Tool, hints map[string]string) []types.APIToolDefinition
BuildProviderToolDefinitionsWithHints builds provider-facing tool definitions and appends per-tool guidance from hints. Keys in hints are canonical tool names.
func SeshatCoreStablePrompt ¶
func SeshatCoreStablePrompt() string
SeshatCoreStablePrompt returns the concatenated stable sections that form the Seshat default agent identity (identity + rules + workflow + examples). Use this as a baseline when building a custom agent that extends Seshat rather than replacing it entirely.
Types ¶
type Assembler ¶
type Assembler struct {
// contains filtered or unexported fields
}
Assembler assembles system prompts from sections
func (*Assembler) AddSection ¶
AddSection adds a section
func (*Assembler) AddSections ¶
AddSections adds multiple sections
func (*Assembler) Build ¶
func (a *Assembler) Build(input BuildInput) (BuildResult, error)
Build builds the system prompt.
func (*Assembler) SetDefaultSections ¶
SetDefaultSections sets the default sections
type BuildInput ¶
type BuildInput struct {
// Sections are the prompt sections
Sections []Section `json:"sections"`
// Variables are template variables
Variables map[string]string `json:"variables,omitempty"`
// OverrideSystemPrompt overrides the system prompt entirely
OverrideSystemPrompt *string `json:"override_system_prompt,omitempty"`
// Model is the model being used
Model string `json:"model,omitempty"`
}
BuildInput represents input for building a prompt
type BuildResult ¶
type BuildResult struct {
// SystemPrompt is the assembled system prompt
SystemPrompt string `json:"system_prompt"`
// CacheBreakpoint is where the cache boundary is
CacheBreakpoint int `json:"cache_breakpoint"`
// StaticText is the cacheable part
StaticText string `json:"static_text"`
// DynamicText is the non-cacheable part
DynamicText string `json:"dynamic_text"`
// FullText is the complete prompt
FullText string `json:"full_text"`
// VariablesUsed are the variables that were used
VariablesUsed []string `json:"variables_used,omitempty"`
}
BuildResult represents the result of building a prompt
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder assembles canonical system prompt parts and then composes a per-turn provider-facing prompt from those parts.
func NewBuilder ¶
func NewBuilder(assembler *Assembler, config *BuilderConfig) *Builder
NewBuilder creates a new prompt builder.
func (*Builder) BuildCacheSafeParams ¶
func (b *Builder) BuildCacheSafeParams( ctx context.Context, input FetchSystemPromptPartsInput, ) (CacheSafeParams, error)
BuildCacheSafeParams builds cache-safe parameters.
func (*Builder) BuildCanonicalPrompt ¶
func (b *Builder) BuildCanonicalPrompt( ctx context.Context, sessionID types.SessionID, turnNumber int, workingDirectory string, parts SystemPromptParts, appendPrompt *string, ) (CacheSafePrompt, error)
BuildCanonicalPrompt composes a per-turn canonical prompt from fetched parts.
func (*Builder) BuildSystemPrompt ¶
func (b *Builder) BuildSystemPrompt( ctx context.Context, sessionID types.SessionID, turnNumber int, workingDirectory string, parts SystemPromptParts, appendPrompt *string, ) (string, error)
BuildSystemPrompt builds the final flattened system prompt from canonical parts.
func (*Builder) ClearStaleEntries ¶
ClearStaleEntries supprime les entrées expirées du cache
func (*Builder) FetchSystemPromptParts ¶
func (b *Builder) FetchSystemPromptParts( ctx context.Context, input FetchSystemPromptPartsInput, ) (SystemPromptParts, error)
FetchSystemPromptParts fetches the stable prefix and the dynamic context maps. Uses prompt cache for stable sections when enabled.
func (*Builder) GetCacheSize ¶
GetCacheSize retourne le nombre d'entrées cacheées
func (*Builder) InvalidateByToolHash ¶
InvalidateByToolHash invalide toutes les entrées dépendant d'un hash d'outils
func (*Builder) InvalidateCache ¶
func (b *Builder) InvalidateCache()
InvalidateCache invalide tout le cache de prompt Appelé sur /clear, /compact, ou changement significatif de configuration
func (*Builder) InvalidateSectionCache ¶
InvalidateSectionCache invalide des sections spécifiques
type BuilderConfig ¶
type BuilderConfig struct {
EnableCaching bool `json:"enable_caching"`
CacheBoundaryPosition int `json:"cache_boundary_position"`
}
BuilderConfig represents the builder configuration.
func DefaultBuilderConfig ¶
func DefaultBuilderConfig() *BuilderConfig
DefaultBuilderConfig returns default builder configuration.
type CacheEntry ¶
type CacheEntry struct {
Content string
ComputedAt time.Time
SectionNames []string
ToolHash string
ModelConfig string
ValidUntil *time.Time // nil = valide jusqu'à invalidation explicite
}
CacheEntry represents a cached prompt section
type CacheHitResult ¶
CacheHitResult represents a cache hit with metadata
type CacheSafeParams ¶
type CacheSafeParams struct {
SystemPrompt string
UserContext map[string]string
SystemContext map[string]string
Tools map[string]tool.Tool
Model types.ModelIdentifier
CustomPrompt *string
AppendPrompt *string
}
CacheSafeParams represents cache-safe parameters for query.
type CacheSafePrompt ¶
type CacheSafePrompt struct {
SystemPrompt string `json:"system_prompt"`
StableText string `json:"stable_text"`
DynamicText string `json:"dynamic_text"`
CacheBreakpoint int `json:"cache_breakpoint"`
UserContext map[string]string `json:"user_context,omitempty"`
SystemContext map[string]string `json:"system_context,omitempty"`
SystemPromptBlocks []types.SystemPromptBlock `json:"system_prompt_blocks,omitempty"`
}
CacheSafePrompt is the canonical provider-facing prompt representation.
type ExecutionStage ¶
type ExecutionStage string
ExecutionStage is the current execution stage of the engine. An overlay section is injected into the dynamic part of the system prompt when the stage is not StageDefault.
const ( // StageDefault is the baseline mode — no overlay injected. StageDefault ExecutionStage = "" // StageToolCall is set when the model is expected to dispatch tool calls. StageToolCall ExecutionStage = "tool_call" // StageToolResult is set when tool results are being sent back to the model. StageToolResult ExecutionStage = "tool_result" // StageContinuation is set when the loop injects a continuation nudge. StageContinuation ExecutionStage = "continuation" // StagePlan is set when the engine is in plan mode (tools shown, not executed). StagePlan ExecutionStage = "plan" )
type FetchSystemPromptPartsInput ¶
type FetchSystemPromptPartsInput struct {
Tools map[string]tool.Tool `json:"-"`
Model types.ModelIdentifier `json:"model"`
WorkingDirectory string `json:"working_directory,omitempty"`
DeferredToolNames []string `json:"deferred_tool_names,omitempty"`
MemoryContext string `json:"memory_context,omitempty"`
AdditionalWorkingDirectories []string `json:"additional_working_directories,omitempty"`
MCPClients []string `json:"mcp_clients,omitempty"`
CustomSystemPrompt *string `json:"custom_system_prompt,omitempty"`
AppendSystemPrompt *string `json:"append_system_prompt,omitempty"`
// Stage sets the execution stage overlay injected into the dynamic section.
Stage ExecutionStage `json:"stage,omitempty"`
// StageOverrides replaces the built-in stage overlay text per stage.
StageOverrides map[ExecutionStage]string `json:"-"`
// ToolHints provides per-tool extra guidance appended to provider-facing
// tool descriptions. Key is the canonical tool name.
ToolHints map[string]string `json:"-"`
// ProjectInstructions is the content of a project-level instructions file
// (e.g. SESHAT.md, AGENTS.md). Injected into the system prompt before the
// memory context section so it takes precedence over accumulated patterns.
ProjectInstructions string `json:"project_instructions,omitempty"`
}
FetchSystemPromptPartsInput represents input for fetching system prompt parts.
type PromptCache ¶
type PromptCache struct {
// contains filtered or unexported fields
}
PromptCache gère la mémoïsation des sections de prompt
func (*PromptCache) ClearStaleEntries ¶
func (c *PromptCache) ClearStaleEntries() int
ClearStaleEntries removes expired entries from the cache
func (*PromptCache) GetSectionCache ¶
func (c *PromptCache) GetSectionCache( sectionNames []string, tools map[string]tool.Tool, model types.ModelIdentifier, env map[string]string, ) (*CacheHitResult, bool)
GetSectionCache tente de récupérer une section cacheée
func (*PromptCache) InvalidateAll ¶
func (c *PromptCache) InvalidateAll()
InvalidateAll invalide tout le cache
func (*PromptCache) InvalidateByToolHash ¶
func (c *PromptCache) InvalidateByToolHash(toolHash string)
InvalidateByToolHash invalide toutes les entrées dépendant d'un hash d'outils
func (*PromptCache) InvalidateSectionCache ¶
func (c *PromptCache) InvalidateSectionCache(sectionNames []string)
InvalidateSectionCache invalide des sections spécifiques
func (*PromptCache) SetSectionCache ¶
func (c *PromptCache) SetSectionCache( sectionNames []string, content string, tools map[string]tool.Tool, model types.ModelIdentifier, env map[string]string, ttl *time.Duration, )
SetSectionCache met en cache une section
func (*PromptCache) Size ¶
func (c *PromptCache) Size() int
Size returns the number of cached entries
type Section ¶
type Section struct {
// Type is the section type
Type SectionType `json:"type"`
// Name identifies this section
Name string `json:"name"`
// Content is the section content
Content string `json:"content"`
// Priority determines order (higher = earlier)
Priority int `json:"priority"`
// Cacheable indicates if this section can be cached
Cacheable bool `json:"cacheable"`
// DynamicBoundary indicates this section marks the cache boundary
DynamicBoundary bool `json:"dynamic_boundary"`
// Enabled indicates if this section is active
Enabled bool `json:"enabled"`
}
Section represents a part of the system prompt
func DefaultSystemPromptSections ¶
func DefaultSystemPromptSections() []Section
DefaultSystemPromptSections returns the canonical prompt sections in stable order.
type SectionType ¶
type SectionType string
SectionType represents the type of a prompt section
const ( SectionTypeDefault SectionType = "default" SectionTypeUser SectionType = "user" SectionTypeSystem SectionType = "system" SectionTypeDynamic SectionType = "dynamic" SectionTypeAppend SectionType = "append" )
type SystemPromptParts ¶
type SystemPromptParts struct {
DefaultSystemPrompt []string `json:"default_system_prompt"`
UserContext map[string]string `json:"user_context"`
SystemContext map[string]string `json:"system_context"`
StableText string `json:"stable_text,omitempty"`
DynamicText string `json:"dynamic_text,omitempty"`
CacheBreakpoint int `json:"cache_breakpoint,omitempty"`
// Stage and StageOverrides are propagated to BuildCanonicalPrompt so the
// dynamic section remains stage-aware across the two-phase build path.
Stage ExecutionStage `json:"stage,omitempty"`
StageOverrides map[ExecutionStage]string `json:"-"`
// ToolHints provides per-tool extra guidance used when building provider
// tool definitions for this turn.
ToolHints map[string]string `json:"-"`
}
SystemPromptParts captures the stable prefix and the dynamic context maps needed to rebuild the final prompt for a given turn.