leader

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxSteps is the default maximum number of steps allowed per request.
	DefaultMaxSteps = 10

	// DefaultMaxParallelTasks is the default maximum number of tasks that can run in parallel.
	DefaultMaxParallelTasks = 10

	// DefaultRetryAttempts is the default number of retry attempts for failed operations.
	DefaultRetryAttempts = 3

	// DefaultSimilarTasksLimit is the default limit for similar task search results.
	DefaultSimilarTasksLimit = 3

	// DefaultSimilarityThreshold is the default similarity threshold for task matching.
	// Tasks with similarity below this value will be filtered out.
	DefaultSimilarityThreshold = 0.5

	// DefaultContextHistoryLength is the default maximum number of messages to keep in context.
	DefaultContextHistoryLength = 10

	// DefaultSummaryLength is the default maximum length for result summaries in characters.
	DefaultSummaryLength = 200
)

Default configuration constants for LeaderAgent.

View Source
const (
	// DefaultTaskTimeout is the default timeout for task execution.
	DefaultTaskTimeout = 5 * time.Minute

	// DefaultDispatchTimeout is the default timeout for task dispatch operations.
	DefaultDispatchTimeout = 2 * time.Minute

	// DefaultAggregationTimeout is the default timeout for result aggregation.
	DefaultAggregationTimeout = 1 * time.Minute
)

Timeout constants for LeaderAgent operations.

View Source
const SortByCreatedAt = "created_at"

SortByCreatedAt sorts items by TaskResult.CreatedAt (newest first).

View Source
const SortByNone = "none"

SortByNone disables sorting; items remain in their original order.

View Source
const SortByPriority = "priority"

SortByPriority sorts items by the associated Task.Priority (descending).

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent interface {
	base.Agent
}

Agent represents the Leader Agent interface.

func New

func New(
	id string,
	parser ProfileParser,
	planner TaskPlanner,
	dispatcher TaskDispatcher,
	aggregator ResultAggregator,
	msgQueue *ahp.MessageQueue,
	hbMon *ahp.HeartbeatMonitor,
	memMgr memory.MemoryManager,
	cfg *LeaderAgentConfig,
) Agent

New creates a new LeaderAgent instance.

type LeaderAgentConfig

type LeaderAgentConfig struct {
	base.Config
	MaxParallelTasks int
	MaxSteps         int
	EnableCache      bool
}

LeaderAgentConfig holds configuration for LeaderAgent.

func DefaultLeaderAgentConfig

func DefaultLeaderAgentConfig() *LeaderAgentConfig

DefaultLeaderAgentConfig returns default configuration.

type LocalMessageSender

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

LocalMessageSender sends messages to local agent queues.

func NewLocalMessageSender

func NewLocalMessageSender() *LocalMessageSender

NewLocalMessageSender creates a new LocalMessageSender.

func (*LocalMessageSender) RegisterQueue

func (s *LocalMessageSender) RegisterQueue(agentAddr string, queue *ahp.MessageQueue)

RegisterQueue registers a message queue for an agent address.

func (*LocalMessageSender) Send

func (s *LocalMessageSender) Send(ctx context.Context, agentAddr string, msg *ahp.AHPMessage) error

Send sends a message to the specified agent address.

type MessageSender

type MessageSender interface {
	Send(ctx context.Context, agentAddr string, msg *ahp.AHPMessage) error
}

MessageSender sends messages to sub-agents (for distributed deployment).

type ProfileParser

type ProfileParser interface {
	Parse(ctx context.Context, input string) (*models.UserProfile, error)
}

ProfileParser parses user profile from input.

func NewProfileParser

func NewProfileParser(
	llmAdapter output.LLMAdapter,
	template *output.TemplateEngine,
	promptTpl string,
	validator *output.Validator,
	maxRetries int,
) ProfileParser

NewProfileParser creates a new ProfileParser with LLM support.

type ResultAggregator

type ResultAggregator interface {
	Aggregate(ctx context.Context, results []*models.TaskResult, tasks []*models.Task) (*models.RecommendResult, error)
}

ResultAggregator aggregates results from sub-agents.

func NewResultAggregator

func NewResultAggregator(enableDedupe bool, maxItems int, sortBy string) ResultAggregator

NewResultAggregator creates a new ResultAggregator. sortBy controls the ordering of aggregated items and must be one of: SortByNone ("none"), SortByPriority ("priority"), or SortByCreatedAt ("created_at"). An unrecognised value is treated as SortByNone.

type SubAgentConfig

type SubAgentConfig struct {
	ID       string
	Type     string
	Triggers []string
	Priority int // Optional. Defaults to 1 if unset or <= 0.
}

SubAgentConfig represents sub agent configuration (mirrors config.SubAgentConfig). SubAgentConfig defines a sub-agent that can be dispatched by the planner.

type TaskDispatcher

type TaskDispatcher interface {
	Dispatch(ctx context.Context, tasks []*models.Task) ([]*models.TaskResult, error)
	RegisterExecutor(agentType models.AgentType, fn func(ctx context.Context, task *models.Task) (*models.TaskResult, error))
}

TaskDispatcher dispatches tasks to sub-agents.

func NewTaskDispatcher

func NewTaskDispatcher(agentRegistry map[models.AgentType]string, maxParallel int, timeout int, sender MessageSender) TaskDispatcher

NewTaskDispatcher creates a new TaskDispatcher.

type TaskExecutorFunc

type TaskExecutorFunc func(ctx context.Context, task *models.Task) (*models.TaskResult, error)

TaskExecutorFunc is a function type for executing tasks directly.

type TaskPlanner

type TaskPlanner interface {
	Plan(ctx context.Context, profile *models.UserProfile, inputText string) ([]*models.Task, error)
}

TaskPlanner plans tasks based on user profile and input text.

func NewTaskPlanner

func NewTaskPlanner(maxTasks int) TaskPlanner

NewTaskPlanner creates a new TaskPlanner.

func NewTaskPlannerWithConfig

func NewTaskPlannerWithConfig(maxTasks int, subAgents []SubAgentConfig) TaskPlanner

NewTaskPlannerWithConfig creates a TaskPlanner with sub-agent configuration.

Jump to

Keyboard shortcuts

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