taskmaster

package
v2.0.4 Latest Latest
Warning

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

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

Documentation

Overview

Package taskmaster provides an unstable reusable async message scheduler.

The runtime coordinates local node inboxes and external dispatch targets around one public Message type. Nodes receive one message, can emit many addressed messages while running, and return one terminal Outcome.

Index

Constants

View Source
const (
	// MessageKindJob identifies a job message.
	MessageKindJob = "job"
	// MessageKindProgress identifies a progress update message.
	MessageKindProgress = "progress"
	// MessageKindNotification identifies a notification message.
	MessageKindNotification = "notification"
	// MessageKindResult identifies a result message.
	MessageKindResult = "result"
	// MessageKindError identifies an error message.
	MessageKindError = "error"

	// OutcomeStatusCompleted means a node completed message handling successfully.
	OutcomeStatusCompleted = "completed"
	// OutcomeStatusFailed means a node failed message handling.
	OutcomeStatusFailed = "failed"
	// OutcomeStatusStopped means a node requested runtime shutdown.
	OutcomeStatusStopped = "stopped"
)
View Source
const (
	// LocatorClassAgent identifies an agent endpoint.
	LocatorClassAgent = "agent"
	// LocatorClassAlias identifies an alias endpoint.
	LocatorClassAlias = "alias"
	// LocatorClassHuman identifies a human endpoint.
	LocatorClassHuman = "human"
	// LocatorClassIntegration identifies an integration endpoint.
	LocatorClassIntegration = "integration"

	// LocatorTransportCLI identifies CLI transport.
	LocatorTransportCLI = "cli"
	// LocatorTransportFakeChat identifies fake chat transport.
	LocatorTransportFakeChat = "fakechat"
	// LocatorTransportLocal identifies in-process local transport.
	LocatorTransportLocal = "local"
	// LocatorTransportTelegram identifies Telegram transport.
	LocatorTransportTelegram = "telegram"
	// LocatorTransportTimer identifies timer transport.
	LocatorTransportTimer = "timer"
	// LocatorTransportWhatsApp identifies WhatsApp transport.
	LocatorTransportWhatsApp = "whatsapp"

	// CLIInputKey identifies the built-in CLI input endpoint.
	CLIInputKey = "input"
	// CLILogKey identifies the built-in CLI log endpoint.
	CLILogKey = "log"
	// DefaultTimerKey identifies the default timer endpoint.
	DefaultTimerKey = "default"
)

Variables

View Source
var ErrUnsupported = errors.New("unsupported locator operation")

ErrUnsupported reports that a target cannot handle the requested locator operation.

Functions

This section is empty.

Types

type CLILogTarget

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

CLILogTarget writes CLI log messages through zerolog.

func (CLILogTarget) DispatchMessage

func (t CLILogTarget) DispatchMessage(_ context.Context, msg Message) error

DispatchMessage writes a message to the configured logger.

func (CLILogTarget) Supports

func (t CLILogTarget) Supports(locator Locator) bool

Supports reports whether the target handles the locator.

type Config

type Config struct {
	Logger        *zerolog.Logger
	RootNodeID    string
	Nodes         map[string]Node
	Targets       []Target
	OutcomeRouter OutcomeRouter
}

Config configures a taskmaster runtime.

type EmitFunc

type EmitFunc func(ctx context.Context, msg Message) error

EmitFunc sends a message produced by a node back into the runtime.

type Locator

type Locator struct {
	Class     string         `json:"class"`
	Transport string         `json:"transport"`
	Key       string         `json:"key"`
	Address   map[string]any `json:"address,omitempty"`
}

Locator identifies a message source or destination.

func NewAgentLocator

func NewAgentLocator(id string) Locator

NewAgentLocator constructs a local agent locator.

func NewCLIInputLocator

func NewCLIInputLocator() Locator

NewCLIInputLocator constructs the built-in CLI input locator.

func NewCLILogLocator

func NewCLILogLocator() Locator

NewCLILogLocator constructs the built-in CLI log locator.

func NewFakeChatHumanLocator

func NewFakeChatHumanLocator(chatID string) Locator

NewFakeChatHumanLocator constructs a fake chat human locator.

func NewLocator

func NewLocator(locatorClass string, transport string, key string) Locator

NewLocator constructs a normalized locator.

func NewTelegramHumanLocator

func NewTelegramHumanLocator(chatID int64, topicID int) Locator

NewTelegramHumanLocator constructs a Telegram human locator.

func NewTimerSourceLocator

func NewTimerSourceLocator() Locator

NewTimerSourceLocator constructs the built-in timer source locator.

func NewWhatsAppHumanLocator

func NewWhatsAppHumanLocator(phoneNumberID string) Locator

NewWhatsAppHumanLocator constructs a WhatsApp human locator.

func NormalizeLocator

func NormalizeLocator(locator Locator) (Locator, error)

NormalizeLocator validates and canonicalizes a locator.

func (Locator) String

func (l Locator) String() string

type Message

type Message struct {
	ID        string         `json:"id"`
	SessionID string         `json:"session_id"`
	Kind      string         `json:"kind"`
	From      Locator        `json:"from"`
	To        Locator        `json:"to"`
	ParentID  string         `json:"parent_id,omitempty"`
	Content   string         `json:"content"`
	Metadata  map[string]any `json:"metadata,omitempty"`
}

Message is the unit routed through a taskmaster runtime.

func NormalizeMessage

func NormalizeMessage(msg Message) (Message, error)

NormalizeMessage validates and canonicalizes a message.

type Node

type Node interface {
	Run(ctx context.Context, msg Message, emit EmitFunc) Outcome
}

Node handles taskmaster messages.

type Outcome

type Outcome struct {
	Status   string
	Content  string
	Metadata map[string]any
	Err      error
}

Outcome describes the result of running a message through a node.

type OutcomeRouter

type OutcomeRouter func(msg Message, outcome Outcome) []Message

OutcomeRouter maps a completed message and outcome to follow-up messages.

type Runtime

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

Runtime coordinates taskmaster nodes, routing, and lifecycle.

func New

func New(cfg Config) (*Runtime, error)

New creates a taskmaster runtime from Config.

func (*Runtime) Done

func (r *Runtime) Done() <-chan struct{}

Done returns a channel closed when the runtime exits.

func (*Runtime) Enqueue

func (r *Runtime) Enqueue(msg Message) error

Enqueue adds a root message to the runtime.

func (*Runtime) Err

func (r *Runtime) Err() error

Err returns the runtime terminal error, if any.

func (*Runtime) Start

func (r *Runtime) Start(ctx context.Context) error

Start begins processing queued and emitted messages.

func (*Runtime) Stop

func (r *Runtime) Stop(ctx context.Context) error

Stop requests shutdown and waits for all running work to finish.

type Target

type Target interface {
	Supports(locator Locator) bool
	DispatchMessage(ctx context.Context, msg Message) error
}

Target dispatches messages to supported locators.

func NewCLILogTarget

func NewCLILogTarget(logger zerolog.Logger) Target

NewCLILogTarget constructs a target for the built-in CLI log locator.

Directories

Path Synopsis
Package adk wraps an already-built ADK agent for Taskmaster local execution.
Package adk wraps an already-built ADK agent for Taskmaster local execution.

Jump to

Keyboard shortcuts

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