Help us shape the future of Go! Take the 2026 Go Developer Survey

planner

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ToolCreatePlan    = "create_plan"
	ToolUpdatePlan    = "update_plan"
	ToolGetPlanStatus = "get_plan_status"
)

Tool names for planner tools.

Variables

This section is empty.

Functions

func CreatePlanToolSchema

func CreatePlanToolSchema() types.ToolSchema

CreatePlanToolSchema returns the tool schema for creating a plan.

func GetPlanStatusToolSchema

func GetPlanStatusToolSchema() types.ToolSchema

GetPlanStatusToolSchema returns the tool schema for querying plan status.

func GetPlannerToolSchemas

func GetPlannerToolSchemas() []types.ToolSchema

GetPlannerToolSchemas returns all planner tool schemas.

func UpdatePlanToolSchema

func UpdatePlanToolSchema() types.ToolSchema

UpdatePlanToolSchema returns the tool schema for updating a plan.

Types

type CreatePlanArgs

type CreatePlanArgs struct {
	Title string           `json:"title"`
	Tasks []CreateTaskArgs `json:"tasks"`
}

CreatePlanArgs contains the arguments for creating a new plan.

type CreateTaskArgs

type CreateTaskArgs struct {
	ID           string         `json:"id"`
	ParentID     string         `json:"parent_id,omitempty"`
	Title        string         `json:"title"`
	Description  string         `json:"description"`
	AssignTo     string         `json:"assign_to,omitempty"`
	Dependencies []string       `json:"dependencies,omitempty"`
	Priority     int            `json:"priority,omitempty"`
	Metadata     map[string]any `json:"metadata,omitempty"`
}

CreateTaskArgs contains the arguments for creating a single task within a plan.

type DefaultDispatcher

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

DefaultDispatcher implements TaskDispatcher with configurable strategies.

func NewDefaultDispatcher

func NewDefaultDispatcher(strategy DispatchStrategy, logger *zap.Logger) *DefaultDispatcher

NewDefaultDispatcher creates a new DefaultDispatcher.

func (*DefaultDispatcher) Dispatch

func (d *DefaultDispatcher) Dispatch(ctx context.Context, task *PlanTask, executors map[string]Executor) (*TaskOutput, error)

Dispatch selects an executor and runs the task.

type DispatchStrategy

type DispatchStrategy string

DispatchStrategy determines how tasks are assigned to executors.

const (
	StrategyByRole       DispatchStrategy = "by_role"       // 按角色名匹配
	StrategyByCapability DispatchStrategy = "by_capability" // 按能力匹配(当前同 by_role)
	StrategyRoundRobin   DispatchStrategy = "round_robin"   // 轮询分配
)

type Executor

type Executor interface {
	ID() string
	Name() string
	Execute(ctx context.Context, content string, taskCtx map[string]any) (*TaskOutput, error)
}

Executor is the minimal interface a planner task dispatcher needs from an agent. Decoupled from agent.Agent to avoid circular imports.

type Plan

