--- name: cva-concepts-adk description: Google ADK (Agent Development Kit) architecture and core concepts. Covers agent types (LLM, Sequential, Parallel, Loop, Multi-agent), tool ecosystem, execution flows, deployment options, and observability. Model-agnostic framework for production AI agents. Use when understanding ADK architecture, selecting agent patterns, designing agent systems, or deploying to Vertex AI. allowed-tools: Read,Bash,Edit,Write,Glob --- # Google ADK (Agent Development Kit) - Architecture > **Framework:** Open-source by Google > **Version:** 0.2.0+ > **Production:** Powers Google Agentspace and CES > **Documentation:** https://google.github.io/adk-docs/ --- ## 🎯 What is Google ADK? **Agent Development Kit (ADK)** is Google's open-source framework for developing and deploying AI agents. ### Key Characteristics - 🧠 **Model-agnostic** - Works with Gemini, OpenAI, Claude, Llama, etc. - πŸš€ **Deployment-agnostic** - Local, Vertex AI, Cloud Run, GKE, Kubernetes - πŸ”§ **Framework-compatible** - Integrates with LangChain, CrewAI, custom tools - 🏒 **Production-ready** - Battle-tested in Google products - πŸ”„ **Interoperable** - Java and Python SDKs with identical APIs --- ## πŸ—οΈ Core Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Your Application β”‚ β”‚ (Clojure via Java interop) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Agent Layer β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ LLM β”‚ β”‚ Workflow β”‚ β”‚ Multi-Agent β”‚ β”‚ β”‚ β”‚ Agent β”‚ β”‚ Agent β”‚ β”‚ System β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Tool Ecosystem β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚Built-in β”‚ β”‚ Custom β”‚ β”‚ OpenAPIβ”‚ β”‚Third-partyβ”‚ β”‚ β”‚ β”‚ Tools β”‚ β”‚Functionsβ”‚ β”‚ Tools β”‚ β”‚ (LC) β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ LLM Layer β”‚ β”‚ Gemini | Claude | GPT | Open Models β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## πŸ€– Agent Types ### 1. LLM Agent (Dynamic Routing) **Concept:** Agent uses LLM to make decisions about which actions to execute. **When to use:** - βœ… Adaptive behavior based on context - βœ… Multiple tools available - βœ… Complex decisions required - βœ… Unpredictable input patterns **Clojure Example:** ```clojure (ns lab.agents.llm-agent "LLM Agent with dynamic tool selection" (:import [com.google.adk.agent LLMAgent] [com.google.adk.model GeminiModel] [com.google.adk.tool Tool])) (defn create-calculator-tool "Custom calculator tool" [] (-> (Tool/builder) (.setName "calculator") (.setDescription "Performs basic arithmetic operations") (.setFunction (reify java.util.function.Function (apply [_ input] ;; Parse and execute calculation (str "Result: " (eval (read-string input)))))) (.build))) (defn create-llm-agent "Creates LLM agent with tools" [tools] (-> (LLMAgent/builder) (.setModel (-> (GeminiModel/builder) (.setModelName "gemini-1.5-flash") (.setTemperature 0.7) (.build))) (.addTools tools) (.setSystemPrompt "You are a helpful assistant with access to tools.") (.build))) ;; REPL Usage (comment (def tools [(create-calculator-tool)]) (def agent (create-llm-agent tools)) (.execute agent "What is 25 * 4?") ;; Agent decides to use calculator tool ;; => "The result is 100" ) ``` **Flow:** ``` Input β†’ LLM decides β†’ Selects Tool β†’ Executes β†’ LLM synthesizes β†’ Output ``` --- ### 2. Workflow Agents (Structured) #### 2.1 Sequential Agent **Concept:** Execute steps in predetermined order. **When to use:** - βœ… Fixed pipeline (ETL, data processing) - βœ… Deterministic execution required - βœ… Lower cost (no LLM routing overhead) ```clojure (ns lab.agents.sequential (:import [com.google.adk.agent SequentialAgent] [com.google.adk.agent.step LLMStep])) (defn create-sequential-pipeline "Sequential agent for data processing" [] (-> (SequentialAgent/builder) (.addStep (-> (LLMStep/builder) (.setPrompt "Extract key entities from: {{input}}") (.setModel "gemini-1.5-flash") (.build))) (.addStep (-> (LLMStep/builder) (.setPrompt "Classify entities: {{previous_output}}") (.build))) (.addStep (-> (LLMStep/builder) (.setPrompt "Generate summary: {{previous_output}}") (.build))) (.build))) ;; REPL Usage (comment (def pipeline (create-sequential-pipeline)) (.execute pipeline "Process this medical text...") ;; Step 1: Extract entities ;; Step 2: Classify ;; Step 3: Summarize ;; => Final summary ) ``` **Flow:** ``` Input β†’ Step 1 β†’ Step 2 β†’ Step 3 β†’ ... β†’ Output ``` --- #### 2.2 Parallel Agent **Concept:** Execute multiple agents concurrently. **When to use:** - βœ… Independent tasks can run simultaneously - βœ… Need to reduce latency - βœ… Aggregating results from multiple sources ```clojure (ns lab.agents.parallel (:import [com.google.adk.agent ParallelAgent])) (defn create-parallel-researcher "Parallel agent for multi-source research" [] (-> (ParallelAgent/builder) (.addAgent "scholar" (create-scholar-agent)) (.addAgent "pubmed" (create-pubmed-agent)) (.addAgent "web" (create-web-search-agent)) (.setAggregationStrategy :merge-all) (.build))) ;; REPL Usage (comment (def researcher (create-parallel-researcher)) (.execute researcher "Research: effectiveness of salicylic acid") ;; Executes 3 agents concurrently: ;; - Google Scholar search ;; - PubMed search ;; - Web search ;; => Aggregated results from all sources ) ``` **Flow:** ``` Input β†’ ┬─ Agent 1 ─┐ β”œβ”€ Agent 2 ─┼─ Aggregate β†’ Output └─ Agent 3 β”€β”˜ ``` --- #### 2.3 Loop Agent **Concept:** Repeat execution until condition met. **When to use:** - βœ… Iterative refinement needed - βœ… Quality threshold must be reached - βœ… Self-correction workflows ```clojure (ns lab.agents.loop (:import [com.google.adk.agent LoopAgent])) (defn create-refining-agent "Loop agent that refines output until quality threshold" [] (-> (LoopAgent/builder) (.setAgent (create-writer-agent)) (.setMaxIterations 5) (.setCondition (reify java.util.function.Predicate (test [_ output] (>= (calculate-quality-score output) 0.8)))) (.build))) ;; REPL Usage (comment (def refiner (create-refining-agent)) (.execute refiner "Write professional medical article") ;; Iteration 1: quality = 0.6 ;; Iteration 2: quality = 0.75 ;; Iteration 3: quality = 0.85 βœ“ ;; => Returns iteration 3 output ) ``` **Flow:** ``` Input β†’ Execute β†’ Check condition ─No─┐ β”‚ β”‚ Yes β”‚ ↓ β”‚ Output β†β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ### 3. Multi-Agent Systems **Concept:** Coordinate multiple specialized agents. **Patterns:** - **Hierarchical:** Manager agent delegates to worker agents - **Collaborative:** Agents negotiate and share information - **Competitive:** Best result selected from multiple approaches ```clojure (ns lab.agents.multi-agent (:import [com.google.adk.agent MultiAgentSystem])) (defn create-healthcare-system "Multi-agent system for healthcare content generation" [] (-> (MultiAgentSystem/builder) (.addAgent "extractor" (create-data-extraction-agent)) (.addAgent "validator" (create-claims-validator-agent)) (.addAgent "researcher" (create-reference-search-agent)) (.addAgent "seo" (create-seo-optimizer-agent)) (.addAgent "consolidator" (create-final-consolidator-agent)) (.setOrchestrationStrategy :sequential-with-feedback) (.build))) ``` > πŸ“˜ **Complete implementation:** See [`cva-healthcare-pipeline`](../cva-healthcare-pipeline/SKILL.md) for production multi-agent system. --- ## πŸ”§ Tool Ecosystem ### Built-in Tools **Available out-of-box:** - Web search (Google Search, Google Scholar) - Code execution (Python, JavaScript) - Data retrieval (BigQuery, Cloud Storage) - API calls (REST, GraphQL) ### Custom Tools (Clojure) ```clojure (ns lab.tools.custom (:import [com.google.adk.tool Tool])) (defn create-database-query-tool "Custom tool for database queries" [db-spec] (-> (Tool/builder) (.setName "query_database") (.setDescription "Queries PostgreSQL database for tenant data") (.setInputSchema {:type "object" :properties {:query {:type "string" :description "SQL query to execute"}} :required ["query"]}) (.setFunction (reify java.util.function.Function (apply [_ input] (let [query (get input "query")] (jdbc/execute! db-spec [query]))))) (.build))) ``` ### Tool Composition **Combine tools from different sources:** ```clojure (defn create-hybrid-agent "Agent with built-in + custom + third-party tools" [] (let [built-in-search (GroundingTool/googleSearch) custom-db (create-database-query-tool db-spec) langchain-tool (from-langchain wikipedia-tool)] (create-llm-agent [built-in-search custom-db langchain-tool]))) ``` --- ## πŸš€ Deployment Options ### 1. Local Development ```bash # Run locally with Clojure CLI clojure -M:dev -m lab.core ``` ### 2. Vertex AI Agent Engine ```clojure (ns lab.deployment.vertex (:import [com.google.cloud.vertexai.agent AgentEngine])) (defn deploy-to-vertex "Deploy agent to Vertex AI Agent Engine" [agent project-id] (-> (AgentEngine/builder) (.setProjectId project-id) (.setLocation "us-central1") (.setAgent agent) (.deploy))) ;; REPL Usage (comment (deploy-to-vertex my-agent "saas3-476116") ;; => Deployed to Vertex AI with endpoint URL ) ``` ### 3. Cloud Run (Container) ```dockerfile FROM clojure:openjdk-17-tools-deps COPY . /app WORKDIR /app RUN clojure -M:build CMD ["clojure", "-M:prod"] ``` ```bash # Deploy to Cloud Run gcloud run deploy agent-service \ --source . \ --region us-central1 \ --allow-unauthenticated ``` --- ## πŸ“Š Observability ### Logging ```clojure (ns lab.observability.logging (:require [clojure.tools.logging :as log])) (defn execute-with-logging "Execute agent with comprehensive logging" [agent input] (log/info "Agent execution started" {:input input}) (let [start-time (System/currentTimeMillis) result (.execute agent input) duration (- (System/currentTimeMillis) start-time)] (log/info "Agent execution completed" {:duration-ms duration :output-length (count result) :success true}) result)) ``` ### Metrics **Track key metrics:** - Execution time - Token usage - Tool invocations - Error rates - Cost per execution ```clojure (defn track-metrics [agent input] (let [metrics (atom {})] (add-watch agent :metrics (fn [_ _ _ new-state] (swap! metrics assoc :tokens (:tokens-used new-state) :tools-called (:tool-invocations new-state)))) (.execute agent input) @metrics)) ``` --- ## πŸ’‘ Best Practices ### 1. Start Simple, Optimize Later **Progression:** ``` LLM Agent β†’ Sequential Agent β†’ Parallel Agent β†’ Multi-Agent System (Day 1) (Week 1) (Month 1) (Production) ``` **Rationale:** Build complexity incrementally based on actual requirements. ### 2. Choose the Right Agent Type **Decision Matrix:** | Need | Agent Type | Reason | |------|-----------|--------| | Simple task, one path | Sequential | Lowest cost, deterministic | | Complex routing needed | LLM | Flexibility, adaptability | | Independent parallel tasks | Parallel | Reduced latency | | Iterative refinement | Loop | Quality improvement | | Complex system | Multi-Agent | Specialized expertise per component | > πŸ“˜ **Detailed guidance:** See [`cva-concepts-agent-types`](../cva-concepts-agent-types/SKILL.md) for A/B/C/D taxonomy. ### 3. Tool Design Principles - **Single Responsibility:** One tool = one clear function - **Descriptive Names:** `query_customer_database` not `db` - **Rich Descriptions:** Help LLM understand when to use tool - **Error Handling:** Return structured errors, not exceptions - **Idempotent:** Safe to retry ### 4. Model Selection **By task complexity:** - **Simple** (extraction, classification): `gemini-1.5-flash` - **Medium** (reasoning, personalization): `gemini-1.5-pro` or `claude-3-5-haiku` - **Complex** (consolidation, critical decisions): `claude-3-5-sonnet` or `gemini-2.0-flash-thinking` > πŸ“˜ **Cost optimization:** See [`cva-patterns-cost`](../cva-patterns-cost/SKILL.md) for multi-model routing. ### 5. Testing Strategy ```clojure (ns lab.testing.agents (:require [clojure.test :refer :all])) (deftest test-agent-execution (testing "Agent produces valid output" (let [agent (create-test-agent) result (.execute agent "test input")] (is (string? result)) (is (> (count result) 0)) (is (valid-json? result))))) (deftest test-agent-tools (testing "Agent uses correct tools" (let [agent (create-test-agent-with-mock-tools) _ (.execute agent "calculate 2 + 2") tool-calls (get-tool-invocations agent)] (is (= 1 (count tool-calls))) (is (= "calculator" (:tool-name (first tool-calls))))))) ``` ### 6. Error Handling ```clojure (defn execute-with-retry "Execute agent with exponential backoff retry" [agent input max-retries] (loop [attempt 1] (try (.execute agent input) (catch Exception e (if (< attempt max-retries) (do (Thread/sleep (* 1000 (Math/pow 2 attempt))) (recur (inc attempt))) (throw e)))))) ``` --- ## πŸ”— Related Skills - [`cva-concepts-agent-types`](../cva-concepts-agent-types/SKILL.md) - A/B/C/D agent taxonomy ⭐ - [`cva-quickref-adk`](../cva-quickref-adk/SKILL.md) - ADK API quick reference ⭐ - [`cva-patterns-workflows`](../cva-patterns-workflows/SKILL.md) - Multi-agent workflow patterns - [`cva-patterns-cost`](../cva-patterns-cost/SKILL.md) - Cost optimization strategies - [`cva-healthcare-pipeline`](../cva-healthcare-pipeline/SKILL.md) - Production multi-agent system - [`cva-setup-vertex`](../cva-setup-vertex/SKILL.md) - Vertex AI deployment setup --- ## πŸ“˜ Additional Resources ### Official Documentation - [Google ADK Docs](https://google.github.io/adk-docs/) - [ADK GitHub](https://github.com/google/adk-java) - [Vertex AI Agent Engine](https://cloud.google.com/vertex-ai/generative-ai/docs/agent-engine) ### Advanced Topics - [Custom Tool Development](https://google.github.io/adk-docs/tools/) - [Multi-Agent Orchestration](https://google.github.io/adk-docs/agents/multi-agent/) - [Production Deployment](https://google.github.io/adk-docs/deploy/) --- *This skill provides foundational ADK knowledge. Combine with agent-types taxonomy and workflow patterns for complete understanding.*