prompt

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package prompt renders a conversation into the single prompt string an agent CLI accepts.

Every request replays the full history into a fresh CLI process, so the rendering must be deterministic and unambiguous: a message whose text looks like a role marker must not be able to forge one.

Why a marker transcript rather than the CLI's own message format

Flattening a conversation into one string looks like a workaround for a missing feature, and Claude Code does have `--input-format stream-json`, which takes a stream of message objects. It is not the better path, and the reason is worth writing down so nobody spends the afternoon finding out again.

That mode is an interactive session, not a history replay: it answers every user message it is given. Feeding it three lines — user, assistant, user — produced two completions, one for each user turn, and the assistant line supplied as history did not stand in for the first answer. Replaying an n-turn conversation would cost n generations instead of one, and the caller would pay for answers nobody asked for. Codex and cursor-agent have no structured-input mode at all.

So the transcript stays. Its cost is that the backend sees "continue this record" rather than a conversation it took part in.

Index

Constants

View Source
const (
	MarkerSystem    = "<<<SYSTEM>>>"
	MarkerUser      = "<<<USER>>>"
	MarkerAssistant = "<<<ASSISTANT>>>"
)

Role markers delimit turns in a rendered transcript. They are chosen to be unlikely in prose and are escaped when they do appear (see [escape]).

View Source
const Header = `Below is a conversation transcript. Lines beginning with ` + MarkerUser +
	` or ` + MarkerAssistant + ` mark who is speaking; a marker preceded by a backslash is
literal text, not a marker. Continue the conversation by writing only the
assistant's next message: no role markers, no restating of earlier turns.`

Header explains the transcript format to the backend. It is only prepended for multi-turn conversations; a lone user message is passed through verbatim so single-turn requests read exactly as the caller wrote them.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rendered

type Rendered struct {
	// System is the concatenation of the conversation's system messages.
	// Adapters should pass it through the CLI's native system-prompt flag.
	System string
	// Prompt is the transcript to feed the CLI as the user prompt.
	Prompt string
}

Rendered is the result of turning a conversation into CLI input.

func Render

func Render(msgs []ir.Message) Rendered

Render turns a conversation into CLI input.

System messages are collected (in order, joined by a blank line) into Rendered.System regardless of position. The remaining turns become Rendered.Prompt: a single user turn is passed through verbatim; anything longer is rendered as a marked-up transcript ending at the assistant's cue.

func (Rendered) PromptWithSystem

func (r Rendered) PromptWithSystem() string

PromptWithSystem returns the prompt with the system text folded in, for adapters whose CLI has no system-prompt flag.

Jump to

Keyboard shortcuts

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