task

package
v0.2.0-alpha.8 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInputRequired         = apierr.New(apierr.KindInvalid, "input required")
	ErrAgentsNotConfigured   = apierr.New(apierr.KindNotConfigured, "agents not configured")
	ErrTasksNotConfigured    = apierr.New(apierr.KindNotConfigured, "tasks not configured")
	ErrTaskRunsNotConfigured = apierr.New(apierr.KindNotConfigured, "task runs not configured")
	ErrAgentNotFound         = apierr.New(apierr.KindInvalid, "agent not found")
	ErrTaskNotFound          = apierr.New(apierr.KindNotFound, "task not found")
	// ErrNoRunToRetry means the task has no finished run to repeat: it has
	// never run, or its only run is still in flight.
	ErrNoRunToRetry = apierr.New(apierr.KindConflict, "this task has no finished run to retry")
	// ErrRetryOfWorkflowStep means the task belongs to a workflow step. The
	// workflow owns that task's lifecycle — it reacts to the step run's
	// outcome — so a run started behind its back would mark a settled step
	// succeeded and dispatch the next step of a workflow run that is already
	// over.
	ErrRetryOfWorkflowStep = apierr.New(apierr.KindConflict, "this run belongs to a workflow step and cannot be retried on its own")
)

Functions

This section is empty.

Types

type CreateRunCmd

type CreateRunCmd struct {
	UserID        string
	TaskID        string
	Input         string
	CreatedByType string
	TriggerSource string
	// RetryOfTaskRunID names the run this one repeats, when it repeats one.
	RetryOfTaskRunID *string
	// SourceMessageID names the conversation message that asked for this run.
	SourceMessageID *string
	// IdempotencyKey is the caller's dedup key for this Continue request. A
	// repeat with the same key on the same task returns the run the first call
	// created instead of starting a second one.
	IdempotencyKey *string
}

CreateRunCmd creates a new run on an existing task.

type CreateTaskCmd

type CreateTaskCmd struct {
	ConversationID string
	UserID         string
	SpaceID        string
	Input          string
	AgentID        *string
	IssueID        *string
	CreatedByType  string
	TriggerSource  string
	// SourceMessageID names the conversation message that asked for this task.
	SourceMessageID *string
}

CreateTaskCmd creates a new task and its first run.

type QuotaChecker

type QuotaChecker interface {
	Check(ctx context.Context, spaceID string, runsToAdd, tokensToAdd int) (allowed bool, reason string, err error)
}

QuotaChecker is the narrow quota surface needed by task workflows.

type RetryResult

type RetryResult struct {
	Run        *coretask.Run
	RetriedRun coretask.Run
}

RetryResult reports the new run and the one it repeats.

type RetryRunCmd

type RetryRunCmd struct {
	UserID string
	TaskID string
}

RetryRunCmd repeats a task's most recent run.

type Service

type Service struct {
	Agents         agentdef.Store
	Tasks          coretask.Store
	TaskRuns       coretask.RunStore
	QuotaChecker   QuotaChecker
	TitleGenerator llm.TitleGenerator
	// WorkflowSteps is only consulted by RetryRun. Callers that never retry
	// leave it nil.
	WorkflowSteps WorkflowStepLookup
}

Service owns task-related application workflows.

func (*Service) Admits

func (s *Service) Admits(ctx context.Context, spaceID string) error

Admits reports whether the space can start one more run right now, before a caller writes anything a refusal would strand.

CreateTask checks the same allowance, but only after resolving a title -- which is a model call -- and only once it has been handed a conversation to hang the task on. An orchestrator that creates that conversation first and asks afterwards leaves one behind on every refusal, and nothing deletes a conversation. This is the question worth asking before the first write.

It asks about the run allowance alone. The token half depends on the title the model has not written yet, so CreateTask still checks it and can still refuse; what this closes is the case a space hits routinely, which is running out of runs.

func (*Service) CreateRun

func (s *Service) CreateRun(ctx context.Context, cmd CreateRunCmd) (*coretask.Run, error)

CreateRun enforces basic run creation rules and delegates to TaskRunStore.

func (*Service) CreateTask

func (s *Service) CreateTask(ctx context.Context, cmd CreateTaskCmd) (*coretask.Task, error)

CreateTask resolves input, applies title/quota rules, and persists a new task.

func (*Service) RetryRun

func (s *Service) RetryRun(ctx context.Context, cmd RetryRunCmd) (*RetryResult, error)

RetryRun repeats a task's most recent run with the same input.

The input comes from the run rather than the task because a task's later runs can carry follow-up instructions, and retrying means running that again — not running whatever the task was first asked to do.

A run still in flight is not retried: one task holds at most one active run, and the answer to "it is taking too long" is to stop it first.

func (*Service) StartBackgroundTask

func (s *Service) StartBackgroundTask(ctx context.Context, cmd CreateTaskCmd) (*StartBackgroundTaskResult, error)

StartBackgroundTask creates a task and returns its task/run ids.

type StartBackgroundTaskResult

type StartBackgroundTaskResult struct {
	TaskID string
	RunID  string
}

StartBackgroundTaskResult is returned when a background task is created.

type WorkflowStepLookup

type WorkflowStepLookup interface {
	GetWorkflowStepRunByTaskID(ctx context.Context, taskID string) (*coreworkflow.StepRun, error)
}

WorkflowStepLookup answers whether a task is a workflow step's task. It is optional: a deployment with no workflow store has no workflow steps, so a nil lookup means nothing to protect rather than an unanswered question.

Jump to

Keyboard shortcuts

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