sysprompt

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package sysprompt builds the agent's system prompt: a hardcoded base instruction block, the workspace bootstrap files (framed, ordered, capped), an optional tool catalog, and a per-turn runtime line. The result is split into a stable prefix (cacheable) and a dynamic suffix (per-turn) so prompt caching can be wired later without restructuring.

Index

Constants

View Source
const DefaultBase = `` /* 888-byte string literal not displayed */

DefaultBase is the always-present operational floor. It provides a default agent identity ("Sahara") plus operating rules; persona, voice, and conventions otherwise come from the project context files (IDENTITY.md, SOUL.md, AGENTS.md, ...) that layer on top. These rules hold even if those files are absent or edited.

Variables

This section is empty.

Functions

func DefaultWorkspaceFiles

func DefaultWorkspaceFiles() []bootstrap.File

DefaultWorkspaceFiles returns the embedded default bootstrap files, sorted by name. Callers seed these into a fresh workspace (no-clobber) so a new sandbox has a real persona rather than an empty workspace.

Types

type AttachmentSummary

type AttachmentSummary struct {
	Name    string
	Mime    string
	Size    int64
	Purpose string
	Path    string
	// Error, when non-empty, means the attachment could NOT be materialized
	// (fetch/permission failure). It is still listed — so the model knows an
	// input was provided but is missing rather than pursuing the task blind —
	// with this reason and no Path/usable bytes.
	Error string
}

AttachmentSummary is a non-image file the user attached to the current turn's message — an "attachment" (a novel upload) or a "document" (already preprocessed by MemoryLayer). The harness materializes it to disk and lists it here so the model knows what it was given and can open it with its file tools; the bytes are NOT inlined into the request (only images are). Path is an absolute, tool-readable location; Purpose is the spec FilePart purpose ("document"/"attachment"/"").

type AutoLoadedSkill

type AutoLoadedSkill struct {
	Name string
	Body string
}

AutoLoadedSkill is a skill whose full body was injected into context this turn because a relevance provider judged it relevant (no load_skill call needed).

type Input

type Input struct {
	Base      string // base instructions; DefaultBase if empty
	Bootstrap []bootstrap.File
	Tools     []ToolSummary
	Skills    []SkillSummary
	// SkillsDynamic renders the "## Skills" listing in the dynamic suffix rather
	// than the cacheable prefix — set when a relevance provider makes the listing
	// per-turn. Off (default) keeps the full catalog in the stable, cacheable prefix.
	SkillsDynamic bool
	// SkillLoadTool reports that the load_skill tool is registered, so the "## Skills"
	// section instructs the model to load a skill by name (load_skill resolves the
	// file + prerequisites) instead of reading its file directly. Off -> the model is
	// told to read_file the skill path (the path is then listed per skill).
	SkillLoadTool bool
	// SkillsHidden is the count of catalog skills NOT shown in the listing because a
	// relevance provider capped it (ListReplace). >0 renders a "+N more available"
	// hint so the model knows the listing is a relevance-filtered subset, not the
	// whole catalog. 0 -> no hint.
	SkillsHidden     int
	AutoLoadedSkills []AutoLoadedSkill // bodies injected this turn by a relevance provider (dynamic)
	LoadedSkills     []LoadedSkill     // previously loaded via load_skill (dynamic; carries age)
	// SkillLoadWarnings are skill-discovery validation warnings (see
	// skills.DiscoverWithWarnings) — e.g. a malformed skill name or an over-cap
	// description. Derived from untrusted on-disk content, so each is
	// HTML-escaped and framed as non-instructional when rendered.
	SkillLoadWarnings []string
	RecentFiles       []RecentFile   // files written/edited this session (dynamic; carries age)
	Todos             []TodoLine     // the agent's todo board (dynamic; carries age)
	Subagents         []SubagentLine // sub-agents delegated to this session (dynamic; carries age)
	// Attachments are the non-image files attached to the current turn's user
	// message, materialized to disk and surfaced as a text listing (name/mime/size
	// + on-disk path) so the model can open them with its file tools. Images are
	// delivered inline (not listed here). Per-turn (dynamic); empty -> omitted.
	Attachments []AttachmentSummary
	// PromptNotes are authoritative reusable workspace instructions. They are
	// dynamic because the resolved workspace and current revisions can differ per
	// turn. The assembler validates and orders them before Build.
	PromptNotes []PromptNote
	// RequestInstructions are per-turn caller-supplied instructions (e.g. an
	// agent.synthesize one-shot's options.system/instructions), rendered as the
	// last, highest-salience suffix section. Authenticated request config; empty ->
	// omitted.
	RequestInstructions string
	MemoryTools         bool // emit the Memory guidance section (memory_search/memory_get available)
	SubagentsEnabled    bool // emit the delegation guidance section (spawn_subagent available)
	MaxFileBytes        int  // per-file cap for bootstrap content; 0 disables capping
	WorkspaceDir        string
	Model               string
	SandboxID           string
	Now                 time.Time // zero -> runtime line omits time
}

