askengine

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 24 Imported by: 0 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 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

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

func New(ctx context.Context, cfg *config.Config, opts Options) (*Engine, error)

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

func (e *Engine) Ask(ctx context.Context, prompt string, authorize bool) (*Result, error)

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) Config

func (e *Engine) Config() *config.Config

Config returns the engine's loaded configuration.

func (*Engine) MCPCommand

func (e *Engine) MCPCommand() string

MCPCommand returns the current MCP server command ("" = disabled).

func (*Engine) MaintainPeers

func (e *Engine) MaintainPeers(ctx context.Context)

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

func (e *Engine) SetMCPCommand(ctx context.Context, cmd string) error

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) WorkPath

func (e *Engine) WorkPath() string

WorkPath returns the configured work directory — the project workspace panel sessions execute in. It lets the panel pin non-repo sessions to the work path so the memory wall (§17.2) holds for them too.

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

type StreamCallbacks struct {
	OnDelta  func(text string)
	OnStatus func(text string)
}

StreamCallbacks receives live progress while an ask converges. OnDelta delivers answer text incrementally (streaming); OnStatus delivers one-line progress notes (tool calls, task submission).

Jump to

Keyboard shortcuts

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