Skip to main content
You build Terminal Use agents with the Python runtime API. The public runtime surface is AgentServer, and it exposes three lifecycle hooks:
  • @server.on_create
  • @server.on_event
  • @server.on_cancel
There is no public on_complete hook.

Start With tu init

That creates an agent project with:

Minimal Agent

The Handler Model

on_create

Runs once when the task is created. Use it for:
  • initializing state
  • validating params
  • sending the first message

on_event

Runs every time your app sends an event to the task. This is where most agent logic lives.

on_cancel

Runs when the task is cancelled. Use it for cleanup or last-message behavior if needed. Important runtime detail: on_cancel does not run with the normal automatic filesystem sync wrapper. Do not rely on /workspace writes made in on_cancel being persisted automatically.

TaskContext

Every handler receives a TaskContext. TaskContext is the default path. The lower-level adk.* modules are still useful in helper code when you need to pass IDs explicitly.

Messages

The most common thing you do inside a handler is emit messages:
For structured output, send a typed part:

State

State is persisted per task and agent.
Use it for:
  • conversation continuity
  • IDs or handles you need on future turns
  • lightweight workflow progress

Filesystem Access

If the task has an attached filesystem, your agent sees it at /workspace. Terminal Use syncs that filesystem around on_create and on_event. If the caller only has read access to the filesystem, /workspace is mounted read-only for that task. on_cancel is the exception: the runtime skips the automatic sync wrapper for cancel handlers. See Filesystem Sync and Access Control.

TypeScript vs Python

The TypeScript SDK is for calling deployed agents and managing Terminal Use resources from your application. The public agent runtime shown on this page is Python.