Input is the data composed into the system prompt.

type LoadedSkill

type LoadedSkill struct {
	Name     string
	AgeTurns int
}

LoadedSkill is a skill previously loaded via load_skill this session, with its age in turns (0 = loaded this turn). Rendered in the dynamic suffix so the model knows what it has loaded and how stale it is — its body may have been compacted out of context, in which case it should reload.

type Prompt

type Prompt struct {
	StablePrefix  string // base + tools + project context (cacheable)
	DynamicSuffix string // runtime line (changes per turn)
}

Prompt is the assembled system prompt, split for cacheability.

func Build

func Build(in Input) Prompt

Build composes the system prompt from in.

func (Prompt) Message

func (p Prompt) Message() (protocol.ChatMessage, error)

Message returns the prompt as a single system-role ChatMessage.

The stable prefix is emitted as a literal byte-prefix of the content (only the runtime line trails), so providers that do automatic prefix caching (e.g. OpenAI) cache it for free. For providers that need an explicit breakpoint (e.g. Anthropic cache_control), the message carries a meta hint meta.scitrera.cache.stable_prefix_chars marking where the cacheable prefix ends; the sidecar consumes it. The OpenAI request encoding drops meta, so direct providers never see the hint.

func (Prompt) Text

func (p Prompt) Text() string

Text joins the prompt into a single string.

type PromptNote added in v0.0.2

type PromptNote struct {
	Key     string `json:"key"`
	Title   string `json:"title,omitempty"`
	Content string `json:"instructions"`
}

PromptNote is an enabled, workspace-scoped reusable instruction. Key is the stable ordering/identity handle; Title is optional display context.

type RecentFile

type RecentFile struct {
	Path     string
	Kind     string // write | edit
	AgeTurns int
}

RecentFile is a file the agent wrote/edited this session, with its age in turns. Rendered so the model recalls what it produced even after the tool result that created it was compacted out.

type SkillSummary

type SkillSummary struct {
	Name        string
	Description string
	Path        string
	Note        string
}

SkillSummary is a skill the agent can load on demand (lazy: the model reads the file at Path when it decides to use the skill). Note is an optional relevance hint (from a SkillRelevanceProvider) shown next to the skill.

type SubagentLine

type SubagentLine struct {
	Name     string
	ThreadID string
	Status   string
	Summary  string
	AgeTurns int
}

SubagentLine is a specialist the agent delegated to this session (via spawn_subagent), with its re-addressable thread_id handle, status, short summary, and age. Rendered so the orchestrator sees its live sub-agents and can route a follow-up to one (spawn_subagent thread=<id>) instead of re-delegating.

type TodoLine

type TodoLine struct {
	Content  string
	Status   string
	AgeTurns int
}

TodoLine is a todo from the agent's board, with its age (turns since last updated). Rendered so the working checklist survives compaction.

type ToolSummary

type ToolSummary struct {
	Name        string
	Description string
}

ToolSummary is a tool's model-facing name + one-line description.

Jump to

Keyboard shortcuts

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