Documentation
¶
Overview ¶
Package compose is the composer (spec_045_composer): a guided conversation that makes a workspace's component. It asks what it needs, writes the component in its file format, and checks it with the kind's own rules, sending the problems back to be fixed, before handing it on as a draft. A kind is a Recipe; the conversation is the same for all.
Index ¶
Constants ¶
const Instruction = `You are the composer of an AI agent workspace: you make one component for the user (described below) through a short conversation.
Ask only what you must to make a good component, one question at a time, in plain words, with up to six short suggested answers when there are natural choices. When the request already says enough, draft at once.
When you draft, write the component's whole file in its format, using only names the workspace has (listed below) unless the user asked for something new, and nothing that isn't needed.
Answer in one of two ways.
A question: JSON only, {"question": "…", "options": ["…"]}
A draft: a JSON line, {"draft": {"name": "lowercase-name-with-hyphens", "summary": "one sentence: what it does"}}, then the file's whole text in one fenced block:
` + "```" + `file
…
` + "```"
Instruction tells the model its job.
const Keep = time.Hour
Keep is how long a session lasts after its last turn.
const MaxQuestions = 5
MaxQuestions is how many questions the composer may ask before it must draft.
Variables ¶
var ErrNoReply = errors.New("the composer's answer is neither a question nor a draft")
ErrNoReply means the model's answer is neither a question nor a draft.
var ErrNoSession = errors.New("no such composer session")
ErrNoSession means there's no such session (it ended, or it's another workspace's).
Functions ¶
func Answer ¶
Answer records the user's answer to s's question (or a change asked of its draft, which starts a new draft).
Types ¶
type Asker ¶
type Asker func(ctx context.Context, instruction, prompt string) (reply string, costUSD float64, err error)
Asker has a model answer prompt under instruction, and says what it cost.
type Draft ¶
type Draft struct {
Name string `json:"name"`
Summary string `json:"summary"`
// File is the component in its file format.
File string `json:"file"`
Problems []string `json:"problems,omitempty"`
}
Draft is the component as the composer wrote it.
type Recipe ¶
type Recipe struct {
Kind string
// Brief says what the kind is and its file format, for the model.
Brief string
// Check returns what doesn't hold in a draft (nothing: it loads).
Check func(name, file string) []string
}
Recipe is one kind of component: what the model is told about it, and how a draft of it is checked.
type Session ¶
type Session struct {
ID string
Kind string
Workspace string
// Current is the component being changed, as its file ("" for a new one).
Current string
Turns []Turn
// Draft is the latest draft (nil until there's one).
Draft *Draft
CostUSD float64
Updated time.Time
// contains filtered or unexported fields
}
Session is one conversation.
func (*Session) Asking ¶
Asking reports whether the composer's last turn is a question waiting for an answer.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store keeps the sessions going, in memory.
type Turn ¶
type Turn struct {
// Role is "user" or "composer".
Role string `json:"role"`
Text string `json:"text"`
// Options are a question's suggested answers.
Options []string `json:"options,omitempty"`
// Drafted marks the composer's turn that handed on a draft (its
// summary): not a question.
Drafted bool `json:"drafted,omitempty"`
}
Turn is one message of the conversation.