task

package
v1.8.5 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package task runs work in the background as tasks the model can follow: each has an ID, a status and an output file, and a message announces it when it ends. The bash tool runs its background commands as tasks, the subagent tool its background agents; Runtime.Tools lets the model read and stop them.

Index

Constants

View Source
const KindNotification = "task_notification"

KindNotification marks the message announcing that a task ended.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	ID          string
	Type        Type
	Description string
	Status      Status
	StartedAt   time.Time
	EndedAt     time.Time
	// OutputFile is the file the task's output goes to.
	OutputFile string
	// Error is why a Failed task failed.
	Error string

	// A shell command.
	Command  string
	ExitCode int

	// A sub-agent.
	Agent     string
	Prompt    string
	Result    string // the agent's last response
	ToolCount int
	TokensIn  int
	TokensOut int
}

Entry is the state of a task.

type Runtime

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

Runtime runs and tracks tasks.

func NewRuntime

func NewRuntime(dir string, notify func(agentcore.Message)) *Runtime

NewRuntime returns a Runtime that writes the output of each task to a file in dir, the system's temporary directory if "", and hands notify the message announcing each task that ended; nil drops them.

func (*Runtime) Active added in v1.7.13

func (r *Runtime) Active() int

Active returns how many tasks have not ended, their announcement included.

func (*Runtime) Get

func (r *Runtime) Get(id string) (Entry, bool)

Get returns the entry of task id.

func (*Runtime) List

func (r *Runtime) List() []Entry

List returns the entries of all tasks, oldest first.

func (*Runtime) Start added in v1.8.5

func (r *Runtime) Start(ctx context.Context, e Entry, work func(ctx context.Context, t *Task) error) (Entry, error)

Start runs work as a new task, described by e: its Type, its Description and the fields of its type. It returns the task's entry at once; work runs on a goroutine of its own, with a context that keeps ctx's values but not its cancellation and is cancelled when the task is stopped. When work returns, the task ends: Killed if it was stopped, Failed if work failed, Completed otherwise; then notify hears of it.

func (*Runtime) Stop

func (r *Runtime) Stop(id string) bool

Stop stops task id, which ends Killed. It reports whether the task was running.

func (*Runtime) StopAll

func (r *Runtime) StopAll() int

StopAll stops every running task and returns how many it stopped.

func (*Runtime) Tools added in v1.8.5

func (r *Runtime) Tools() []agentcore.Tool

Tools returns the tools that let the model follow the tasks of r: task_output, which reports a task, once it ends if asked to wait, and task_stop, which stops one.

func (*Runtime) Wait added in v1.7.13

func (r *Runtime) Wait()

Wait returns once no task is active, counting those started while it waits, such as by a task of its own.

func (*Runtime) WaitFor added in v1.8.5

func (r *Runtime) WaitFor(ctx context.Context, id string) (Entry, error)

WaitFor returns the entry of task id once it ended and was announced, or ctx's error first.

type Status

type Status string

Status is where a task stands.

const (
	Running   Status = "running"
	Completed Status = "completed"
	Failed    Status = "failed"
	// Killed is a task stopped before it ended.
	Killed Status = "killed"
)

type Task added in v1.8.5

type Task struct {
	ID string
	// Output is the task's output file.
	Output io.Writer
	// contains filtered or unexported fields
}

Task is a task, as its work sees it.

func (*Task) Update added in v1.8.5

func (t *Task) Update(fn func(*Entry))

Update changes the task's entry as its work goes on, such as to count what it did. The Runtime sets the status when the task ends.

type Type

type Type string

Type is the kind of work a task does.

const (
	TypeShell    Type = "shell"
	TypeSubAgent Type = "subagent"
)

Jump to

Keyboard shortcuts

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