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 ¶
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]).
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 ¶
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 ¶
PromptWithSystem returns the prompt with the system text folded in, for adapters whose CLI has no system-prompt flag.