type Plan struct {
	ID         string
	Title      string
	RootTaskID string // 根任务 ID
	Tasks      map[string]*PlanTask
	Status     PlanStatus
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

Plan represents an execution plan containing multiple tasks.

func (*Plan) HasFailed

func (p *Plan) HasFailed() bool

HasFailed returns true if any task has failed.

func (*Plan) IsComplete

func (p *Plan) IsComplete() bool

IsComplete returns true when every task is in a terminal state.

func (*Plan) ReadyTasks

func (p *Plan) ReadyTasks() []*PlanTask

ReadyTasks returns tasks whose dependencies are all completed and status is pending or ready.

func (*Plan) StatusReport

func (p *Plan) StatusReport() *PlanStatusReport

StatusReport generates a PlanStatusReport from the current plan state.

type PlanExecutor

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

PlanExecutor executes a plan by dispatching tasks in topological order with parallel execution.

func NewPlanExecutor

func NewPlanExecutor(planner *TaskPlanner, dispatcher TaskDispatcher, maxParallel int, logger *zap.Logger) *PlanExecutor

NewPlanExecutor creates a new PlanExecutor.

func (*PlanExecutor) ExecuteWithAgents

func (e *PlanExecutor) ExecuteWithAgents(ctx context.Context, planID string, executors map[string]Executor) (*TaskOutput, error)

ExecuteWithAgents executes a plan by dispatching tasks to the provided executors.

type PlanStatus

type PlanStatus string

PlanStatus represents the overall status of a plan.

const (
	PlanStatusPending   PlanStatus = "pending"
	PlanStatusRunning   PlanStatus = "running"
	PlanStatusCompleted PlanStatus = "completed"
	PlanStatusFailed    PlanStatus = "failed"
)

type PlanStatusReport

type PlanStatusReport struct {
	PlanID         string
	Status         PlanStatus
	TotalTasks     int
	CompletedTasks int
	FailedTasks    int
	RunningTasks   int
	PendingTasks   int
	TaskDetails    []TaskDetail
}

PlanStatusReport provides a summary of plan execution progress.

type PlanTask

type PlanTask struct {
	ID           string
	ParentID     string // 父任务 ID(支持递归分解)
	Title        string
	Description  string
	AssignTo     string   // 目标 agent role/id
	Dependencies []string // 依赖的任务 ID 列表
	Priority     int
	Status       PlanTaskStatus
	Result       *TaskOutput
	Error        string
	Metadata     map[string]any
}

PlanTask represents a single task within a plan.

type PlanTaskStatus

type PlanTaskStatus string

PlanTaskStatus represents the status of an individual task within a plan.

const (
	TaskStatusPending   PlanTaskStatus = "pending"
	TaskStatusBlocked   PlanTaskStatus = "blocked"
	TaskStatusReady     PlanTaskStatus = "ready"
	TaskStatusRunning   PlanTaskStatus = "running"
	TaskStatusCompleted PlanTaskStatus = "completed"
	TaskStatusFailed    PlanTaskStatus = "failed"
	TaskStatusSkipped   PlanTaskStatus = "skipped"
)

type PlannerToolHandler

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

PlannerToolHandler handles tool calls for planner operations. It is an infrastructure adapter for plan CRUD/status tools only and must not evolve into a default closed-loop agent execution entrypoint.

func NewPlannerToolHandler

func NewPlannerToolHandler(planner *TaskPlanner) *PlannerToolHandler

NewPlannerToolHandler creates a new PlannerToolHandler.

func (*PlannerToolHandler) CanHandle

func (h *PlannerToolHandler) CanHandle(name string) bool

CanHandle returns true if the tool name is a planner tool.

func (*PlannerToolHandler) Handle

Handle dispatches a tool call to the appropriate handler method.

type TaskDetail

type TaskDetail struct {
	ID       string
	Title    string
	Status   PlanTaskStatus
	AssignTo string
	Error    string
}

TaskDetail provides status information for a single task.

type TaskDispatcher

type TaskDispatcher interface {
	Dispatch(ctx context.Context, task *PlanTask, executors map[string]Executor) (*TaskOutput, error)
}

TaskDispatcher dispatches a task to an appropriate executor.

type TaskOutput

type TaskOutput struct {
	Content    string
	TokensUsed int
	Cost       float64
	Duration   time.Duration
	Metadata   map[string]any
}

TaskOutput holds the result of a dispatched task execution. Decoupled from agent.Output to avoid circular imports.

type TaskPlanner

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

TaskPlanner manages plans and their lifecycle.

func NewTaskPlanner

func NewTaskPlanner(dispatcher TaskDispatcher, logger *zap.Logger) *TaskPlanner

NewTaskPlanner creates a new TaskPlanner instance.

func (*TaskPlanner) CreatePlan

func (p *TaskPlanner) CreatePlan(_ context.Context, args CreatePlanArgs) (*Plan, error)

CreatePlan creates a new plan from the given arguments.

func (*TaskPlanner) DeletePlan

func (p *TaskPlanner) DeletePlan(planID string)

DeletePlan removes a plan from the planner.

func (*TaskPlanner) GetPlan

func (p *TaskPlanner) GetPlan(planID string) (*Plan, bool)

GetPlan returns a plan by ID.

func (*TaskPlanner) GetPlanStatus

func (p *TaskPlanner) GetPlanStatus(_ context.Context, planID string) (*PlanStatusReport, error)

GetPlanStatus returns a status report for the given plan.

func (*TaskPlanner) SetPlanStatus

func (p *TaskPlanner) SetPlanStatus(planID string, status PlanStatus)

SetPlanStatus sets the status of a plan (used by executor).

func (*TaskPlanner) SetTaskResult added in v1.8.10

func (p *TaskPlanner) SetTaskResult(planID, taskID string, status PlanTaskStatus, output *TaskOutput, errMsg string)

SetTaskResult updates a task's status and stores its result atomically. Used by PlanExecutor to record task completion/failure without exposing internal locks.

func (*TaskPlanner) UpdatePlan

func (p *TaskPlanner) UpdatePlan(_ context.Context, args UpdatePlanArgs) error

UpdatePlan updates task statuses within an existing plan.

type TaskUpdate

type TaskUpdate struct {
	TaskID string          `json:"task_id"`
	Status *PlanTaskStatus `json:"status,omitempty"`
	Error  *string         `json:"error,omitempty"`
}

TaskUpdate describes a status update for a single task.

type UpdatePlanArgs

type UpdatePlanArgs struct {
	PlanID      string       `json:"plan_id"`
	TaskUpdates []TaskUpdate `json:"task_updates"`
}

UpdatePlanArgs contains the arguments for updating an existing plan.

Jump to

Keyboard shortcuts

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