askuser

package
v0.47.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 7 Imported by: ? 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 askuser provides the ask_user tool that lets the agent ask the user one or more questions and block until they respond.

Index

Constants

View Source
const (
	// MaxQuestions is the largest batch a single ask_user call may contain.
	// The Automation API's answer cap mirrors it.
	MaxQuestions = 32
	// MaxQuestionBytes bounds a single question's text.
	MaxQuestionBytes = 4 << 10
	// MaxOptions bounds the predefined choices offered for one question.
	MaxOptions = 32
	// MaxOptionBytes bounds a single predefined choice.
	MaxOptionBytes = 1 << 10
)

Limits on a single ask_user call. They exist because the answers come back through a UI or, for automation sessions, through an HTTP endpoint that caps the answer array: a prompt with more questions than the answer cap could never be answered by a machine caller. Bounding the text keeps one prompt from being a payload dump.

View Source
const (
	ResponderUser       = "user"       // the user, from the web UI or a paired app
	ResponderOwner      = "owner"      // a project owner agent, on the user's behalf
	ResponderAutomation = "automation" // a caller of the Automation API
	ResponderVoice      = "voice"      // the voice relay, set only by the server's call bridge
)

Responder kinds. The zero Kind means the resolver did not say, which is also what every answer recorded before the field existed reads as.

View Source
const CustomKey = "ask_responder"

CustomKey is the tool_result Custom key that records the Responder. Custom never reaches the provider, so the record costs the model nothing.

View Source
const MaxContextBytes = 2000

MaxContextBytes bounds a question's context: a few lines, not a report.

View Source
const MultiSeparator = "; "

MultiSeparator joins the options chosen in a multiple-choice question.

Variables

View Source
var ErrRequiresTap = errors.New("this question requires a tap or typed confirmation; voice cannot answer it")

ErrRequiresTap is returned when a voice responder tries to resolve a request that must be answered by a tap or typed confirmation.

Functions

func Ask added in v0.47.0

func Ask(ctx context.Context, b *Bridge, questions []Question, requiresTap bool) core.Result

Ask puts questions to the user through b and blocks until they are answered or ctx ends. It is ask_user's body, shared with tools that end in a written question (request_call when no call happens).

func NewTool

func NewTool(b *Bridge) core.Tool

NewTool creates the ask_user tool wired to the given bridge.

Types

type Bridge

type Bridge struct {
	// contains filtered or unexported fields
}

Bridge connects the ask_user tool to the UI.

func NewBridge

func NewBridge() *Bridge

NewBridge creates a bridge.

func (*Bridge) Prompts

func (b *Bridge) Prompts() <-chan Prompt

Prompts returns the channel the UI listens on.

type Prompt

type Prompt struct {
	Questions []Question
	// RequiresTap is a property of the whole request: only a tap or typed
	// answer may resolve it, never the voice relay.
	RequiresTap bool
	Response    chan<- Reply // exactly once
}

Prompt is the full batch sent from the agent to the UI.

type Question

type Question struct {
	Text string `json:"question"`
	// Context lets the user answer without reading the conversation: what is
	// going on, why it is asked, what each option changes. Optional and
	// additive; an older client simply does not show it.
	Context string   `json:"context,omitempty"`
	Options []string `json:"options,omitempty"`
	// Multiple lets the user tick several options. The answer is still one
	// string per question: the chosen options joined by MultiSeparator, then
	// any free text, so every responder (UI, automation, owner) keeps the
	// same []string contract.
	Multiple bool `json:"multiple,omitempty"`
}

Question describes a single question with optional predefined choices.

func ParseQuestion added in v0.47.0

func ParseQuestion(m map[string]any) (Question, error)

ParseQuestion validates one question as ask_user does.

func ParseQuestions added in v0.47.0

func ParseQuestions(params map[string]any) ([]Question, error)

ParseQuestions validates the "questions" parameter as ask_user does.

type Reply added in v0.46.0

type Reply struct {
	Answers   []string
	Responder Responder
}

Reply answers a Prompt: one answer per question, and who gave them.

type Responder added in v0.46.0

type Responder struct {
	Kind string `json:"kind"`
	// ID and Name identify an owner.
	ID   string `json:"id,omitempty"`
	Name string `json:"name,omitempty"`
	// Via is the authenticated channel of a user answer (device:<id>,
	// network or token), as the server audits it.
	Via string `json:"via,omitempty"`
	// CallID and Quote are the evidence of a voice answer: the local call and
	// the owner's words as heard.
	CallID string `json:"call_id,omitempty"`
	Quote  string `json:"quote,omitempty"`
}

Responder identifies who answered an ask_user. It is set by the code path that resolved the prompt, never parsed from the answer text.

func ResponderFromCustom added in v0.46.0

func ResponderFromCustom(v any) (Responder, bool)

ResponderFromCustom reads the recorded Responder back from a tool_result's Custom value: the struct itself in memory, a JSON object once persisted.

func (Responder) Attribution added in v0.46.0

func (r Responder) Attribution() string

Attribution is the line prepended to an answer the user did not give, so the model never reports it as theirs. Empty for the user and for unknown. The web client recognises this exact shape to label the answer card.

Jump to

Keyboard shortcuts

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