subagent

package
v0.5.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToJSONRPCMessage

func ToJSONRPCMessage(msg provider.Message) types.Message

ToJSONRPCMessage converts a provider message to JSON-RPC format

Types

type AgentFactory added in v0.3.0

type AgentFactory func(provider provider.Provider, registry ToolRegistry, toolsSchema []map[string]interface{}, systemPrompt string) AgentRunner

AgentFactory is a function type for creating agents

type AgentRunner added in v0.3.0

type AgentRunner interface {
	RunConversation(ctx context.Context, input string) (string, error)
}

AgentRunner is an interface for running agent conversations

type Config

type Config struct {
	MaxConcurrent int           `json:"max_concurrent"` // Max parallel subagents
	MaxDepth      int           `json:"max_depth"`      // Max recursion depth
	Timeout       time.Duration `json:"timeout"`        // Task timeout
	EnableNested  bool          `json:"enable_nested"`  // Enable nested subagents
}

Config holds subagent configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default subagent configuration

type DAGExecutor added in v0.5.1

type DAGExecutor struct {

	// Configuration
	MaxConcurrency int
	Timeout        time.Duration
	// contains filtered or unexported fields
}

DAGExecutor executes a task DAG with configurable concurrency

func NewDAGExecutor added in v0.5.1

func NewDAGExecutor(dag *TaskDAG, prov provider.Provider, cfg DAGExecutorConfig) *DAGExecutor

NewDAGExecutor creates a new DAG executor

func (*DAGExecutor) Execute added in v0.5.1

func (exec *DAGExecutor) Execute(ctx context.Context, goal string, createAgent func(role string, tools []string) *SubAgent) (string, error)

Execute executes all tasks in the DAG respecting dependencies

type DAGExecutorConfig added in v0.5.1

type DAGExecutorConfig struct {
	MaxConcurrency int
	Timeout        time.Duration
}

DAGExecutorConfig configures the DAG executor

func DefaultDAGExecutorConfig added in v0.5.1

func DefaultDAGExecutorConfig() DAGExecutorConfig

DefaultDAGExecutorConfig returns default config

type Manager

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

Manager manages all subagents

func NewManager

func NewManager(cfg *Config, prov provider.Provider, registry ToolRegistry, factory AgentFactory) *Manager

NewManager creates a new subagent manager

func (*Manager) CancelTask added in v0.3.0

func (m *Manager) CancelTask(id string) error

CancelTask cancels a task by ID

func (*Manager) GetResult

func (m *Manager) GetResult(id string) *Result

GetResult returns a result by task ID

func (*Manager) GetStats

func (m *Manager) GetStats() map[string]interface{}

GetStats returns manager statistics

func (*Manager) GetTask

func (m *Manager) GetTask(id string) *Task

GetTask returns a task by ID

func (*Manager) KillSubAgent

func (m *Manager) KillSubAgent(id string) error

KillSubAgent terminates a subagent

func (*Manager) ListSubAgents

func (m *Manager) ListSubAgents() []map[string]interface{}

ListSubAgents returns all active subagents

func (*Manager) ListTasks added in v0.3.0

func (m *Manager) ListTasks(statusFilter TaskStatus) []*Task

ListTasks returns all tasks with optional status filter

func (*Manager) SpawnMultiple

func (m *Manager) SpawnMultiple(tasks []struct {
	Description string
	Input       string
	Tools       []string
}) ([]Result, error)

SpawnMultiple spawns multiple tasks and waits for all results

func (*Manager) SpawnNestedTask added in v0.3.0

func (m *Manager) SpawnNestedTask(parentTaskID, description, input string, tools []string, ctx map[string]interface{}) (string, error)

SpawnNestedTask spawns a nested subagent task from a parent task

func (*Manager) SpawnTask

func (m *Manager) SpawnTask(description, input string, tools []string) (string, error)

SpawnTask spawns a new subagent task

func (*Manager) SpawnTaskWithContext

func (m *Manager) SpawnTaskWithContext(description, input string, tools []string, ctx map[string]interface{}) (string, error)

SpawnTaskWithContext spawns a task with additional context

func (*Manager) Start

func (m *Manager) Start()

Start starts the subagent manager

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the subagent manager

func (*Manager) SubmitTask

func (m *Manager) SubmitTask(task *Task) error

SubmitTask submits a task to the queue

func (*Manager) WaitForResult

func (m *Manager) WaitForResult(taskID string, timeout time.Duration) (*Result, error)

WaitForResult waits for a task result with timeout

type Result

type Result struct {
	TaskID     string        `json:"task_id"`
	Success    bool          `json:"success"`
	Output     string        `json:"output"`
	Error      string        `json:"error,omitempty"`
	Duration   time.Duration `json:"duration"`
	SubResults []Result      `json:"sub_results,omitempty"`
	CreatedAt  time.Time     `json:"created_at"`
}

Result represents the result of a subagent task

type ResultSynthesizer added in v0.5.1

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

ResultSynthesizer synthesizes results from multiple sub-agents

func NewResultSynthesizer added in v0.5.1

func NewResultSynthesizer(prov provider.Provider) *ResultSynthesizer

NewResultSynthesizer creates a new result synthesizer

func (*ResultSynthesizer) SynthesizeResults added in v0.5.1

func (rs *ResultSynthesizer) SynthesizeResults(ctx context.Context, goal string, results map[string]string, failedTasks []*SubTaskNode) (string, error)

SynthesizeResults combines results from multiple sub-tasks into a coherent final result

type SubAgent

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

SubAgent represents a subagent that can execute tasks

func (*SubAgent) Run

