Lifecycle Hooks
The public Python runtime exposes three handlers:@server.on_create@server.on_event@server.on_cancel
on_complete hook.
Typical Flow
- Your app creates a task with
agent_nameoragent_id. - You optionally attach an existing filesystem with
filesystem_id, or ask TerminalUse to create one from aproject_id. - TerminalUse resolves the target version for the requested branch.
- The runtime calls
on_create. - Your app sends follow-up events and the runtime calls
on_event. - The agent emits messages and updates state.
- If the task is cancelled, the runtime calls
on_cancel.
What Lives On A Task
| Resource | Scope |
|---|---|
| Messages | Per task |
| Events | Per task |
| State | Per task and agent |
| System folders | Per task |
| Filesystem mount | Shared only if you attach the same filesystem |
Filesystem Behavior
If a task has a filesystem, TerminalUse syncs that filesystem into/workspace before on_create and on_event, and syncs changes back after those handlers complete.
on_cancel is different: the current runtime registers cancel handlers with sync disabled, so you should not rely on writing files in on_cancel and expecting those workspace changes to persist.
If the caller can run the task but does not have filesystem update permission, /workspace is mounted read-only. See Access Control.
TaskContext
TaskContext gives your handler pre-bound helpers for the current task:
ctx.taskctx.agentctx.messagesctx.statectx.events