Build Stateful Agentic Apps with the Gemini Interactions API

Step 1 of 12•5 min read & hands-on

1. Overview

In this step

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 and Google Cloud project, used only to open Cloud Shell (no billing required on your project).
  • A Gemini API key:
    • At a live workshop: Provided by your facilitator, you do not need to open Google AI Studio or set up billing.
    • Self-paced: Create a key in Google AI Studio (gemini-3.8-flash is available on the Free Tier for individual use, or via a Paid Tier project with a minimum $5 Prepay credit balance).
  • Intermediate Python: functions, dictionaries, classes and reading JSON.
No Billing Required on Your Cloud Project

Billing does not need to be enabled on your Google Cloud project. Cloud Shell is only the coding environment, and all Interactions API requests authenticate directly with the Gemini API key. At the live workshop, use the key provided by your facilitator.

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