pony

package
v0.20.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RuntimeIDKey = &runtimeIDKey{}

Functions

func DegenerateReasoningStopReason added in v0.15.0

func DegenerateReasoningStopReason() string

DegenerateReasoningStopReason exposes the canonical stop reason for tests and other packages that need to recognise or forward it.

func LoadAgentsMD

func LoadAgentsMD(dir string) string

LoadAgentsMD walks up from dir to find an AGENTS.md file. Returns the content if found, or empty string if not found (not an error).

func LoopWithRetry

func LoopWithRetry(
	ctx context.Context,
	adapter model.Adapter,
	modelName string,
	maxTokens int,
	history []model.Message,
	reg *tools.Registry,
	workingDir string,
	eventCh chan<- events.Event,
	stopConditions []StopCondition,
	approval ApprovalChecker,
) ([]model.Message, string, error)

LoopWithRetry wraps RunLoop with exponential backoff retry. Retries on error only if no tool calls were dispatched (retrying after tool execution is unsafe because side effects would replay). Max 4 attempts total. Backoff: 1s, 2s, 4s.

func MergeSkills

func MergeSkills(baseSystem, baseInitial string, skills []Skill) (system, initial string)

MergeSkills merges skill prompts into a profile's system_prompt and initial_prompt. Later skills' prompts are appended with section headers.

func RunLoop

func RunLoop(
	ctx context.Context,
	adapter model.Adapter,
	modelName string,
	maxTokens int,
	history []model.Message,
	reg *tools.Registry,
	workingDir string,
	eventCh chan<- events.Event,
	stopConditions []StopCondition,
	approval ApprovalChecker,
) ([]model.Message, string, error)

RunLoop drives the multi-turn loop until a stop condition or terminal condition.

It sends the history + tool defs to the adapter each turn, processes streamed chunks, accumulates tool calls, dispatches them through the registry, and appends results to history.

If approval is non-nil, it is called before each tool to check for permission. Events are emitted on eventCh as the loop runs for subscribers.

Returns the final conversation history (including all assistant and tool turns) and the final stop reason.

func SetCompactionTaskPrompt added in v0.15.0

func SetCompactionTaskPrompt(prompt string)

SetCompactionTaskPrompt overrides the task prompt for LLM compaction. Empty string resets to the default. Safe to call concurrently with RunLoop.

func SetCompactionThreshold added in v0.15.0

func SetCompactionThreshold(bytes int)

SetCompactionThreshold overrides the byte threshold for compactForRequest. Values <= 0 reset to the default (80 KB). Called from New() which derives the byte value from the profile's Context field (tokens × bytesPerToken).

func SetGlobalConfig

func SetGlobalConfig(cfg *Config)

SetGlobalConfig stores the pony config for the factory path.

func SetGlobalProfiles added in v0.15.0

func SetGlobalProfiles(defaultAgent string, profiles map[string]Config)

SetGlobalProfiles stores pony profile configs for per-attempt agent resolution.

Types

type ApprovalChecker

type ApprovalChecker func(ctx context.Context, toolName string, eventCh chan<- events.Event) (bool, error)

ApprovalChecker is called before a tool executes. It blocks until the permission is granted or denied. Returns true if approved, false if denied.

type Config

type Config struct {
	Adapter          model.Adapter
	Model            string
	MaxTokens        int
	SystemPrompt     string
	InitialPrompt    string
	Executor         OrchestratorExecutor // nil when OrchTools is false
	LocalTools       bool
	OrchTools        bool
	WorkingDir       string // for AGENTS.md discovery
	InjectAgentsMD   bool
	AllowedReadDirs  []string        // additional directories read tools may access (e.g. skills)
	AllowedWriteDirs []string        // additional directories write tools may access
	ToolApproval     map[string]bool // tool name → requires approval
	ShellConfig      *ShellConfig    // overrides for shell tool
	FileReadConfig   *FileReadConfig // overrides for file_read tool
	Context          int             // model context window in tokens; 0 = use default compaction
	CompactionPrompt string          // override LLM compaction task prompt

	// StopConditions for the loop.
	StopConditions []StopCondition
	// contains filtered or unexported fields
}

Config configures the pony provider.

type FileReadConfig added in v0.15.0

type FileReadConfig = tools.FileReadConfig

FileReadConfig overrides file_read tool defaults per-profile.

type LoopRunState

type LoopRunState struct {
	StepCount   int
	CalledTools []string // tool names called so far
}

LoopRunState tracks the state across loop iterations for stop conditions.

type OrchestratorExecutor

type OrchestratorExecutor interface {
	SpawnAgent(ctx context.Context, params map[string]any) (sessionID string, err error)
	SendPrompt(ctx context.Context, sessionID, prompt, requestID string) error
	GetStatus(ctx context.Context, sessionID string) (map[string]any, error)
	WaitForDone(ctx context.Context, sessionID string) (*runtime.AgentResult, error)
	SendToParent(ctx context.Context, runtimeID, message string) error
}

