Skip to main content

internal/infra/inference/summariser.go

internal/infra/inference · 179 lines · 12 declarations · source

Declarations

var compactionPromptFile

var compactionPromptFile []byte

The compaction prompt is a file for the same reasons the report prompt is, and compiled in for the same reason: a segment stands in for somebody's history, so a prompt the filesystem can change is a path by which whoever can write next to the binary changes what an agent is told happened.

source

var compactionPrompt

var compactionPrompt = mustLoadCompactionPrompt(compactionPromptFile)

compactionPrompt is parsed once, at startup, with the report prompt's loader: the two files have the same sections because they answer the same questions, what the model is for, what grounds it, what shape it answers in, and where the data begins.

source

func mustLoadCompactionPrompt

func mustLoadCompactionPrompt(raw []byte) reportPromptFileShape

source

type Summariser

type Summariser struct {
config Config
client *http.Client
}

Summariser writes segments by asking a chat model.

It writes prose and nothing more. What a segment covers, when it is written and what an erasure does to it are the compaction package's and the pass's decisions, and they must not vary with the vendor.

source

func NewSummariser

func NewSummariser(config Config) *Summariser

NewSummariser builds a segment writer against an OpenAI-compatible endpoint.

source

method Summariser.Write

func (s *Summariser) Write(ctx context.Context, m compaction.Material) (compaction.Summary, error)

Write asks the model to condense one stretch of history.

source

func compactionSystemPrompt

func compactionSystemPrompt() string

compactionSystemPrompt composes the file's sections in their fixed order, the boundary last.

source

func decodeSummary

func decodeSummary(content string) (compaction.Summary, error)

decodeSummary reads the reply, locating the JSON object inside whatever the model sent, and refuses an empty summary: a segment that says nothing would stand in for turns and lose them.

source

func nextBrace

func nextBrace(s string, after int) int

source

func lastBrace

func lastBrace(s string) int

source

func renderMaterial

func renderMaterial(m compaction.Material) string

renderMaterial writes the material out, fenced, in log order. The order is the conversation's own, and it is fixed so two writes of one range say the same thing.

source

func materialWords

func materialWords(m compaction.Material) string

materialWords is every byte of somebody else's words in the material, which the fence must be absent from.

source