Documentation
¶
Overview ¶
Package entry implements the unified entry model (design doc §7): one model call classifies a user request as an answer, a controlled tool call, or a structured task. The model never performs side effects — the Go core validates and executes whatever the model emits.
Index ¶
- Variables
- func BuildPrompt(opts PromptOptions) string
- func Speak(ctx context.Context, text string) error
- func ValidateTaskSpec(t *TaskSpec) error
- func ValidateToolCall(tc *ToolCall) error
- func WrapAPIError(err error) error
- type ClassifyError
- type Client
- func (c *Client) Complete(ctx context.Context, system, user string) (string, error)
- func (c *Client) CompleteTurns(ctx context.Context, system string, turns []Turn) (string, error)
- func (c *Client) CompleteTurnsWithTools(ctx context.Context, system string, turns []Turn, tools []ToolSpec) (Response, error)
- func (c *Client) StreamTurnsWithTools(ctx context.Context, system string, turns []Turn, tools []ToolSpec, ...) (Response, error)
- type ContentBlock
- type Kind
- type Output
- func Classify(ctx context.Context, c *Client, devices []ledger.Node, memory, user string) (Output, error)
- func ClassifyStreamWithTools(ctx context.Context, c *Client, devices []ledger.Node, memory string, ...) (Output, error)
- func ClassifyTurns(ctx context.Context, c *Client, devices []ledger.Node, memory string, ...) (Output, error)
- func ClassifyTurnsWithTools(ctx context.Context, c *Client, devices []ledger.Node, memory string, ...) (Output, error)
- func ParseOutput(raw string) (Output, error)
- type PromptOptions
- type Registry
- type Requires
- type ResourceProfile
- type Response
- type TaskSpec
- type TaskSpecDetail
- type Tool
- type ToolCall
- type ToolSpec
- type ToolUse
- type Transcript
- type Turn
Constants ¶
This section is empty.
Variables ¶
var ErrNoKey = errors.New("entry: no model api_key configured")
ErrNoKey is returned when no API key is configured.
Functions ¶
func BuildPrompt ¶
func BuildPrompt(opts PromptOptions) string
BuildPrompt assembles the system prompt with the device capability summary and user-memory placeholder filled in.
func Speak ¶
Speak speaks text via the TTS sidecar. A missing driver is returned as an error, not fatal.
func ValidateTaskSpec ¶
ValidateTaskSpec checks a task emitted by the model for the fields the core needs before it can be persisted and routed. It returns an error describing the first problem; the model output is never trusted verbatim.
func ValidateToolCall ¶
ValidateToolCall checks a tool invocation. The tool name must be present; the Go core's tool whitelist (not this package) decides whether the named tool is actually allowed to run.
func WrapAPIError ¶
WrapAPIError converts a model-call error into a user-friendly ClassifyError.
Types ¶
type ClassifyError ¶
ClassifyError wraps a model/parse failure with a user-friendly message. The entry layer must never fail silently — an API error surfaces a clear explanation, and a malformed structured output degrades to an answer rather than erroring out (see ParseOutput).
func (*ClassifyError) Error ¶
func (e *ClassifyError) Error() string
func (*ClassifyError) Unwrap ¶
func (e *ClassifyError) Unwrap() error
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to an Anthropic-compatible Messages API or an OpenAI-compatible Chat Completions API, selected by the config's api_type. It is small and dependency-free so the core daemon does not pull in an SDK.
func NewClient ¶
func NewClient(model config.ModelConfig) (*Client, error)
NewClient builds a client from the model config. A zero baseURL/model falls back to config defaults, so callers can pass config.Default().Model. The endpoint must be HTTPS so the API key never travels cleartext (M2); loopback http stays allowed for a local dev model, matching the guard the commander applies to adapter endpoints (D7).
func (*Client) CompleteTurns ¶
CompleteTurns runs one call with a conversation history and no tools, returning the model's text. It is the answer/fallback path; the tool path is CompleteTurnsWithTools.
func (*Client) CompleteTurnsWithTools ¶
func (c *Client) CompleteTurnsWithTools(ctx context.Context, system string, turns []Turn, tools []ToolSpec) (Response, error)
CompleteTurnsWithTools runs one call with a conversation history and an optional tool set, returning both text and any tool_use blocks. It dispatches on the configured api type; the Anthropic path leaves tool_choice unset: the Messages API defaults to "auto" when tools are present, and DeepSeek's Anthropic endpoint rejects the string "auto" (it wants the internally-tagged object form). Omitting it is simpler and correct.
func (*Client) StreamTurnsWithTools ¶
func (c *Client) StreamTurnsWithTools(ctx context.Context, system string, turns []Turn, tools []ToolSpec, onDelta func(string)) (Response, error)
StreamTurnsWithTools runs one call with a conversation history, an optional tool set, and a text-delta callback: answer text is delivered live as the provider streams it, while tool_use blocks and the final Response are accumulated and returned at the end. It is the streaming counterpart of CompleteTurnsWithTools and dispatches on the configured api type.
type ContentBlock ¶
type ContentBlock struct {
Type string `json:"type"` // text | thinking | tool_use | tool_result
Text string `json:"text,omitempty"` // text/thinking
ID string `json:"id,omitempty"` // tool_use id
Name string `json:"name,omitempty"` // tool_use name
Input map[string]any `json:"input,omitempty"` // tool_use input
ToolUseID string `json:"tool_use_id,omitempty"` // tool_result linkage
Content string `json:"content,omitempty"` // tool_result content
}
ContentBlock is a structured content block in a message or response. It covers the Messages API vocabulary PANDA uses: text/thinking (responses) and tool_use/tool_result (both directions).
type Output ¶
type Output struct {
Kind Kind
Answer string // KindAnswer
Tool *ToolCall // KindToolCall
Task *TaskSpec // KindTask
Note string // dropped text / extra tool_use (KindToolCall)
}
Output is the parsed result of one entry-model call. Exactly one of Answer/Tool/Task is populated, matching Kind. Note carries content the executor does not act on — text emitted alongside a tool call and any tool_use after the first — so callers can surface it rather than drop it.
func Classify ¶
func Classify(ctx context.Context, c *Client, devices []ledger.Node, memory, user string) (Output, error)
Classify runs the unified entry model once with no tools and returns the parsed Output. It is the answer/fallback entry point; the tool path is ClassifyTurnsWithTools.
func ClassifyStreamWithTools ¶
func ClassifyStreamWithTools(ctx context.Context, c *Client, devices []ledger.Node, memory string, turns []Turn, registry *Registry, onDelta func(string)) (Output, error)
ClassifyStreamWithTools is ClassifyTurnsWithTools with live text streaming: answer deltas are delivered to onDelta as the provider emits them, while the parsed Output is returned once complete.
func ClassifyTurns ¶
func ClassifyTurns(ctx context.Context, c *Client, devices []ledger.Node, memory string, turns []Turn) (Output, error)
ClassifyTurns is Classify with a conversation history and no tools.
func ClassifyTurnsWithTools ¶
func ClassifyTurnsWithTools(ctx context.Context, c *Client, devices []ledger.Node, memory string, turns []Turn, registry *Registry) (Output, error)
ClassifyTurnsWithTools runs the entry model with a conversation history and a tool registry. A native tool_use response becomes a KindToolCall output; a text response falls through to the existing JSON/prose parsing (answer/task).
func ParseOutput ¶
ParseOutput turns raw model text into a validated Output. The model may emit JSON for tool_call/task or plain prose for answer. Anything that is not a valid tool_call/task JSON object falls back to KindAnswer (never a silent error for the user — design doc §7.4).
type PromptOptions ¶
type PromptOptions struct {
Devices []ledger.Node // capability directory snapshot (may be empty)
Memory string // Hermes memory summary (may be empty; capped)
}
PromptOptions carries the dynamic parts of the system prompt.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the set of tools the entry model may call, keyed by name.
type Requires ¶
type Requires struct {
Abilities []string `json:"abilities"`
}
Requires lists the abilities a task needs (design doc §7.3).
type ResourceProfile ¶
type ResourceProfile struct {
CPU int `json:"cpu"`
RAMGB float64 `json:"ram_gb"`
GPUVRAMGB float64 `json:"gpu_vram_gb"`
DurationHint string `json:"duration_hint"` // short | long
}
ResourceProfile is a coarse resource hint, not a safety rating (design doc §7.3; complexity/risk are recorded but do not auto-switch model tiers in MVP).
type Response ¶
Response is the parsed result of one completion call: the textual answer plus any tool_use blocks the model emitted (a model may return text alongside a tool call, or only a tool call). Truncated reports that the provider stopped at max_tokens, so the text is incomplete.
type TaskSpec ¶
type TaskSpec struct {
Title string `json:"title"`
Project string `json:"project"`
ContextType string `json:"context_type"`
Requires Requires `json:"requires"`
Spec TaskSpecDetail `json:"spec"`
Complexity float64 `json:"complexity"`
Risk string `json:"risk"`
Resources ResourceProfile `json:"resource_profile"`
}
TaskSpec is the structured task payload the model emits for KindTask (design doc §7.3).
type TaskSpecDetail ¶
type TaskSpecDetail struct {
Scope string `json:"scope"`
Target string `json:"target"`
Node string `json:"node,omitempty"` // preferred node id/name; empty lets the scheduler choose
Constraints []string `json:"constraints"`
SuccessDefinition string `json:"success_definition"`
}
TaskSpecDetail captures what to do, where, and how to verify success.
type Tool ¶
type Tool struct {
Name string
Description string
Schema map[string]any // JSON Schema for the tool's input arguments
Run func(ctx context.Context, args map[string]any) (string, error)
}
Tool is a callable tool the entry model may invoke. Name/Description/Schema are what the model sees (the Anthropic tool schema); Run executes the call and returns a short user-facing result. The model never performs side effects — the registry's Run is the only thing that acts on a tool call.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id,omitempty"`
Tool string `json:"tool"`
Arguments map[string]any `json:"arguments"`
}
ToolCall is a validated tool invocation request. ID carries the tool_use id when the call came from native tool_use (so the loop can reply with a matching tool_result); it is empty for the text-JSON fallback path.
type ToolSpec ¶
type ToolSpec struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema map[string]any `json:"input_schema"`
}
ToolSpec describes one tool the model may call (Anthropic Messages API shape).
type Transcript ¶
Transcript is one captured utterance: the wake word fired and the speech that followed was transcribed. OK is false (with Err set) when a sidecar is unavailable — a missing key or driver degrades, it never crashes the caller.
func Listen ¶
func Listen(ctx context.Context, durationS float64) Transcript
Listen blocks until the wake word fires (or durationS elapses), then captures and transcribes the utterance. It drives wake.py then stt.py. VAD is deliberately NOT in this chain yet: each sidecar opens its own microphone stream, so a vad.py gate would consume the start of the utterance and leave stt.py with silence. VAD belongs in a single-stream capture (wake + VAD + ASR sharing one audio feed), which is a hardware-phase follow-up.
type Turn ¶
type Turn struct {
Role string // "user" | "assistant"
Content string // plain text (used when Blocks is empty)
Blocks []ContentBlock // structured blocks for tool_use/tool_result
}
Turn is one conversation turn for multi-turn classification.