app

package
v0.1.32 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 42 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 app provides the shared AgentRunner used by both the CLI and MCP adapters. Neither adapter should duplicate the agent-resolution, prompt assembly, or result-normalization logic; all of that lives here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssemblePromptForTest

func AssemblePromptForTest(constitution string, skills map[string]*skill.Skill, skillNames []string, task string) (string, string)

AssemblePromptForTest exposes assemblePrompt for golden tests in internal/benchmark.

Types

type AgentRunner

type AgentRunner interface {
	// ListAgents returns lightweight summaries for every registered agent.
	ListAgents(ctx context.Context) ([]agent.Summary, error)
	// Run executes one agent invocation end-to-end and returns a normalized
	// result envelope with enough metadata for the orchestrator to judge
	// usefulness.
	Run(ctx context.Context, req RunRequest) (result.RunResult, error)
	// GetConstitution returns the resolved constitution text and its source for
	// a given agent ID. Useful for auditing and MCP get_constitution calls.
	GetConstitution(ctx context.Context, agentID string) (Constitution, error)
	// Doctor reports Ollama connectivity, registry state, and skill layout.
	Doctor(ctx context.Context) (result.DoctorResult, error)
}

AgentRunner is the service interface consumed by both the CLI and MCP adapters. Any adapter that satisfies this interface can be tested in isolation without a live Ollama instance.

type Config

type Config struct {
	// BundleFS contains agents/, skills/, and constitutions/. Production callers
	// use Prism's embedded bundle; tests and development overrides may supply one.
	BundleFS fs.FS
	// Bundle metadata is stamped onto every result and event.
	BundleVersion string
	BundleDigest  string
	BundleMode    string
	// WorkspaceFS is visible only to repository-aware runtime plugins.
	WorkspaceFS    fs.FS
	WorkspaceLabel string
	GitHubToken    string
	// RootFS is the resolved fs.FS for the project root. When set it takes
	// priority over RootDir. Set by the CLI via rootresolver after resolving
	// the --root flag (local path or remote GitHub URL).
	RootFS fs.FS
	// RootLabel is the human-readable root descriptor for display (e.g.
	// "https://github.com/owner/repo" or "/local/path"). Used in doctor output.
	RootLabel string
	// RootDir is the local project root. Used when RootFS is nil. Kept for
	// backward compatibility with tests that create on-disk fixtures.
	RootDir string
	// AgentDir is a local path override for the agents directory.
	// When set it overrides the agents/ sub-FS derived from RootFS/RootDir.
	AgentDir string
	// ConstitutionFS supplies sibling support files for an AgentDir override.
	// When unset, constitutions resolve from the effective bundle. Both
	// execution and get_constitution use this filesystem.
	ConstitutionFS fs.FS
	// SkillsDir is a local path override for the skills directory.
	// When set it overrides the skills/ sub-FS derived from RootFS/RootDir.
	SkillsDir string
	// OllamaHost is the base URL of the local Ollama server.
	// Defaults to http://127.0.0.1:11434 if empty.
	OllamaHost string
	// RuntimePlugins is the optional registry of native plugins exposed to agents.
	// Defaults to the built-in registry.
	RuntimePlugins *plugins.Registry
	// DownstreamMCP is an optional client for configured MCP servers that
	// specialists can inspect and call through bounded Prism bridge tools.
	DownstreamMCP DownstreamMCPClient
	// ModelRuntime is an optional provider-neutral runtime used for all
	// specialist model calls. When nil, Prism builds an Ollama-backed
	// runtime targeting OllamaHost.
	ModelRuntime llmruntime.ModelRuntime
	// EventSink receives one stable RunEvent after each Run call. Defaults to a
	// no-op sink so OSS behavior is unchanged when observability is not enabled.
	EventSink observe.Sink
	// PolicyEngine is optional. When set, requests are checked before evidence
	// collection and model execution.
	PolicyEngine *internalpolicy.Engine
	// ExtensionsStateDir enables managed-extension catalog composition.
	ExtensionsStateDir string
	// ExtensionSnapshot can be precomputed by callers; when nil New composes one.
	ExtensionSnapshot *extensions.CatalogSnapshot
	// MCPAccess controls per-agent downstream MCP visibility and authorization.
	MCPAccess           extensions.MCPAccessState
	MCPAccessConfigured bool
	// Graphify is the explicit, workspace-bound Graphify capability
	// configuration. It is intentionally independent of MCPAccess.
	Graphify graphify.Config
	// RuntimeTarget describes the effective process runtime. Model may be empty
	// when the process has no global model override.
	RuntimeTarget            extensions.RuntimeTarget
	ModelRuntimeConfig       llmruntime.Config // diagnostic model discovery, including authentication
	ToolModelStateDir        string
	ToolRecommendationAgents []string
	RecommendationObserver   func(RecommendationTrace)
	ToolRecommendationModel  string
	DecisionURL              string
	DecisionAPIKeyEnv        string
	DecisionModel            string
	KevURL                   string
	KevAPIKeyEnv             string
	KevModel                 string
}

Config holds runtime configuration for a Runner.

type Constitution

type Constitution struct {
	AgentID string `json:"agent_id"`
	// Source is one of "path", "body", or "legacy".
	Source string `json:"source"`
	// Path is set when Source is "path" or "legacy".
	Path string `json:"path,omitempty"`
	Text string `json:"text"`
}

