Documentation
¶
Overview ¶
Package question defines provider-neutral structured user questions.
Index ¶
- Constants
- Variables
- func Digest(spec Spec) (string, error)
- func RequestCount(request Request) int
- func ValidateCall(info agent.ToolCallInfo) error
- func ValidateRequest(request Request) error
- func ValidateResolution(request Request, resolution Resolution) error
- func ValidateResolutionShape(resolution Resolution) error
- func ValidateSpec(spec Spec) error
- type Answer
- type Controller
- func (c *Controller) BeforeTool(_ context.Context, info agent.ToolCallInfo) agent.ToolDecision
- func (c *Controller) Catalog() (*catalog.Catalog, error)
- func (c *Controller) Reconcile(pending []ai.ToolCallPart) (*Request, error)
- func (c *Controller) Reject(requestID, schemaDigest string) error
- func (c *Controller) Resolve(resolution Resolution) error
- type Option
- type Question
- type Request
- type RequestKind
- type Resolution
- type Resolver
- type Spec
Constants ¶
const ( // CatalogID is the application-owned provenance of ask_user. CatalogID = "coding.question" // ToolName is the provider-neutral structured user-question capability. ToolName = "ask_user" // TextToolName is the exact one-field recovery capability used after a // malformed structured question. TextToolName = "ask_user_text" // RejectionToolResult is the durable result of an explicit user cancellation. RejectionToolResult = "The user canceled this question without selecting an answer." )
Variables ¶
var ( // ErrNoPending means no durable ask_user call is awaiting a response. ErrNoPending = errors.New("coding question: no pending request") // ErrMismatch means a response does not identify the current request exactly. ErrMismatch = errors.New("coding question: request mismatch") )
var ErrInvalid = errors.New("coding question: invalid value")
ErrInvalid means a question schema or response violates the protocol.
Functions ¶
func RequestCount ¶
RequestCount returns the number of user-visible decisions. A free-form fallback is one decision even though it has no structured options.
func ValidateCall ¶
func ValidateCall(info agent.ToolCallInfo) error
ValidateCall checks one question Tool call through the same strict decoder used by the pause owner. Plan flow uses it only to choose the bounded recovery phase; it never repairs arguments.
func ValidateRequest ¶
ValidateRequest verifies identity and schema integrity.
func ValidateResolution ¶
func ValidateResolution(request Request, resolution Resolution) error
ValidateResolution verifies one exact response against its pending request.
func ValidateResolutionShape ¶
func ValidateResolutionShape(resolution Resolution) error
ValidateResolutionShape validates bounded content that does not require the pending request schema. Runtime still calls ValidateResolution before use.
func ValidateSpec ¶
ValidateSpec validates the bounded model-supplied schema.
Types ¶
type Answer ¶
type Answer struct {
Selections []string `json:"selections,omitempty"`
Custom string `json:"custom,omitempty"`
}
Answer resolves one question in its original request order.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller owns ask_user validation, pause reconciliation, and one-shot resolution. Its pending state is reconstructable from the durable Tool call.
func NewController ¶
func NewController(resolver Resolver) (*Controller, error)
NewController constructs one question coordinator.
func (*Controller) BeforeTool ¶
func (c *Controller) BeforeTool(_ context.Context, info agent.ToolCallInfo) agent.ToolDecision
BeforeTool validates ask_user arguments before pausing the Agent loop.
func (*Controller) Catalog ¶
func (c *Controller) Catalog() (*catalog.Catalog, error)
Catalog returns the exact local read-risk ask_user registration.
func (*Controller) Reconcile ¶
func (c *Controller) Reconcile(pending []ai.ToolCallPart) (*Request, error)
Reconcile derives the current question from durable pending Tool calls. Non-question calls are left for their owning coordinator.
func (*Controller) Reject ¶
func (c *Controller) Reject(requestID, schemaDigest string) error
Reject durably records an explicit cancellation as a Tool error.
func (*Controller) Resolve ¶
func (c *Controller) Resolve(resolution Resolution) error
Resolve validates and durably records one exact answer before clearing it.
type Option ¶
type Option struct {
Label string `json:"label"`
Description string `json:"description"`
Preview string `json:"preview,omitempty"`
}
Option is one model-provided selectable answer.
type Question ¶
type Question struct {
Header string `json:"header"`
Question string `json:"question"`
Options []Option `json:"options"`
Multiple bool `json:"multiple,omitempty"`
}
Question is one single- or multiple-select user question.
type Request ¶
type Request struct {
ID string `json:"id"`
ToolCallID string `json:"tool_call_id"`
SchemaDigest string `json:"schema_digest"`
Kind RequestKind `json:"kind,omitempty"`
Prompt string `json:"prompt,omitempty"`
Questions []Question `json:"questions"`
}
Request is one Runtime-owned pending structured question.
func CloneRequest ¶
CloneRequest returns a fully detached Request.
func NewFreeformRequest ¶
NewFreeformRequest binds one bounded direct prompt to Runtime and Tool-call identities. The prompt is application-owned when malformed fallback arguments cannot be trusted.
type RequestKind ¶
type RequestKind string
RequestKind distinguishes structured choices from a direct free-form response owned by the Runtime.
const ( // RequestStructured is the backward-compatible zero-value request kind. RequestStructured RequestKind = "" // RequestFreeform asks for one direct text response. RequestFreeform RequestKind = "freeform" )
type Resolution ¶
type Resolution struct {
RequestID string `json:"request_id"`
SchemaDigest string `json:"schema_digest"`
Answers []Answer `json:"answers,omitempty"`
Chat string `json:"chat,omitempty"`
}
Resolution is either complete structured answers or one chat response.
func CloneResolution ¶
func CloneResolution(resolution Resolution) Resolution
CloneResolution returns a fully detached Resolution.
type Resolver ¶
type Resolver interface {
ResolveToolCalls(...agent.ToolResolution) error
}
Resolver durably records one result for a pending Tool call.