pi

package
v0.93.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AgentStatusDone       = agentlib.AgentStatusDone
	AgentStatusFailed     = agentlib.AgentStatusFailed
	AgentStatusNeedsInput = agentlib.AgentStatusNeedsInput
)

Variables

This section is empty.

Functions

func BuildPrompt

func BuildPrompt(instructions string, envContext map[string]string, taskContent string) string

BuildPrompt combines instructions with environment context and task content.

func BuildResultSection

func BuildResultSection(r string) string

BuildResultSection renders a Result as a markdown section.

func NewSession added in v0.92.0

func NewSession(runner Runner) agentlib.Session

NewSession wraps runner as a session: one conversation whose turns are runs.

A pi session holds nothing between turns — each turn spawns its own process, and continuity lives in the pi CLI's own session store, keyed by the --session-id the runner was configured with. The session therefore adds no state of its own; it is the adapter that lets a Runner be addressed the way the shared interactive service addresses a conversation.

func NewSessionFactory added in v0.92.0

func NewSessionFactory(
	base PiRunnerConfig,
	newRunner func(PiRunnerConfig) Runner,
) agentlib.SessionFactory

NewSessionFactory returns a SessionFactory that builds one pi-backed session per session id.

base carries the agent's own configuration — AgentDir, AllowedTools, Model, Env — and is copied, never mutated. newRunner constructs each session's runner from the config this factory derives: pass NewRunner in production; a test passes a recorder so it can observe the config each path produces.

The derived config is base with the continuity pair set from id. A non-empty id turns persistence on and pins the run to it, which is what makes a second prompt on the same id continue the first. An empty id leaves both unset, so a caller with no session identity keeps exactly the runner it had before — the task-routed shape, unchanged.

func NewStep

func NewStep(cfg StepConfig) agentlib.Step

NewStep wraps a single Pi invocation as an agentlib.Step.

func PrintResult

func PrintResult(ctx context.Context, result Result) error

PrintResult marshals a Result to JSON and prints to stdout.

Types

type AgentStatus

type AgentStatus = agentlib.AgentStatus

AgentStatus mirrors the shared agent status type.

type PiRunnerConfig

type PiRunnerConfig struct {
	// AgentDir is the working directory for the pi process. Pi's
	// context-file discovery walks AGENTS.md/CLAUDE.md from cwd toward /,
	// so place project guardrails as AGENTS.md inside this directory.
	// Pi's other config (settings, skills, sessions) is resolved via
	// $PI_CODING_AGENT_DIR or ~/.pi/agent/ and is independent of cwd.
	AgentDir string
	// AllowedTools is the comma-separated list of tool names to enable.
	AllowedTools string
	// Model selects the model (e.g. "MiniMax-M2.7-highspeed").
	Model string
	// Env holds extra KEY=VALUE entries appended to the subprocess environment.
	// Use for API keys, custom provider settings, etc.
	Env map[string]string
	// PersistSession keeps pi's session storage instead of discarding it, by
	// omitting the default --no-session flag.
	//
	// Default false, and it must stay false for a task-routed (job) agent: each
	// run of such an agent is an unrelated task, and a persisted session would
	// let a later run resume the previous task's conversation from the shared
	// ~/.pi/agent/ volume. Set it only for a long-running identity agent, where
	// continuity across prompts is the point.
	//
	// Persisting is necessary but **not sufficient** for continuity. `--no-session`
	// governs whether pi *writes* the transcript; reading it back is a different
	// flag. Setting this alone yields an agent that saves every conversation and
	// remembers none of them — which is exactly what happened: a two-prompt proof
	// returned the first answer and then "no token was previously requested".
	PersistSession bool

	// SessionID, when set, passes pi's --session-id: one stable identity whose
	// transcript is created on first use and continued on every later run.
	//
	// This is the flag that makes continuity real — see PersistSession, which only
	// stops pi discarding the transcript. It is `--session-id` rather than
	// `--continue` because it **creates the session when it is missing**, so the
	// first prompt of a brand-new agent behaves exactly like the thousandth;
	// `--continue` would be resuming nothing on that first run.
	//
	// Leave empty for a task-routed agent, where each run is an unrelated task.
	SessionID string
}

PiRunnerConfig holds configuration for spawning the Pi CLI.

type Result

type Result struct {
	Result string `json:"result"`
}

Result is the structured output from a Pi CLI run.

func (Result) GetResult

func (r Result) GetResult() string

type RunError

type RunError struct {
	Msg string
	Err error
}

RunError encapsulates a runner failure.

func (*RunError) Error

func (e *RunError) Error() string

func (*RunError) Unwrap

func (e *RunError) Unwrap() error

Unwrap exposes the underlying cause so callers can use errors.Is/As.

type Runner

type Runner interface {
	Run(ctx context.Context, prompt string) (*Result, error)
}

Runner spawns a headless Pi CLI session with a prompt and tools.

func NewRunner

func NewRunner(config PiRunnerConfig) Runner

NewRunner creates a Runner that spawns pi --print.

type StepConfig

type StepConfig struct {
	Name          string
	Runner        Runner
	Instructions  string
	EnvContext    map[string]string
	OutputSection string
	NextPhase     string
}

StepConfig bundles everything a Pi agent Step needs at construction time.

Jump to

Keyboard shortcuts

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