Introduction to Agent Development Kit (ADK)

As modern cross-platform applications evolve, integrating intelligent AI agents has become a core requirement for enterprise mobile and web applications. Google's Agent Development Kit (ADK) provides a structured environment for building, running, and managing intelligent agents powered by Large Language Models (LLMs) such as Gemini. Knowing how to setup ADK properly ensures that your backend orchestration remains scalable, secure, and ready to serve client applications like Flutter.

In this developer guide, we will walk through installing Python and the ADK dependencies, configuring API credentials for both Gemini API and Vertex AI, setting up a clean backend project structure, and integrating the resulting service with a Flutter client.

Note: While ADK execution engines typically run in Python-based environments for backend orchestration, Flutter apps interact seamlessly with these agents via lightweight API bridge layers.

Step 1: Installing Python and ADK Dependencies

Before initializing an ADK project, ensure that Python 3.10 or higher is installed on your local development machine. Isolating your dependencies within a virtual environment prevents package conflicts.

Creating a Virtual Environment

Execute the following commands in your terminal to set up a dedicated directory and virtual environment:

Code
# Create directory for your ADK project
mkdir adk_flutter_backend
cd adk_flutter_backend
# Create virtual environment
python3 -m venv venv
# Activate virtual environment (Linux/macOS)
source venv/bin/activate
# Activate virtual environment (Windows)
# venv\Scripts\activate

Installing the Package

With the virtual environment active, install the core Google Gen AI ADK runtime and web server framework:

Code
pip install google-genai fastapi uvicorn pydantic python-dotenv

Step 2: Configuring Gemini or Vertex AI Credentials

ADK supports authentication through either Google AI Studio (using a standard API key) or Google Cloud Vertex AI (using Enterprise IAM and Service Accounts). Choose the authentication path appropriate for your environment.

Option A: Gemini API Key (Google AI Studio)

Create a file named .env in your root project folder and supply your API key obtained from Google AI Studio:

Code
GEMINI_API_KEY="your_gemini_api_key_here"

Option B: Vertex AI Credentials (Google Cloud)

For production deployments on Google Cloud Platform, set up Application Default Credentials (ADC) by pointing to your downloaded Service Account JSON key:

Code
GOOGLE_APPLICATION_CREDENTIALS="/path/to/service_account.json"
GCP_PROJECT_ID="your-gcp-project-id"
GCP_LOCATION="us-central1"

Security Tip: Never commit your .env file or service_account.json file to version control. Add them to your .gitignore file immediately.

Step 3: Creating the Basic ADK Project Structure

To keep your ADK agent clean and maintainable, adopt a modular folder structure separating agent logic, custom tools, and API controllers:

Code
adk_flutter_backend/
│── .env
│── requirements.txt
│── main.py
└── agent/
    ├── __init__.py
    ├── config.py
    └── tools.py

Defining Agent Configurations in Python

Below is a minimal, working implementation of an ADK setup in main.py using FastAPI to expose the agent endpoint to external consumers like Flutter:

Code
import os
from dotenv import load_dotenv
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from google import genai

load_dotenv()

app = FastAPI(title="ADK Backend for Flutter")

# Initialize Gemini Client
client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))

class PromptRequest(BaseModel):
    prompt: str

class AgentResponse(BaseModel):
    reply: str

@app.post("/api/agent", response_model=AgentResponse)
async def run_agent(request: PromptRequest):
    try:
        response = client.models.generate_content(
            model='gemini-2.5-flash',
            contents=request.prompt,
        )
        return AgentResponse(reply=response.text)
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8080)

Step 4: Connecting the ADK Agent Backend to Flutter

With the backend agent configured and listening on port 8080, you can now connect your Flutter application. We will use the official http package to send user requests to our ADK agent endpoint.

Adding Flutter Dependencies

Add the HTTP package to your Flutter project's pubspec.yaml:

Code
dependencies:
  flutter:
    sdk: flutter
  http: ^1.2.0

