Build Stateful Agentic Apps with the Gemini Interactions API

90 min remaining
Step 1 of 12•5 min

1. Overview

Traditional LLM integrations turn developers into state managers. You keep a growing history array, you persist it across services, and you write the glue that runs tools and feeds their results back. The Gemini Interactions API moves that state to the server. Each request creates an interaction with its own ID, and the next request continues from it with previous_interaction_id.

In this codelab you build an on-call agent for Orbital 7, an ageing space station that has just lost main power. The agent has to work out what is wrong from telemetry it cannot fully trust, recover from hardware that fails when it is used, spend limited coolant and power wisely, and decide when to hand over to a human. Nothing in the tools tells it the order of operations: it has to reason.

What you'll learn

  • Run a multi-step tool loop with client.interactions, typed function_call steps and function_result inputs matched by call ID.
  • Design tools that make a model reason: typed arguments, enums, limited resources and errors it can recover from.
  • Read the agent's thought summaries, and measure what each turn sends compared with what the model reads.
  • Get a machine-readable incident report with structured output, and check the agent's claims against ground truth.
  • Resume a session from a different process using only its interaction ID.
  • Branch a session from an earlier turn to test how the agent handles a different failure.
  • Apply production practices and know the trade-offs of server-side state.

What you'll need

  • A modern web browser.
  • A Google Account to create a free Gemini API key in Google AI Studio.
  • A Google Cloud project, used only to open Cloud Shell.
  • Intermediate Python: functions, dictionaries, classes and reading JSON.
No Billing Required

Billing does not need to be enabled. Cloud Shell is the coding environment, and the Interactions API traffic goes through Google AI Studio with your API key.

Workshop plan (90 minutes)

BlockTimeSteps
The Interactions API model10 minOverview, Understand the Interactions API
Setup10 minSet up your environment, project structure
Build the agent25 minStation simulator, tools, agent loop, first run
Trust, but verify10 minStructured incident report, scenarios 2 and 3
State in action25 minMeasure, resume from a new process, branch the timeline
Production and wrap-up10 minProduction practices, trade-offs, clean up