agenttask

package
v0.0.0-...-820128f Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package agenttask owns durable asynchronous agent execution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventSink

type EventSink func(context.Context, string, any) error

EventSink persists observable task progress.

type Options

type Options struct {
	Tasks      *database.TaskRepository
	AgentTasks *database.AgentTaskRepository
	Workflows  *database.WorkflowRepository
	Runner     Runner
	Logger     *slog.Logger
	Timeout    time.Duration

	Concurrency        int
	SessionConcurrency int
	QueueCapacity      int
}

Options configures the task service.

type Result

type Result struct {
	Text      string
	UsageJSON string
}

Result is the terminal output of an agent run.

type Runner

type Runner interface {
	Run(context.Context, *database.AgentTaskEntity, EventSink) (Result, error)
}

Runner executes one persisted agent task.

type RuntimeRunner

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

RuntimeRunner executes durable tasks through the shared assistant runtime.

func NewRuntimeRunner

func NewRuntimeRunner(
	runtime *assistant.Runtime,
	catalog *agent.Catalog,
	sessions *database.SessionRepository,
) (*RuntimeRunner, error)

NewRuntimeRunner creates an assistant runtime adapter for durable agent tasks.

func (*RuntimeRunner) Run

func (runner *RuntimeRunner) Run(
	ctx context.Context,
	task *database.AgentTaskEntity,
	sink EventSink,
) (Result, error)

Run executes one task using the persisted agent definition and child session.

type Service

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

Service schedules and owns durable agent tasks.

func New

func New(ctx context.Context, options *Options) (*Service, error)

New creates and starts a task service.

func NewStopped

func NewStopped(ctx context.Context, options *Options) (*Service, error)

NewStopped creates a task service without starting its workers.

func (*Service) Await

func (service *Service) Await(ctx context.Context, taskID string) (*database.AgentTaskEntity, error)

Await waits until a task is terminal or the caller context ends.

func (*Service) Cancel

func (service *Service) Cancel(
	ctx context.Context,
	ownerSessionID string,
	taskID string,
	source string,
) (*database.TaskEntity, bool, error)

Cancel requests cancellation without allowing terminal states to change. The source records who requested cancellation for durable provenance.

func (*Service) Events

func (service *Service) Events(
	ctx context.Context,
	taskID string,
	after int64,
	limit int,
) ([]database.TaskEventEntity, error)

Events returns durable task events after the requested sequence.

func (*Service) Get

func (service *Service) Get(ctx context.Context, taskID string) (*database.AgentTaskEntity, bool, error)

Get returns an agent task by ID.

func (*Service) List

func (service *Service) List(
	ctx context.Context,
	ownerSessionID string,
	limit int,
) ([]database.AgentTaskEntity, error)

List returns tasks owned by a session.

func (*Service) Shutdown

func (service *Service) Shutdown(ctx context.Context) error

Shutdown cancels active work and waits for all workers.

func (*Service) Start

func (service *Service) Start(ctx context.Context) error

Start launches workers and queues recovered tasks.

func (*Service) Submit

func (service *Service) Submit(ctx context.Context, request *SubmitRequest) (*database.AgentTaskEntity, error)

Submit durably accepts a task before making it available to workers.

func (*Service) SubmitAgentTask

func (service *Service) SubmitAgentTask(
	ctx context.Context,
	request *assistant.AgentTaskRequest,
) (*database.AgentTaskEntity, error)

SubmitAgentTask adapts the assistant tool boundary to the durable scheduler.

func (*Service) Subscribe

func (service *Service) Subscribe(taskID string) Subscription

Subscribe follows newly persisted events for a task. Delivery is bounded and best-effort; callers recover gaps using Events and the event sequence.

func (*Service) SubscribeAgentTask

func (service *Service) SubscribeAgentTask(
	taskID string,
) (events <-chan database.TaskEventEntity, cancel func(), err error)

SubscribeAgentTask exposes task completion notifications through the assistant boundary.

type SubmitRequest

type SubmitRequest struct {
	ParentTaskID   string
	OwnerSessionID string
	ChildSessionID string
	ConcurrencyKey string
	AgentName      string
	Prompt         string
	Model          string
	Provider       string
	PolicyJSON     string
	Depth          int
}

SubmitRequest describes a durable agent task.

type Subscription

type Subscription struct {
	Events <-chan database.TaskEventEntity
	Cancel func()
}

Subscription delivers best-effort live events. Durable replay remains available through Events when a subscriber falls behind.

Jump to

Keyboard shortcuts

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