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
- type Entry
- type Runtime
- func (r *Runtime) Active() int
- func (r *Runtime) Get(id string) (Entry, bool)
- func (r *Runtime) List() []Entry
- func (r *Runtime) Start(ctx context.Context, e Entry, work func(ctx context.Context, t *Task) error) (Entry, error)
- func (r *Runtime) Stop(id string) bool
- func (r *Runtime) StopAll() int
- func (r *Runtime) Tools() []agentcore.Tool
- func (r *Runtime) Wait()
- func (r *Runtime) WaitFor(ctx context.Context, id string) (Entry, error)
- type Status
- type Task
- type Type
Constants ¶
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
Run string // the run's Spawn.ID, as "explore#3"
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 ¶
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
Active returns how many tasks have not ended, their announcement included.
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 ¶
Stop stops task id, which ends Killed. It reports whether the task was running.
func (*Runtime) Tools ¶ added in v1.8.5
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.