Constitution holds the resolved constitution text and provenance.

type DownstreamMCPClient added in v0.1.14

type RecommendationTrace added in v0.1.32

type RecommendationTrace struct {
	Result     ToolRecommendations `json:"result"`
	DurationMS int64               `json:"duration_ms"`
	Injected   bool                `json:"injected"`
	Error      string              `json:"error,omitempty"`
}

RecommendationTrace records whether an automatic recommendation reached the prompt.

type RunRequest

type RunRequest struct {
	// AgentID identifies the specialist to invoke.
	AgentID string
	// Task is the task text supplied by the orchestrator (from --input, --stdin,
	// or the MCP tool call payload).
	Task string
	// SkillNames is the required list of skill IDs to attach.
	// Each must be present in the agent's allowed_skills list.
	SkillNames []string
	// SkillResources explicitly attaches bounded text resources in
	// <skill>:<path> form for runtimes that cannot make tool calls.
	SkillResources []string
	// Format controls the rendered output: "json" (default) or "markdown".
	Format string
	// Metadata is optional caller context used by team dashboards and reports.
	Metadata observe.Metadata
	// Workspace selects repository evidence for this invocation. It is optional
	// for agents that do not use repository-aware plugins.
	Workspace Workspace
	// Optional graph provenance fields.
	GraphID     string
	GraphNodeID string
}

RunRequest is the input to Runner.Run.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner implements AgentRunner on top of a provider-neutral ModelRuntime.

func New

func New(cfg Config) (*Runner, error)

New creates a Runner from cfg, loads all agent specs, and returns. It fails fast if the agent directory cannot be read or any spec is invalid.

func (*Runner) CatalogSnapshot added in v0.1.22

func (r *Runner) CatalogSnapshot() extensions.CatalogSnapshot

func (*Runner) Doctor

func (r *Runner) Doctor(ctx context.Context) (result.DoctorResult, error)

Doctor implements AgentRunner. It checks selected-runtime model availability, agent registry state, and skill directory structure.

func (*Runner) GetConstitution

func (r *Runner) GetConstitution(_ context.Context, agentID string) (Constitution, error)

GetConstitution implements AgentRunner. It resolves the constitution for agentID and returns it with provenance metadata.

func (*Runner) GetSpec

func (r *Runner) GetSpec(_ context.Context, agentID string) (*agent.Spec, error)

GetSpec returns the full parsed Spec for agentID. This is a convenience method for CLI commands that need more detail than the Summary returned by ListAgents.

func (*Runner) ListAgents

func (r *Runner) ListAgents(_ context.Context) ([]agent.Summary, error)

ListAgents implements AgentRunner.

func (*Runner) RecommendTools added in v0.1.24

func (r *Runner) RecommendTools(ctx context.Context, agentID, task string, topK int) (ToolRecommendations, error)

RecommendTools returns a bounded shortlist from the agent's authorized catalog.

func (*Runner) RecommendToolsForWorkspace added in v0.1.24

func (r *Runner) RecommendToolsForWorkspace(ctx context.Context, agentID, task string, topK int, workspace Workspace) (ToolRecommendations, error)

func (*Runner) RequiresWorkspace added in v0.1.21

func (r *Runner) RequiresWorkspace(agentID string) (bool, error)

RequiresWorkspace reports whether an agent declares a repository-scoped runtime plugin. MCP adapters use it to avoid asking hosts for roots when the selected specialist does not need repository access.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, req RunRequest) (result.RunResult, error)

Run implements AgentRunner end-to-end:

  1. Resolve the agent spec by ID.
  2. Validate that at least one skill is requested.
  3. Validate each requested skill against the agent's allowed_skills.
  4. Load the constitution (via constitution_path, inline body, or legacy path).
  5. Load each skill's full SKILL.md content.
  6. Assemble the model prompt with progressive disclosure.
  7. Enforce the per-agent context budget (warn if exceeded).
  8. Apply the agent's latency_budget_ms as a context deadline if none is set.
  9. Call the configured model runtime.
  10. Return a normalized RunResult with usage and provenance metadata.

func (*Runner) SkillsFS added in v0.1.22

func (r *Runner) SkillsFS() fs.FS

SkillsFS returns the exact runtime skills filesystem used by this runner.

type ToolRecommendation added in v0.1.24

type ToolRecommendation struct {
	Server      string  `json:"server"`
	Name        string  `json:"name"`
	Description string  `json:"description,omitempty"`
	InputSchema any     `json:"input_schema,omitempty"`
	Score       float64 `json:"score"`
}

ToolRecommendation is advisory; CallTool performs authorization again.

type ToolRecommendations added in v0.1.24

type ToolRecommendations struct {
	Tools         []ToolRecommendation `json:"tools"`
	ScoreKind     string               `json:"score_kind"`
	ModelIdentity string               `json:"model_identity,omitempty"`
	Incomplete    bool                 `json:"incomplete,omitempty"`
	Warnings      []string             `json:"warnings,omitempty"`
}

type Workspace added in v0.1.21

type Workspace struct {
	Root                  string `json:"root"`
	GenerationFingerprint string `json:"generation_fingerprint,omitempty"`
}

Jump to

Keyboard shortcuts

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