OrchestratorExecutor wraps the control-socket client for orchestration tools.

func NewControlSocketExecutor

func NewControlSocketExecutor(socketPath string) (OrchestratorExecutor, error)

NewControlSocketExecutor creates an OrchestratorExecutor backed by a control socket client. This is used by the CLI to wire orchestration tools.

type PonyConfig

type PonyConfig struct {
	BaseURL      string             `json:"base_url"`
	APIKeyEnv    string             `json:"api_key_env"`
	DefaultAgent string             `json:"default_agent"`
	Profiles     map[string]Profile `json:"profiles"`
}

PonyConfig is the top-level pony configuration loaded from the JSON config file.

func LoadPonyConfig

func LoadPonyConfig(path string) (*PonyConfig, error)

LoadPonyConfig reads and parses a JSON pony config file.

func (*PonyConfig) ResolveProfile

func (c *PonyConfig) ResolveProfile(name string) (*Profile, error)

ResolveProfile looks up a profile by name, falling back to default_agent.

type Profile

type Profile struct {
	Model            string          `json:"model"`
	SystemPrompt     string          `json:"system_prompt,omitempty"`
	InitialPrompt    string          `json:"initial_prompt,omitempty"`
	InjectAgentsMD   bool            `json:"inject_agents_md,omitempty"`
	Tools            ToolGate        `json:"tools"`
	MaxTokens        int             `json:"max_tokens,omitempty"`
	ToolApproval     ToolApproval    `json:"tool_approval,omitempty"`
	ShellConfig      *ShellConfig    `json:"shell_config,omitempty"`
	FileReadConfig   *FileReadConfig `json:"file_read_config,omitempty"`
	BaseURL          string          `json:"base_url,omitempty"`
	APIKeyEnv        string          `json:"api_key_env,omitempty"`
	Skills           []string        `json:"skills,omitempty"`            // skill names to load
	Context          int             `json:"context,omitempty"`           // model context window in tokens; 0 = use default compaction (80 KB)
	CompactionPrompt string          `json:"compaction_prompt,omitempty"` // override LLM compaction task prompt
}

Profile defines a named agent profile with its own model, prompts, and tool gating.

type Provider

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

Provider implements runtime.Provider for the pony backend.

func New

func New(cfg Config) *Provider

New creates a new pony provider with the given config.

func NewWithOptions

func NewWithOptions(opts runtime.StartOptions) *Provider

func (*Provider) AnswerPermission

func (p *Provider) AnswerPermission(ctx context.Context, sessionID string, requestID string, response runtime.PermissionResponse) error

func (*Provider) Cancel

func (p *Provider) Cancel(ctx context.Context, sessionID string) error

func (*Provider) Capabilities

func (p *Provider) Capabilities(ctx context.Context) (runtime.Capabilities, error)

func (*Provider) Events

func (p *Provider) Events(ctx context.Context, sessionID string) (<-chan events.Event, error)

func (*Provider) Prompt

func (p *Provider) Prompt(ctx context.Context, sessionID string, prompt string) error

func (*Provider) Resume

func (p *Provider) Resume(ctx context.Context, sessionID string) (runtime.Session, error)

func (*Provider) Start

type ShellConfig

type ShellConfig = tools.ShellConfig

ShellConfig overrides shell tool defaults per-profile. This is a reference to the tools.ShellConfig type, aliased for convenience.

type Skill

type Skill struct {
	Name          string `json:"name"`
	SystemPrompt  string `json:"system_prompt,omitempty"`
	InitialPrompt string `json:"initial_prompt,omitempty"`
}

Skill is a reusable prompt component loaded from a skill file.

func LoadSkills

func LoadSkills(configDir string, skillNames []string) ([]Skill, error)

LoadSkills discovers and loads skills referenced by a profile. Discovery order:

  1. $PONY_SKILLS_DIR env var
  2. .pony/skills/ next to the config file
  3. ~/.config/avenor/skills/

Skill files can be JSON (.json) or Markdown (.md). JSON format: {"system_prompt": "...", "initial_prompt": "..."} MD format: first section after frontmatter is system_prompt, second section (after ---) is initial_prompt.

type StopCondition

type StopCondition func(state LoopRunState) bool

StopCondition is a function that returns true when the loop should stop. Called after each turn (including tool execution).

func StepCountIs

func StepCountIs(n int) StopCondition

StepCountIs returns a stop condition that triggers after n steps (loop turns).

type ToolApproval

type ToolApproval map[string]bool

ToolApproval maps tool names to whether they require approval before execution.

type ToolGate

type ToolGate struct {
	Local         bool `json:"local"`
	Orchestration bool `json:"orchestration"`
}

ToolGate controls which tool groups are enabled for a profile.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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