func (s *SubAgent) Run(ctx context.Context, input string) (string, error)

Run executes the subagent

type SubTaskNode added in v0.5.1

type SubTaskNode struct {
	ID           string
	Description  string
	Role         string   // researcher, coder, reviewer, planner, etc.
	Tools        []string // Tools available to this sub-agent
	Priority     int
	Dependencies []string // IDs of tasks that must complete first
	Status       SubTaskStatus
	Result       string
	Error        string
	Agent        *SubAgent
	StartTime    time.Time
	EndTime      time.Time
	Duration     time.Duration
	Retries      int
	MaxRetries   int
}

SubTaskNode represents a node in the task dependency graph

type SubTaskStatus added in v0.5.1

type SubTaskStatus string

SubTaskStatus represents the status of a sub-task

const (
	SubTaskPending   SubTaskStatus = "pending"
	SubTaskReady     SubTaskStatus = "ready"
	SubTaskRunning   SubTaskStatus = "running"
	SubTaskCompleted SubTaskStatus = "completed"
	SubTaskFailed    SubTaskStatus = "failed"
	SubTaskSkipped   SubTaskStatus = "skipped"
)

type Task

type Task struct {
	ID          string                 `json:"id"`
	Description string                 `json:"description"`
	Input       string                 `json:"input"`
	Tools       []string               `json:"tools,omitempty"` // Tools to enable for this task
	Context     map[string]interface{} `json:"context,omitempty"`
	ParentID    string                 `json:"parent_id,omitempty"`
	Depth       int                    `json:"depth"`
	Status      TaskStatus             `json:"status"`
	CreatedAt   time.Time              `json:"created_at"`
	StartedAt   *time.Time             `json:"started_at,omitempty"`
	CompletedAt *time.Time             `json:"completed_at,omitempty"`
	Cancelled   bool                   `json:"cancelled"`
	// contains filtered or unexported fields
}

Task represents a task to be executed by a subagent

func (*Task) Cancel added in v0.3.0

func (t *Task) Cancel()

Cancel marks the task as cancelled

func (*Task) GetStatus added in v0.3.0

func (t *Task) GetStatus() TaskStatus

GetStatus gets the task status thread-safely

func (*Task) IsCancelled added in v0.3.0

func (t *Task) IsCancelled() bool

IsCancelled checks if the task is cancelled

func (*Task) SetStatus added in v0.3.0

func (t *Task) SetStatus(status TaskStatus)

SetStatus sets the task status thread-safely

type TaskDAG added in v0.5.1

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

TaskDAG manages a directed acyclic graph of sub-tasks

func BuildDAGFromPlan added in v0.5.1

func BuildDAGFromPlan(planDescription string, tasks []struct {
	ID          string
	Description string
	Role        string
	Tools       []string
	Deps        []string
	Priority    int
}) (*TaskDAG, error)

BuildDAGFromPlan builds a task DAG from a plan description

func NewTaskDAG added in v0.5.1

func NewTaskDAG() *TaskDAG

NewTaskDAG creates a new task DAG

func (*TaskDAG) AddNode added in v0.5.1

func (dag *TaskDAG) AddNode(node *SubTaskNode) error

AddNode adds a task node to the DAG

func (*TaskDAG) GenerateDAGSummary added in v0.5.1

func (dag *TaskDAG) GenerateDAGSummary() string

GenerateDAGSummary generates a text summary of the DAG status

func (*TaskDAG) GetAllNodes added in v0.5.1

func (dag *TaskDAG) GetAllNodes() []*SubTaskNode

GetAllNodes returns all nodes in topological order

func (*TaskDAG) GetFailedTasks added in v0.5.1

func (dag *TaskDAG) GetFailedTasks() []*SubTaskNode

GetFailedTasks returns all failed tasks

func (*TaskDAG) GetNode added in v0.5.1

func (dag *TaskDAG) GetNode(id string) *SubTaskNode

GetNode gets a task node by ID

func (*TaskDAG) GetProgress added in v0.5.1

func (dag *TaskDAG) GetProgress() float64

GetProgress returns the overall progress (0.0 - 1.0)

func (*TaskDAG) GetReadyTasks added in v0.5.1

func (dag *TaskDAG) GetReadyTasks() []*SubTaskNode

GetReadyTasks returns tasks whose dependencies are all satisfied

func (*TaskDAG) GetResults added in v0.5.1

func (dag *TaskDAG) GetResults() map[string]string

GetResults returns all completed results in topological order

func (*TaskDAG) IsComplete added in v0.5.1

func (dag *TaskDAG) IsComplete() bool

IsComplete returns whether all tasks are done (completed or failed)

func (*TaskDAG) UpdateStatus added in v0.5.1

func (dag *TaskDAG) UpdateStatus(id string, status SubTaskStatus) error

UpdateStatus updates the status of a task node

type TaskStatus added in v0.3.0

type TaskStatus string

TaskStatus represents the status of a task

const (
	TaskStatusPending   TaskStatus = "pending"
	TaskStatusRunning   TaskStatus = "running"
	TaskStatusCompleted TaskStatus = "completed"
	TaskStatusFailed    TaskStatus = "failed"
	TaskStatusCancelled TaskStatus = "cancelled"
)

type Tool added in v0.3.0

type Tool interface {
	Name() string
	Description() string
	Schema() map[string]interface{}
}

Tool is an interface for tools

type ToolRegistry added in v0.3.0

type ToolRegistry interface {
	List() []string
	Get(name string) (Tool, error)
}

ToolRegistry is an interface for tool registry to avoid circular imports

Jump to

Keyboard shortcuts

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