Dart Implementation for ADK Service

Below is a syntactically correct, production-ready Dart service class designed to call your local or remote ADK backend:

Code
import 'dart:convert';
import 'package:http/http.dart' as http;

class AdkAgentService {
  final String baseUrl;

  AdkAgentService({required this.baseUrl});

  Future queryAgent(String userPrompt) async {
    final uri = Uri.parse('$baseUrl/api/agent');

    try {
      final response = await http.post(
        uri,
        headers: {
          'Content-Type': 'application/json',
        },
        body: jsonEncode({
          'prompt': userPrompt,
        }),
      );

      if (response.statusCode == 200) {
        final Map data = jsonDecode(response.body);
        return data['reply'] as String? ?? 'No response text received.';
      } else {
        throw Exception('Agent error (${response.statusCode}): ${response.body}');
      }
    } catch (e) {
      throw Exception('Failed to communicate with ADK service: $e');
    }
  }
}

Consuming the ADK Service in a Flutter Widget

Here is how to integrate the service within a simple Flutter UI component:

Dart / Flutter
import 'package:flutter/material.dart';

class AgentChatScreen extends StatefulWidget {
  const AgentChatScreen({Key? key}) : super(key: key);

  @override
  State createState() => _AgentChatScreenState();
}

class _AgentChatScreenState extends State {
  final TextEditingController _controller = TextEditingController();
  final AdkAgentService _adkService = AdkAgentService(baseUrl: 'http://10.0.2.2:8080');
  String _response = '';
  bool _isLoading = false;

  Future _sendPrompt() async {
    if (_controller.text.trim().isEmpty) return;

    setState(() {
      _isLoading = true;
      _response = '';
    });

    try {
      final result = await _adkService.queryAgent(_controller.text.trim());
      setState(() {
        _response = result;
      });
    } catch (error) {
      setState(() {
        _response = 'Error: ${error.toString()}';
      });
    } finally {
      setState(() {
        _isLoading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('ADK Flutter Agent')),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: [
            TextField(
              controller: _controller,
              decoration: const InputDecoration(
                labelText: 'Enter prompt for ADK Agent',
                border: OutlineInputBorder(),
              ),
            ),
            const SizedBox(height: 12),
            ElevatedButton(
              onPressed: _isLoading ? null : _sendPrompt,
              child: _isLoading
                  ? const CircularProgressIndicator()
                  : const Text('Send to Agent'),
            ),
            const SizedBox(height: 24),
            Expanded(
              child: SingleChildScrollView(
                child: Text(
                  _response,
                  style: const TextStyle(fontSize: 16),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Summary & Best Practices

Understanding how to setup ADK lays the groundwork for creating scalable AI agents in multi-platform applications. When organizing your project for production:

  • Keep API credentials secure: Never expose your Gemini or Vertex AI API keys inside your client-side Flutter code. Always route requests through your secure ADK backend.
  • Use proper host aliases: When testing locally with the Android Emulator, use http://10.0.2.2:8080 to refer to your host computer's localhost.
  • Modularize Agent Tools: Maintain separate Python modules inside your ADK project for enterprise tools, database lookups, and third-party API integrations.

Frequently Asked Questions

What is ADK in the context of Google Gen AI?

ADK (Agent Development Kit) is a framework that enables developers to build, orchestrate, and deploy AI agents powered by models like Gemini on Vertex AI or Google AI Studio.

What is the difference between setting up Gemini API vs Vertex AI credentials in ADK?

Gemini API uses a simple API key set via environment variables (e.g., GEMINI_API_KEY). Vertex AI requires Google Cloud Application Default Credentials (ADC) using service account keys along with a project ID and location.

How do Flutter applications communicate with an ADK backend?

Flutter applications communicate with ADK backends using standard HTTP REST endpoints or WebSockets served by a Python middleware framework like FastAPI or Flask hosting the ADK agent.