Skip to main content
When does it go wrong? You wrote a loop by hand and it crashed on a tool the agent didn’t know about. Then it crashed again because an authority came back as a number instead of text.
Now your manager wants to know why the agent promised a refund. You delete the whole file out of frustration. The idea was right, but you spent a week plumbing and wiring code when you should have been writing an agent. This lesson rewinds and gets you started correctly. In about five minutes you’ll have a real agent in a real folder answering you in real time from a new terminal. That folder, my_agent, is the basis for every lesson that follows.
Overview: what you’ll do
  • Create a clean Python virtual environment (venv).
  • Install the ADK CLI package (google-adk).
  • Get a Gemini API key from Google AI Studio.
  • Keep that key out of source by using an environment variable.
  • Scaffold a starter agent with adk create my_agent.
  • Run and iterate on my_agent.
Create a virtual environment and install ADK ADK is a Python package. Use a virtual environment to avoid dependency conflicts with other projects on your machine.
Verify the ADK CLI is available:
Quick reference — common setup commands Choose a model and get an API key ADK is built to work with Gemini models. The fastest way to start is with a free API key from Google AI Studio. Sign in, click “Get API Key,” and copy the key string.
  • Recommended model: gemini-flash-latest — fast and cost-effective for most tasks.
  • Backend: Google AI Studio — paste your API key when prompted by the ADK CLI.
Important: do not hard-code API keys in source files Never paste your API key directly into source code. If you put the key into agent.py or any committed file, it can be accidentally published and abused.
Store the key in an environment variable named GOOGLE_API_KEY. ADK reads that environment variable automatically when your agent starts.
Never commit API keys or secrets to source control. Use environment variables or a secrets manager instead.
Tip: After exporting GOOGLE_API_KEY in your shell, ADK will automatically pick it up the next time you run adk run or any other ADK command in that shell session.
ADK is code-first Your agent is plain Python you can open, read, and edit — not a config file or a drag-and-drop canvas. That means you can version, test, and iterate using standard development workflows.
An infographic titled "Code First" showing two panels: one for Python with a code icon and buttons labeled "Open, Read, Edit," and another for "Config File or Canvas" with icons for config files and a canvas. Below them is a dark code editor window labeled "agent.py."
Scaffold a starter agent with the ADK CLI The ADK CLI can scaffold a starter agent for you. Run the create command and answer two prompts: which model and which backend.
  • When prompted, choose gemini-flash-latest as the model.
  • Choose Google AI Studio for the backend and paste your API key when asked.
Example interaction:
Files created by adk create my_agent Run your agent Now you have a working project folder (my_agent) with a scaffolded agent.py. Start it and iterate from there; every lesson will add features to this same agent so you build on prior work rather than starting over.
Links and references Next steps
  • Open my_agent/agent.py and run a simple query.
  • Add or register tools deliberately, validate inputs, and add robust error handling to avoid crashes like the one above.
  • Keep iterating: the agent is code-first, so make small, testable changes and use version control to avoid losing your work.

Watch Video