Vibe coding and context engineering with ADK
By Google for Developers
Key Concepts
- Vibe Coding: Instructing an AI to develop a project based on natural language descriptions and desired "vibe."
- Context Engineering: Providing an AI agent with additional context through documents to improve its understanding and development of features, removing guesswork.
- Token Optimization: Reducing the size of the "briefing packet" for an AI agent by focusing on the most necessary documents and information to complete a task efficiently.
- Gemini CLI: A command-line interface tool for interacting with Gemini AI models, enabling code generation and agent development.
- ADK (Agent Development Kit): A framework or set of tools used for building AI agents.
- Cloud Run: A managed compute platform that allows for the deployment of containerized applications.
- RAG (Retrieval-Augmented Generation): A technique that combines retrieval of relevant information with generative AI models.
- Vector Databases: Databases optimized for storing and querying high-dimensional data, often used in RAG.
- PRD (Product Requirements Document): A document outlining the requirements and specifications for a product or feature.
Building an AI Agent with Vibe Coding, Context Engineering, and Token Optimization
This summary details a demonstration of building and deploying an AI agent for expense tracking using Gemini CLI, without writing any code. The process leverages three core techniques: Vibe Coding for initial development, Context Engineering for enhancing code quality, and Token Optimization for efficiency. The agent is then deployed to Cloud Run.
1. Vibe Coding: Initial Agent Development
The demonstration begins with a blank slate in VS Code. The first step is to install the Gemini CLI extension.
Process:
- Install Gemini CLI Extension: Search for "Gemini CLI" in the VS Code extensions tab and install it.
- Initialize Gemini CLI: Open the command panel (Ctrl+Shift+P or Cmd+Shift+P), type "Gemini CLI," and select "Run Gemini CLI." Log in with a Google account if prompted.
- Acquire ADK Documentation: To provide the AI with context on ADK, all its documentation is fetched into a single file named
LLM's_full.txtusing the command:curl https://raw.githubusercontent.com/google/generative-ai-docs/main/docs/examples/LLM's_full.txt -o LLM's_full.txt. This file serves as a consolidated "briefing packet" for the AI. - Initiate Agent Creation (Vibe Coding): A prompt is given to Gemini CLI to create an expense tracking agent using Python and ADK. Key instructions include:
- Using
uvfor package management. - Consolidating functionality into a
tools.pyfile. - Separating the ADK agent into its own file.
- Crucially, referencing the
LLM's_full.txtfile for best practices and ADK knowledge. - The prompt includes a request to "create a simple implementation plan using Python ADK."
- Using
- Plan Review and Execution: Gemini CLI generates an implementation plan (Project Setup, Dependencies, Agent Tool Implementation, Testing). The user approves the plan and instructs Gemini CLI to "proceed with the implementations," again referencing
LLM's_full.txt. - Permission Management: Gemini CLI prompts for permission to execute actions like running
uvfor package management. Users can choose to allow once, always, or suggest changes. "Allow always" is selected for a smoother process. - Code Generation and Debugging: Gemini CLI generates code, including a
main.pyfile with anExpenseclass, anadd_expensefunction, and the agent itself with an attached tool.- Debugging Example: An error occurs where
main.pyhas the correct idea but misses a final update. The user prompts Gemini CLI to fix this by pointing to the file. - Refinement: The generated tool is moved to its own
tools.pyfile, and the data class tomodels.pyfor better organization. - Dependency Management:
uv add google-adis used to add a dependency topyproject.toml.
- Debugging Example: An error occurs where
- Project Structuring:
- A new directory
expense_trackeris created, andmain.py,models.py, andtools.pyare moved into it. - An
.envfile is created with environment variables for deployment (e.g.,VERTEX_AI_PROJECT_ID,VERTEX_AI_LOCATION). This is for authentication with the model, specifically mentioningGemini 2.5 Flashand Vertex AI. The flexibility to use API keys from Google AI Studio is also noted. - The main agent file is renamed from
main.pytoagent.py.
- A new directory
- Local Testing with ADK Web:
- The command
uv run adk webis used to run the ADK agent locally. - Debugging Example: An initial error "no module named tools" is encountered. This is resolved by correcting relative imports in
agent.pyandtools.py(e.g., adding a period for local file references). - The agent is tested by adding an expense: "add an expense $50 for groceries short description of this expense for my weekly groceries."
- Debugging Example: A "Dict object has no attribute amount" error occurs. The error message is fed back to Gemini CLI for a fix. The AI identifies that the tool needs to be included at the top of the function.
- Further Debugging: The arguments within the tool are refined to be primitive types (amount: float, category: string, description: string) instead of the
Expenseobject, allowing for casting. - The agent is re-run and successfully adds expenses and responds to queries like "what's my total spending?" (though it initially states it can only add expenses).
- The command
2. Context Engineering: Enhancing Code Quality and Functionality
This section focuses on improving the agent's capabilities by providing structured context.
Process:
- Adding New Functionality: Gemini CLI is prompted to add new features: "Calculate my total spending," "Get spending by category," and "List recent expenses." The prompt also reminds it to "remember to add the tools to the agent once they're created."
- In-Memory Database: The AI intelligently creates an in-memory database within the
tools.pyfile to store expense data for the new functionalities. - Tool and Agent Updates: The
tools.pyfile is updated with functions forcalculate_total_spending,get_spending_by_category, andlist_recent_expenses. Theagent.pyfile is updated to include these new tools in itstoolsarray. - Testing New Features: The agent is run again, and the new functionalities are tested:
- Adding expenses.
- Querying "What's my total spending?" (now works, returning $170).
- Querying "How much have I spent on food?" (prompts for a category, then correctly identifies $0 for "utilities" but $120 for "bills").
- Querying "List recent expenses" (successfully lists the added expenses).
- Introducing Context Engineering Files: To further improve the AI's understanding and adherence to standards, three key files are introduced:
gemini.md: Located in the user's hidden Gemini directory, this file contains project standards and best practices (e.g., Python styles, error handling, data storage). It's used globally by Gemini CLI for any project.docs/PRD_recurring_expenses.md: A Product Requirements Document (PRD) detailing the requirements for a new feature: "recurring expenses." This document bridges product and engineering.project_summary.md: A generated file that provides a concise overview of the entire directory structure, including file descriptions, key dependencies, and architectural patterns. This is crucial for Token Optimization.
- Implementing Recurring Expenses Feature: Gemini CLI is prompted to implement the "recurring expenses" feature, referencing the
PRD_recurring_expenses.mdfile, theproject_summary.mdfile, and thegemini.mdfile for coding standards. The prompt specifies extendingagent.py, updating the data model, and including error handling. - Reviewing New Code:
agent.pynow includes new tools:add_recurring_expense,list_recurring_expense, andproject_spending.tools.pyhas new functions for these recurring expense features and a new array for them.models.pyincludes a newRecurringExpenseclass.
- Testing Recurring Expenses: The agent is run, and the new features are tested:
- "Add a recurring monthly expense $1,200 for rent starting today, October 7th, 2025, description: rent payment for home."
- "Add another recurring expense $15 for Netflix monthly subscription starting today 2025 October 7th description entertainment."
- "Project my spending for the next 3 months." (Returns $3,645, indicating successful calculation).
- Impact of Context Engineering: The key difference highlighted is the improved structure and error handling in the code generated with context engineering, leading to more robust and production-ready software.
3. Token Optimization and Deployment
This section focuses on efficiency and making the agent accessible.
Process:
- Token Optimization through Project Summary: The
project_summary.mdfile acts as a token optimization mechanism. Instead of feeding the entire directory structure to the AI, it can refer to this summary to quickly identify relevant files, reducing the context window's load. - Deployment Preparation:
- Two files are added to the root directory:
server.py: A FastAPI scaffolding to run the ADK agent on the web and provide API access.Dockerfile: For containerizing the application for deployment.
- Two files are added to the root directory:
- Cloud Configuration:
gcloud config set project amarrage-developmentconfigures the Google Cloud project.
- Deployment to Cloud Run:
- The agent is deployed using the
uv run adk deploy cloud runcommand. - Parameters include: project ID (
amarrage-development), region (europe-west1), service name (expense-tracker-agent), app name (expense-tracker), specifying a UI, and pointing to the agent's location (expense_tracker/agent.py).
- The agent is deployed using the
- Verification:
- Upon successful deployment, a service URL is provided.
- The URL is accessed in a browser, showing the deployed ADK web interface.
- A test prompt ("Add a recurring monthly expense 1,200") is used to confirm the deployed agent functions correctly. The response is quick, indicating efficient deployment.
- The Cloud Console is checked to confirm the
expense-tracker-agentis running on Cloud Run with its own URL.
Key Arguments and Perspectives
- Vibe Coding for Speed: Vibe coding is presented as a method for rapid initial development, getting a project to a significant stage quickly.
- Context Engineering for Quality: Context engineering is crucial for refining the code generated by Vibe Coding, ensuring it adheres to best practices, integrates well with existing code, and is production-ready. It removes guesswork and provides specific guidance.
- Token Optimization for Efficiency and Cost: Token optimization is essential for managing the size of the AI's "briefing packet," preventing context window overload, and potentially reducing costs associated with processing large amounts of information.
- No-Code Development: The entire process emphasizes building and deploying a functional AI agent without writing any code, relying solely on natural language prompts and CLI commands.
- Iterative Debugging: The demonstration highlights the iterative nature of AI development, where errors are encountered and then fed back to the AI for correction.
Notable Quotes
- "Today we're going to learn three powerful techniques to build an AI agent, but all without writing a single line of code."
- "Vibe coding is essentially giving an AI player programmer your vibe or what you want to develop and having it go out and do that for you."
- "Context engineering is what kind of unlocks this for you because you don't have to reprompt your AI agent every time you want to develop a new feature to tell it things like best practices, where it should store certain pieces of code in different files or where it should find your documentation or how your API looks like."
- "Token optimization tries to reduce that by really giving your AI agent some direction on where it should be focusing on because it's really easy for your context window for your AI agent to become really overloaded."
- "So, white coding is for speed and context engineering is how you improve the quality of the code created and token optimization is for efficiency and to bring down the cost lower."
- "This is where context engineering can transform good code into great code."
- "This will help speed up our entire Gemini CLI development flow by introducing what we call token optimization."
Technical Terms and Concepts Explained
- Vibe Coding: A paradigm where natural language prompts define the desired style, functionality, and overall "vibe" of the AI-generated code.
- Context Engineering: A methodology that involves strategically providing relevant external information (documents, code snippets, best practices) to an AI model to enhance its understanding and output quality.
- Token Optimization: The process of minimizing the number of tokens (units of text processed by an LLM) used in prompts and context, aiming for efficiency and cost reduction.
- Gemini CLI: A command-line interface that acts as an intermediary between the user and Gemini AI models, enabling code generation, agent creation, and interaction.
- ADK (Agent Development Kit): A framework or library that provides tools and structures for building AI agents.
- Cloud Run: A serverless platform on Google Cloud that allows for the deployment of containerized applications, scaling automatically based on demand.
- RAG (Retrieval-Augmented Generation): A technique that enhances LLM responses by first retrieving relevant information from an external knowledge base (like a vector database) and then using that information to generate a more informed answer.
- Vector Databases: Databases designed to store and query high-dimensional data, commonly used for similarity searches in RAG systems.
- PRD (Product Requirements Document): A formal document that details the purpose, features, functionality, and user experience of a product or feature.
uv: A Python package manager that aims to be faster and more efficient than traditional managers like pip.- FastAPI: A modern, fast (high-performance) web framework for building APIs with Python, based on standard Python type hints.
- Dockerfile: A text file that contains instructions for building a Docker image, which is a package containing an application and its dependencies.
Logical Connections Between Sections
The video progresses logically from initial AI-assisted code generation (Vibe Coding) to enhancing its quality and functionality (Context Engineering), and finally to optimizing its performance and deploying it (Token Optimization and Cloud Run deployment). The LLM's_full.txt file serves as an initial context for Vibe Coding. Context Engineering builds upon this by introducing structured documents (gemini.md, PRD, project_summary.md) that guide the AI more precisely. Token Optimization, exemplified by the project_summary.md, directly addresses the efficiency concerns arising from extensive context. The deployment phase leverages the structured and refined agent created through these processes.
Data, Research Findings, or Statistics
- The video does not present explicit research findings or statistics but demonstrates practical application of AI development techniques.
- It mentions that Gemini CLI and Google Cloud Run have "generous free tiers," implying cost-effectiveness for users.
Section Headings
- Key Concepts
- Building an AI Agent with Vibe Coding, Context Engineering, and Token Optimization
-
- Vibe Coding: Initial Agent Development
-
- Context Engineering: Enhancing Code Quality and Functionality
-
- Token Optimization and Deployment
-
- Key Arguments and Perspectives
- Notable Quotes
- Technical Terms and Concepts Explained
- Logical Connections Between Sections
- Data, Research Findings, or Statistics Mentioned
- Synthesis/Conclusion
Synthesis/Conclusion
This demonstration effectively showcases a no-code approach to building and deploying a functional AI agent using Gemini CLI. The core takeaway is the synergistic power of Vibe Coding for rapid initial development, Context Engineering for elevating code quality and feature complexity through structured documentation, and Token Optimization for ensuring efficiency and manageability. By leveraging these techniques, users can create sophisticated AI agents, debug them effectively, and deploy them to cloud platforms like Cloud Run with minimal manual intervention. The process highlights how providing the AI with specific context, best practices, and project overviews leads to more robust, maintainable, and capable AI applications. The ability to iterate and debug with the AI, coupled with seamless deployment, makes this workflow accessible and powerful for developers and non-developers alike.
Chat with this Video
AI-PoweredHi! I can answer questions about this video "Vibe coding and context engineering with ADK". What would you like to know?