Documentation
¶
Overview ¶
Package askengine is the unified entry engine shared by `panda ask` (CLI) and the web panel: one prompt in, three intents out — answer (pure LLM reply), tool_call (memory tools, executed and fed back), task (submitted to the node network, locally or delegated). It owns the whole pipeline — config, storage, memory injection, tool registry, entry model client, and the optional P2P scheduler core — so both front-ends run exactly the same classification and execution path with zero duplicated logic.
Index ¶
- type Engine
- func (e *Engine) Ask(ctx context.Context, prompt string, authorize bool) (*Result, error)
- func (e *Engine) AskTurns(ctx context.Context, history []entry.Turn, prompt, workDir string, ...) (res *Result, err error)
- func (e *Engine) Close()
- func (e *Engine) Config() *config.Config
- func (e *Engine) EnqueueTask(ctx context.Context, in core.TaskInput, q core.QueueSpec) (core.Task, error)
- func (e *Engine) MCPCommand() string
- func (e *Engine) MaintainPeers(ctx context.Context)
- func (e *Engine) ModelConfig() config.ModelConfig
- func (e *Engine) PlanStages(ctx context.Context, planID string) ([]core.Task, error)
- func (e *Engine) SetMCPCommand(ctx context.Context, cmd string) error
- func (e *Engine) SetModel(mc config.ModelConfig) error
- func (e *Engine) StartPlan(ctx context.Context, p plan.Plan, q core.QueueSpec) (string, error)
- func (e *Engine) WorkPath() string
- type Options
- type Progress
- type ProgressKind
- type Result
- type StreamCallbacks
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the long-lived unified entry engine. It is safe for concurrent Ask calls (the entry client and registry are; the scheduler core is).
func New ¶
New builds an engine from cfg: opens storage, wires memory stores and the tool registry, connects the entry model client, optionally loads the capability card (creating the scheduler core and dialing peers once so the first classification already sees remote capabilities), and optionally spawns the MCP server. An Options.MCPCommand of "" falls back to config.yaml's mcp.command, so a configured server needs no CLI flag.
func (*Engine) Ask ¶
Ask runs one prompt through the unified entry model. A tool_call intent is executed (memory/MCP tools) and its result fed back, converging to a final answer or task; a task is submitted through the scheduler core (local or delegated) and its outcome returned.
func (*Engine) AskTurns ¶
func (e *Engine) AskTurns(ctx context.Context, history []entry.Turn, prompt, workDir string, authorize bool, cb StreamCallbacks) (res *Result, err error)
AskTurns is the session-aware ask: history carries the conversation so far (plain user/assistant turns), workDir optionally pins where a classified task executes (a session's git worktree), and the callbacks stream live progress. A nil OnDelta still streams internally — it just is not forwarded.
func (*Engine) Close ¶
func (e *Engine) Close()
Close releases the engine's resources (DB handle, scheduler core, MCP server). The engine must not be used afterwards.
func (*Engine) EnqueueTask ¶ added in v0.0.2
func (e *Engine) EnqueueTask(ctx context.Context, in core.TaskInput, q core.QueueSpec) (core.Task, error)
EnqueueTask routes a directly-created task (the panel's board "new task" form) through the async queue: it lands in queued and the scheduler starts it when resources allow. Needs a capability card, like task submission.
func (*Engine) MCPCommand ¶
MCPCommand returns the current MCP server command ("" = disabled).
func (*Engine) MaintainPeers ¶
MaintainPeers keeps redialing configured peers in the background until ctx ends — for long-lived embedders (the web panel). Short-lived CLI asks skip it: New's one-shot dial plus waitForPeers already covers them.
func (*Engine) ModelConfig ¶
func (e *Engine) ModelConfig() config.ModelConfig
ModelConfig returns the engine's current model configuration.
func (*Engine) PlanStages ¶ added in v0.0.6
PlanStages returns every stage of one plan, for following a run.
func (*Engine) SetMCPCommand ¶
SetMCPCommand hot-swaps the stdio MCP server at runtime (the settings page): a new registry is built (memory + system + reminder tools), the new server spawned and its tools imported, then the swap happens atomically. An empty command disables MCP. A failed spawn leaves the previous registry and server serving. The ctx spawns the new server; the engine's own lifetime is unchanged.
func (*Engine) SetModel ¶
func (e *Engine) SetModel(mc config.ModelConfig) error
SetModel hot-swaps the entry model client at runtime (the settings page): a failed build leaves the previous client serving.
func (*Engine) StartPlan ¶ added in v0.0.6
StartPlan hands a multi-stage plan to the scheduler core, which creates one task per stage and releases the ones with no dependencies. It is the plan plane's only entry point outside the daemon's own completion hooks: without it the flagship cross-device pipeline — develop where a coding agent lives, train where the GPU lives, report where the user is — was reachable only from a test. Needs a capability card for the same reason task submission does: a plan whose stages cannot be routed is a plan that cannot start.
type Options ¶
type Options struct {
// CardPath points at capabilities.yaml. Only when set can classified
// tasks actually execute (the card powers the local scheduler core);
// without it the engine answers and runs memory tools only.
CardPath string
// MCPCommand is an optional space-separated stdio MCP server command
// whose tools are imported into the registry.
MCPCommand string
// QueueTasks routes classified tasks through the async queue (core.Enqueue)
// instead of blocking inline submission: the task lands in queued and the
// queue scheduler starts it when resources allow — the panel's mode, where
// progress streams into the session. The CLI keeps inline (blocking) mode.
QueueTasks bool
// ReplyASCII makes the entry model answer in English/ASCII. Set it when
// the client runs on a bare Linux console whose font has no CJK glyphs
// (Chinese replies would otherwise render as diamonds).
ReplyASCII bool
// AsyncPeers dials configured peers in the background instead of waiting
// for the dials (and a settle window) before New returns. Interactive
// surfaces (the REPL) want this: an offline peer's dial timeout is
// routine in a long-lived session, not worth dead air before the banner.
// One-shot callers (panda ask) leave it off — their routing decision runs
// immediately and needs the conns settled first.
AsyncPeers bool
// Logger defaults to a warn-level stderr handler.
Logger *slog.Logger
}
Options tunes how the engine is built.
type Progress ¶ added in v0.0.6
type Progress struct {
Kind ProgressKind
Name string
}
Progress is one structured progress event: the action, and the name of what it acts on (a task title, a plan goal, a tool name). The engine deliberately holds no locale — the CLI translates these through internal/i18n and the panel through the browser's language, from the same event.
type ProgressKind ¶ added in v0.0.6
type ProgressKind string
ProgressKind names what the engine is about to do.
const ( ProgressTask ProgressKind = "task" // submitting a classified task ProgressPlan ProgressKind = "plan" // starting a multi-stage plan ProgressTool ProgressKind = "tool" // running a tool )
type Result ¶
type Result struct {
// Kind is "answer", "task" or "plan" — the final converged intent.
Kind string
// Answer carries the model's text reply when Kind == "answer".
Answer string
// Note is an incidental model note emitted alongside a tool call.
Note string
// Task fields, valid when Kind == "task".
TaskID string
TaskTitle string // for conversation history: "the task that ran" in one line
TaskState string
OK bool
Stdout string
Stderr string
ExitCode int
// Plan fields, valid when Kind == "plan". A plan is asynchronous by nature —
// its stages run on other machines, in waves — so the call returns as soon as
// the stages exist and the first wave is released; PlanID is how the caller
// follows it from there.
PlanID string
PlanGoal string
PlanStages []core.Task
// Cost of this ask, as reported by the entry model's provider (zero for
// providers that report no usage). The CLI shows them on its closing status
// line; the panel bills them through RecordDelegationMetric.
InputTokens int64
OutputTokens int64
Latency time.Duration
}
Result is the outcome of one Ask call.
type StreamCallbacks ¶
type StreamCallbacks struct {
OnDelta func(text string)
OnStatus func(text string)
OnProgress func(Progress)
}
StreamCallbacks receives live progress while an ask converges. OnDelta delivers answer text incrementally (streaming); OnStatus delivers one-line progress notes (tool calls, task submission) as ready-made English prose, and OnProgress delivers the same events structured, for a caller that owns a locale and wants to phrase them itself. Set whichever fits — OnProgress wins when both are present.