Why it matters

Agents that skip lifecycle steps leak resources, lose state, and behave unpredictably. Getting the pattern right is foundational.

Advertisement

The architecture

Init phase: construct Agent instance with tools, model reference, and configuration. Connect to LLM (auth, endpoint). Initialize memory/session backends.

Turn phase: receive user message, add to session context, invoke model, dispatch tool calls, receive tool results, feed back to model, produce final response.

Agent lifecycle phasesInittools + modelTurn loopmessage → responseShutdownflush + releaseTurn loop may iterate multiple times if agent needs multiple tool calls before responding
ADK Java lifecycle stages.
Advertisement

How it works end to end

Runner is the orchestrator. It receives user messages, calls the agent, handles tool dispatch, and streams responses back. Runner manages the loop and error handling.

Callbacks and interceptors let you observe or modify agent behavior at each lifecycle step: log tool calls, add rate limiting, insert human approval.

Shutdown: flush session state, close model connections, release tool resources. Missing shutdown can leak memory or corrupt state.