Documentation
¶
Index ¶
- Constants
- func BuildPrompt(instructions string, envContext map[string]string, taskContent string) string
- func BuildResultSection(r string) string
- func NewSession(runner Runner) agentlib.Session
- func NewSessionFactory(base PiRunnerConfig, newRunner func(PiRunnerConfig) Runner) agentlib.SessionFactory
- func NewStep(cfg StepConfig) agentlib.Step
- func PrintResult(ctx context.Context, result Result) error
- type AgentStatus
- type PiRunnerConfig
- type Result
- type RunError
- type Runner
- type StepConfig
Constants ¶
const ( AgentStatusDone = agentlib.AgentStatusDone AgentStatusFailed = agentlib.AgentStatusFailed AgentStatusNeedsInput = agentlib.AgentStatusNeedsInput )
Variables ¶
This section is empty.
Functions ¶
func BuildPrompt ¶
BuildPrompt combines instructions with environment context and task content.
func BuildResultSection ¶
BuildResultSection renders a Result as a markdown section.
func NewSession ¶ added in v0.92.0
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.
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.