Skip to content
Blog

Running ADK Headless: CLI Streaming and Non-Interactive Batch Modes

Run Google ADK with no browser: adk run one-shot queries, --replay batch files, --jsonl output, CI timeouts, and token-level SSE through the adk api_server /run_sse endpoint.

Published on • November 24, 2026

AI Assistant

The adk web Dev UI is wonderful for clicking through a conversation, but it is explicitly documented as development only — not for production. Real pipelines need the same agents running without a TTY: smoke tests in CI, nightly batch jobs over a file of queries, and HTTP endpoints that stream tokens to a service that has no browser attached.

Google’s Agent Development Kit ships three headless surfaces for exactly that: adk run for terminal and scripted use, adk api_server for REST and Server-Sent Events, and adk eval for grading runs against a dataset. This post walks through each one with the concrete flags, request shapes, and failure modes you will hit in automation.

Choose the right headless surface

CommandBest forOutput style
adk runCI smoke tests, scripted one-shots, terminal replayHuman-readable text or --jsonl
adk api_serverServices, dashboards, token streaming over HTTPJSON arrays (/run) or SSE (/run_sse)
adk evalGrading agent behavior against an eval setEval reports per criterion
agents-cliScaffolding, deploying, and evaluating agents from a coding agentCLI + skill-driven

One-shot queries with adk run

Without arguments, adk run my_agent starts an interactive session (Running agent my_agent, type exit to exit.) that you leave with Ctrl+C or EOF (Ctrl+D). For automation, pass the query as an argument and the process sends the message and exits:

# Interactive
adk run my_agent

# One-shot: single message, then exit
adk run path/to/my_agent "hello"

# One-shot with structured output for a pipeline
adk run --jsonl --timeout 90s path/to/my_agent "hello"

That single-query form is the cheapest possible CI check: create a temp directory, run the agent folder with a known prompt, assert on stdout, delete the directory.

Batch runs with --replay

--replay runs a session file without any interactive input — this is the batch mode:

adk run --replay fixtures/smoke.input.json path/to/my_agent

The input file carries the initial state and the queries to execute in order:

{
  "state": {"key": "value"},
  "queries": ["What is 2 + 2?", "What is the capital of France?"]
}

Companion session flags let you checkpoint between runs: --save_session --session_id my_session writes path/to/my_agent/<session_id>.session.json on exit (without --session_id it prompts for one), and adk run --resume path/to/my_agent/my_session.session.json path/to/my_agent reloads state plus event history before continuing.

Flags that make adk run CI-safe

OptionDescription
--replayPath to an input file for non-interactive replay
--stateInitial state for the run as a JSON string
--timeoutTimeout for a single turn or query, e.g. 30s or 5m
--jsonlOutput structured JSONL instead of human-readable text
--in_memoryDo not persist session data
--session_service_uriCustom session storage URI
--artifact_service_uriCustom artifact storage URI
--default_llm_modelDefault model when the agent does not set one
--use_local_storage/--no_use_local_storageUse the local .adk folder when no service URI is set

Defaults are already pipeline-friendly: sessions go to per-agent SQLite at <agents_dir>/<agent>/.adk/session.db and artifacts to <agents_dir>/<agent>/.adk/artifacts, so nothing escapes the workspace unless you point a URI elsewhere. Pair --timeout with --in_memory in throwaway jobs to guarantee the run leaves no residue.

Streaming without a browser: /run vs /run_sse

adk api_server (default http://localhost:8000) exposes two execution routes. POST /run collects every event and returns them as one JSON array when the turn finishes; POST /run_sse returns Server-Sent Events as they are produced, and setting streaming: true enables token-level streaming.

# Create a session first
curl -X POST http://localhost:8000/apps/my_sample_agent/users/u_123/sessions/s_123 \
  -H "Content-Type: application/json" -d '{"env": "staging"}'

# Stream the turn as SSE with token-level chunks
curl -X POST http://localhost:8000/run_sse \
  -H "Content-Type: application/json" \
  -d '{"appName":"my_sample_agent","userId":"u_123","sessionId":"s_123",
       "newMessage":{"role":"user","parts":[{"text":"Hey whats the weather in new york today"}]},
       "streaming": true}'

Each data: line is a complete event object, so your consumer parses one JSON shape whether the event is a tool call, a partial text chunk, or the final response. Request and response bodies use camelCase field names (appName, userId, sessionId). Interactive Swagger docs live at /docs on the Python and TypeScript servers.

Prefer /run when you just need the answer; prefer /run_sse when a human or a downstream service should watch progress — the same trade-off covered in streaming-inference-fastapi-sse.md.

Scaffolding and evaluating in the pipeline

The companion agents-cli project turns a coding assistant into an ADK pipeline operator: uvx google-agents-cli setup installs the CLI plus skills, agents-cli create <name> -y scaffolds a new agent project (default adk_python template, agent_runtime target), agents-cli eval run runs an eval dataset and grades the traces, and agents-cli deploy ships to Google Cloud. The framework-side equivalent is the bundled evaluator:

adk eval \
    contributing/samples/evaluation/home_automation_agent \
    contributing/samples/evaluation/basic_criteria/home_automation.evalset.json \
    --config_file_path contributing/samples/evaluation/basic_criteria/eval_config.json

Pitfalls

  • Duplicate sessions fail. Reusing a user_id + session_id that already exists returns {"detail":"Session already exists: s_123"} — delete it or generate a unique ID per job.
  • --replay has its own schema. A flat list of strings will not work; the file must be an object with state and queries.
  • The Go console is a different CLI. It does not support --save_session, --resume, --replay, or the service-URI flags; instead it auto-detects stream mode (-streaming_mode is sse on a TTY, none when piped) and you can force it: go run agent.go console -streaming_mode none.
  • Telemetry is off by default, but if a runner image enables it, manage it with adk telemetry enable|disable|status or ~/.adk/config.json.
  • SSE output is still events, not deltas. The streaming: true flag changes chunk granularity; you still accumulate partial text client-side (see streaming-tool-results-agent-loop.md).

Takeaway: Headless ADK is not a stripped-down mode — adk run --replay plus --jsonl and --timeout gives you deterministic batch runs for CI, while adk api_server’s /run and /run_sse (with streaming: true) cover everything from synchronous scripts to token-level streams, and the same session, storage, and telemetry controls you use interactively apply unchanged, so the only real discipline is scripting around session-ID uniqueness and the replay file’s state/queries shape.

Sources