agent

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package agent provides agent lifecycle management and orchestration.

Index

Constants

This section is empty.

Variables

View Source
var (
	StateFile = filepath.Join(os.TempDir(), "pagent-state.json")
)

State file paths

Functions

func ClearState

func ClearState()

ClearState removes the state file

func LoadState

func LoadState() (map[string]int, error)

LoadState loads agent state from disk

func RemoveAgentFromState added in v0.1.2

func RemoveAgentFromState(agentName string) error

RemoveAgentFromState removes a specific agent from the state file

Types

type LibClient

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

LibClient provides direct library integration with agentapi instead of spawning the agentapi binary and communicating via HTTP

func NewLibClient

func NewLibClient(ctx context.Context, cfg LibClientConfig) (*LibClient, error)

NewLibClient creates a new agentapi library client

func (*LibClient) Close

func (c *LibClient) Close(ctx context.Context) error

Close shuts down the agent and server

func (*LibClient) GetProcess

func (c *LibClient) GetProcess() *termexec.Process

GetProcess returns the underlying termexec.Process for advanced usage

func (*LibClient) Handler

func (c *LibClient) Handler() http.Handler

Handler returns the HTTP handler for custom server setups

func (*LibClient) Port

func (c *LibClient) Port() int

Port returns the port the server is listening on

func (*LibClient) ReadScreen

func (c *LibClient) ReadScreen() string

ReadScreen returns the current terminal screen content

func (*LibClient) SendMessage

func (c *LibClient) SendMessage(content string) error

SendMessage sends a message to the agent

func (*LibClient) Start

func (c *LibClient) Start() error

Start begins serving the HTTP API (non-blocking)

func (*LibClient) WaitForCompletion

func (c *LibClient) WaitForCompletion(ctx context.Context, timeout time.Duration) error

WaitForCompletion waits for the agent to finish processing a task

func (*LibClient) WaitForStable

func (c *LibClient) WaitForStable(timeout time.Duration) error

WaitForStable waits for the agent to reach stable state

type LibClientConfig

type LibClientConfig struct {
	Port           int
	Verbose        bool
	AgentCmd       string   // e.g., "claude"
	AgentArgs      []string // additional args for the agent
	TerminalWidth  uint16
	TerminalHeight uint16
}

LibClientConfig configures the library client

type Manager

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

Manager manages agent lifecycle

func NewManager

func NewManager(cfg *config.Config, prdPath string, verbose bool) *Manager

NewManager creates a new agent manager

func NewManagerWithInputs

func NewManagerWithInputs(cfg *config.Config, primaryFile string, inputFiles []string, inputDir string, verbose bool) *Manager

NewManagerWithInputs creates a manager with multiple input files

func (*Manager) ExpandWithDependencies

func (m *Manager) ExpandWithDependencies(agents []string) []string

ExpandWithDependencies takes a list of agents and returns the list expanded to include all transitive dependencies. The returned list is in dependency order.

func (*Manager) GetDependencyLevels

func (m *Manager) GetDependencyLevels(agents []string) [][]string

GetDependencyLevels groups agents by dependency level for parallel execution. Level 0: agents with no dependencies Level 1: agents whose dependencies are all in level 0 Level N: agents whose dependencies are all in levels 0..N-1 Returns a slice of levels, where each level is a slice of agent names.

func (*Manager) GetRunningAgents

func (m *Manager) GetRunningAgents() []*RunningAgent

GetRunningAgents returns currently running agents

func (*Manager) GetTransitiveDependencies

func (m *Manager) GetTransitiveDependencies(agentName string) []string

GetTransitiveDependencies returns all dependencies for an agent, including transitive ones. This is useful for auto-including required agents when a user requests a specific agent.

func (*Manager) RunAgent

func (m *Manager) RunAgent(ctx context.Context, name string) Result

RunAgent spawns and runs a single agent

func (*Manager) StopAll

func (m *Manager) StopAll()

StopAll stops all running agents

func (*Manager) TopologicalSort

func (m *Manager) TopologicalSort(agents []string) []string

TopologicalSort returns agents in dependency order

type Orchestrator

type Orchestrator interface {
	// RunAgent executes a single agent and returns the result.
	RunAgent(ctx context.Context, name string) Result

	// TopologicalSort returns agents in dependency order.
	TopologicalSort(agents []string) []string

	// GetDependencyLevels groups agents by dependency level for parallel execution.
	// Level 0 agents have no dependencies, level 1 depends only on level 0, etc.
	GetDependencyLevels(agents []string) [][]string

	// ExpandWithDependencies takes a list of agents and returns the list expanded
	// to include all transitive dependencies in dependency order.
	ExpandWithDependencies(agents []string) []string

	// GetTransitiveDependencies returns all dependencies for an agent, including transitive ones.
	GetTransitiveDependencies(agentName string) []string

	// StopAll stops all running agents.
	StopAll()

	// GetRunningAgents returns currently running agents.
	GetRunningAgents() []*RunningAgent
}

Orchestrator defines the interface for agent orchestration. This abstraction enables: - Unit testing with mock implementations - Alternative implementations (e.g., remote agent execution) - Dependency injection in calling code

type OrchestratorConfig

type OrchestratorConfig struct {
	// Config is the pagent configuration
	Config interface {
		GetAgentNames() []string
		GetDependencies(name string) []string
	}

	// PrimaryFile is the main input file
	PrimaryFile string

	// InputFiles is the list of all input files
	InputFiles []string

	// InputDir is the input directory (empty if single file)
	InputDir string

	// Verbose enables debug logging
	Verbose bool
}

OrchestratorConfig contains configuration for creating an orchestrator. This provides a cleaner factory interface than passing many parameters.

type Result

type Result struct {
	Agent      string
	OutputPath string
	Error      error
	Duration   time.Duration
}

Result represents the result of running an agent

type RunningAgent

type RunningAgent struct {
	Name      string
	Port      int
	Client    *api.Client // HTTP client for status polling
	LibClient *LibClient  // Library client for agent management
	StartedAt time.Time
}

RunningAgent tracks a running agent

Jump to

Keyboard shortcuts

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