Tutorial — Tasks
A task is a unit of work that viff governs. An agent or a script does the work, on a runner. You can watch a task, tell it something while it runs, and stop it. A task asks a question before it does what it may not do alone. What it says last is its answer.
This page needs a viff instance running. The runs that go to an agent need a model
key, and every other run here is a script. Every run on the page helps triage one bug report
from the users of acme/app: the login page fails after a password reset.
Run one
A run is a spawn, written as a charter writes one, in a file or on
stdin. viff up’s runner builds only the host’s network, and a spawn that names no network has
none, so each spawn here names it:
echo '{script: "echo reproducing the login failure; sleep 30; echo reproduced", environment: {systems: {network: {mode: open}}}}' | viff task run -f - # prints a run-… id viff task # every task, and its status viff task get <id> # status, prompt, agent, runner, result, pending gates viff task cancel <id> # end it before it finishes echo '{script: "echo reproduced", environment: {systems: {network: {mode: open}}}}' | viff task run -f - --wait # …or block until the result
A script runs as a shell script. With a model key configured, a spawn with a prompt gives
your sentence to an agent instead (the local runner):
echo '{prompt: "Summarize this bug report in one line: the login page fails after a password reset.", environment: {systems: {network: {mode: open}}}}' | viff task run -f - viff task say <id> "also say which browser it fails in" # new instructions, while it runs viff task autonomy <id> --file autonomy.tony # new rows, from a file you write
An agent’s run takes two more verbs. say gives the agent new instructions. autonomy replaces
the task’s autonomy, which says what it does unasked, at the task’s next boundary. The file
holds a list of rows, which the next section describes.
The environment and the autonomy
A task stops at each step: writing a file, running a command, pushing, calling a sub-agent. Two parts of the spawn decide them.
- Its environment says what the task may do at all: each system it names, with the verbs it
gives. A step outside it is refused, and nobody is asked.
files: {write: {}}gives file writes;files: {}, a block naming no verb, gives every verb offiles. - Its autonomy says, among those, what happens at each: a list of rows, the first that
matches a step deciding it,
allow,askordeny. With no autonomy every step is asked about, so the last row, the default, is the one place a run is made unattended.
One system is viff itself. A spawn that gives viff lets the task raise asks, read and write
data, and read and install charters, as the person it runs for and only while it runs. It needs
a runner that reaches viff with a token of its own (the viff system).
A script you wrote is one action and no step: it runs, because you wrote it. An agent chooses its steps, so it has only the ones its environment gives; given none, it reads, and answers. This one may write files, and asks first:
cat > write.tony <<'END' prompt: 'Write the file triage.txt with a one-line summary of this bug report: the login page fails after a password reset.' environment: systems: network: {mode: open} files: {write: {}} autonomy: - match: {system: files} then: ask - then: deny END viff task run -f write.tony viff question # - gate: autonomy[0] # id: run-f3e31ed0390f~d1 # step: files.write # tool: write_file viff question approve run-f3e31ed0390f~d1 --as you@example.com
The row names nobody to answer, so the question is on the docket, and anyone who may answer it can. Here that is you.
autonomy[0] is the row that decided. The last row, then: deny, is the default: it decides
whatever no row above matched. The network is a system too, and mode: open gives the task the
host’s network, the only one viff up builds.
To have the task ask about one kind of step, write a row for it. This spawn gives the task the shell, asks before each command, and gives the question ten minutes:
cat > shell.tony <<'END' prompt: 'Run `date -u` and say what it printed: the time this report is triaged.' environment: systems: network: {mode: open} commands: {} autonomy: - name: shell match: {system: commands, verb: run} then: {ask: {within: "10m", default: deny}} - then: allow END viff task run -f shell.tony # run-4e919ce01f99 viff question # - gate: shell # id: run-4e919ce01f99~d1 # step: commands.run # tool: run_bash # … viff question approve run-4e919ce01f99~d1 --as you@example.com # the command runs viff task get run-4e919ce01f99 # status: done
The question is an ask like the ones on the questions page. It is on the same docket, and you answer it the same way. If nobody answers in ten minutes, the answer is no: the command never runs, and the agent hears the refusal and plans again.
run --attach streams the transcript and asks you in the terminal. Anyone the gate waits on can
answer it from anywhere by its id; anyone who may read the task can watch it, and anyone who holds
control over it can steer it: in a shared viff that is the team, not only whoever started the run.
The autonomy has the rows in full.
The answer
What a task says last is its answer: a script’s output, or an agent’s final message. viff task get shows it as result. An agent answers in words. When something will read the answer as
data, give the run an answer contract: the shape its final message must have.
cat > triage.tony <<'END' prompt: "Is 'the login page fails' a bug or a feature, and how severe is it?" environment: {systems: {network: {mode: open}}} answer: kind: !or [bug, feature] severity: !or [low, normal, high] END viff task run -f triage.tony
Viff tells the agent the contract when it starts, and checks the answer when it stops. An answer that does not fit goes back to the agent with what was wrong. If the answer never fits, the task fails. A script cannot be asked again, so viff refuses a contract on a script (the answer contract). The contract matters most in a charter, where a rule reads the answer’s fields.
A task is data
Viff writes every task into the store as data at mirror.task.instance.<id>. So to watch tasks,
you watch data:
viff watch mirror task instance '*' # every task, as it changes viff data mirror task instance '*' -trim '{status}' # …or just the status of each
The end of a task is a change to data, so a rule can react to it. A flow of several steps continues this way: through the store.
Steering
Two acts stop work without ending it. A hold stops one run at its next boundary. A suspension stops the work about a charter and a subject. This page has runs only, so here is the hold:
echo '{script: "echo reproducing the login failure; sleep 30; echo reproduced", environment: {systems: {network: {mode: open}}}}' | viff task run -f - # run-… viff flow # the live tasks, and what is suspended viff flow suspend -task <id> # hold that run at its next boundary viff flow resume -task <id> viff flow cancel -task <id> # end that run (destructive)
A flow is a query over live tasks, so viff flow lists nothing when
nothing runs. A task can also run on a remote viff, or on a runner you install, and the same
verbs steer it (runners-walk.md). Control has the
flags. Next, charters.