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, ...) (*Result, error)
- func (e *Engine) Close()
- func (e *Engine) Config() *config.Config
- func (e *Engine) MCPCommand() string
- func (e *Engine) MaintainPeers(ctx context.Context)
- func (e *Engine) ModelConfig() config.ModelConfig
- func (e *Engine) SetMCPCommand(ctx context.Context, cmd string) error
- func (e *Engine) SetModel(mc config.ModelConfig) error
- func (e *Engine) WorkPath() string
- type Options
- 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) (*Result, 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) 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) 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.
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
// Logger defaults to a warn-level stderr handler.
Logger *slog.Logger
}
Options tunes how the engine is built.
type Result ¶
type Result struct {
// Kind is "answer" or "task" — 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
TaskState string
OK bool
Stdout string
Stderr string
ExitCode int
}
Result is the outcome of one Ask call.
type StreamCallbacks ¶
StreamCallbacks receives live progress while an ask converges. OnDelta delivers answer text incrementally (streaming); OnStatus delivers one-line progress notes (tool calls, task submission).