{"id":28283081,"url":"https://github.com/arjunprabhulal/adk-gemma3-function-calling","last_synced_at":"2026-07-09T20:31:46.118Z","repository":{"id":287879070,"uuid":"966080796","full_name":"arjunprabhulal/adk-gemma3-function-calling","owner":"arjunprabhulal","description":"ADK Gemma3 Function Calling Example","archived":false,"fork":false,"pushed_at":"2025-04-14T13:27:00.000Z","size":29621,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-17T07:44:43.109Z","etag":null,"topics":["adk","crewaitools","function-calling","gemma3","genai","llm","localllm","opensource","tools"],"latest_commit_sha":null,"homepage":"https://medium.com/@arjun-prabhulal","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arjunprabhulal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-14T11:24:08.000Z","updated_at":"2025-05-26T06:02:35.000Z","dependencies_parsed_at":"2025-04-14T13:05:20.497Z","dependency_job_id":null,"html_url":"https://github.com/arjunprabhulal/adk-gemma3-function-calling","commit_stats":null,"previous_names":["arjunprabhulal/adk-gemma3-function-calling"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arjunprabhulal/adk-gemma3-function-calling","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunprabhulal%2Fadk-gemma3-function-calling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunprabhulal%2Fadk-gemma3-function-calling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunprabhulal%2Fadk-gemma3-function-calling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunprabhulal%2Fadk-gemma3-function-calling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arjunprabhulal","download_url":"https://codeload.github.com/arjunprabhulal/adk-gemma3-function-calling/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunprabhulal%2Fadk-gemma3-function-calling/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268273052,"owners_count":24223790,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adk","crewaitools","function-calling","gemma3","genai","llm","localllm","opensource","tools"],"created_at":"2025-05-21T16:14:15.779Z","updated_at":"2025-10-24T21:37:32.440Z","avatar_url":"https://github.com/arjunprabhulal.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gemma 3 Function Calling with Google ADK\n\nA practical implementation demonstrating function calling (tool use) with Google's Gemma 3 model using the Google AI Development Kit (ADK) and Ollama. This project enables Gemma 3 to perform web searches using CrewAI tools wrapped for ADK compatibility.\n\n![Gemma 3 Function Calling Demo](Images/adk-gemma3-functioncalling-demo.gif)\n\n## 📚 Table of Contents\n\n* [🔍 Introduction](#-introduction)\n* [🏗️ Architecture](#️-architecture)\n  * [🧩 Core Components](#-core-components)\n  * [✨ Technology Highlights](#-technology-highlights)\n* [🚀 Features](#-features)\n* [🧠 Core Concepts](#-core-concepts)\n  * [ADK - Agent Development Kit](#adk---agent-development-kit)\n  * [Agents in ADK](#agents-in-adk)\n  * [Tools in ADK](#tools-in-adk)\n  * [Ollama Integration](#ollama-integration)\n* [📋 Requirements](#-requirements)\n* [🚦 Getting Started](#-getting-started)\n  * [1. Installation Steps](#1-installation-steps)\n  * [2. Setup](#2-setup)\n  * [3. Usage](#3-usage)\n* [🔄 How It Works](#-how-it-works)\n* [📁 Project Structure](#-project-structure)\n* [🔄 Key Considerations](#-key-considerations)\n* [⚠️ Troubleshooting](#️-troubleshooting)\n* [📦 Repository](#-repository)\n* [👨‍💻 Author](#-author)\n* [📄 License](#-license)\n\n## 🔍 Introduction\n\nThis project showcases how to leverage Google's ADK (Agent Development Kit) to build an agent powered by Gemma 3, Google's latest large language model. It demonstrates how to:\n\n- Connect to locally-hosted Gemma 3 via Ollama\n- Implement function calling for web search capabilities\n- Create a conversational agent that can access external data\n\n## 🏗️ Architecture\n\n### 🧩 Core Components\n\n* **Google ADK** - Provides the agent framework\n* **Gemma 3 (27B)** - Powers the language understanding and generation\n* **Ollama** - Hosts the Gemma model locally\n* **CrewAI Tools** - Provides web search capabilities\n* **Python 3.12+** - Base runtime environment\n\n### ✨ Technology Highlights\n\n* **Google ADK**  \n  Manages conversation flow and tool orchestration.\n* **Gemma 3 via Ollama**  \n  Delivers high-quality text generation with function calling capabilities.\n* **LiteLlm Integration**  \n  Connects ADK to Ollama-hosted models seamlessly.\n* **Brave Search API**  \n  Provides access to real-time web data through [Brave's Search API](https://brave.com/search/api/).\n\n## 🚀 Features\n\n* **Local LLM Integration** - Run Gemma 3 locally using Ollama\n* **Function Calling** - Enable the model to use external tools\n* **Web Search Capability** - Connect to Brave Search for real-time information\n* **ADK Framework** - Leverage Google's agent development toolkit\n* **Simple Command Line Interface** - Easy to use with straightforward queries\n\n## 🧠 Core Concepts\n\n### ADK - Agent Development Kit\n\n**Agent Development Kit (ADK)** is an open-source, code-first Python toolkit for building intelligent AI agents. It provides the infrastructure needed to create agents that can interact with users, reason about tasks, and use tools to complete goals.\n\n### Agents in ADK\n\nAn **Agent** in ADK acts as the orchestrator for AI interactions. In this project, we use **LlmAgent**, which is a core component in ADK acting as the \"thinking\" part of your application. According to [Google's ADK documentation](https://google.github.io/adk-docs/agents/llm-agents/), an LlmAgent:\n\n- Leverages a Large Language Model (LLM) for reasoning and understanding\n- Is non-deterministic (unlike workflow agents that follow predefined paths)\n- Dynamically decides how to proceed and which tools to use\n- Can be configured with an identity, instructions, and tools\n\nThe four key components of an LlmAgent are:\n\n1. **Identity and Purpose** - Defined through `name`, `description`, and `model`\n2. **Instructions** - Detailed guidance through the `instruction` parameter\n3. **Tools** - Capabilities for external interactions via the `tools` parameter\n4. **Configuration** - Fine-tuning with parameters like `generate_content_config`\n\n### Tools in ADK\n\n**Tools** in ADK are capabilities that agents can use to interact with external systems. In this project:\n\n- We use **CrewaiTool** - A wrapper that adapts CrewAI's BraveSearchTool for use with ADK\n- The tool has a clear name and description to help the model understand when and how to use it\n- Our implementation follows best practices by providing detailed guidance on tool usage in the agent instructions\n\nThis implementation follows the [official Google ADK documentation for third-party tools](https://google.github.io/adk-docs/tools/third-party-tools/#2-using-crewai-tools), which provides guidance on integrating tools from frameworks like CrewAI into ADK agents.\n\n### Ollama Integration\n\n**Ollama** provides a way to run Gemma 3 and other large language models locally. Google ADK connects to Ollama through:\n\n- **LiteLlm** - A wrapper that standardizes communication with different LLM providers\n- The LiteLlm implementation uses the `litellm` library to communicate with Ollama\n\n## 📋 Requirements\n\n- Python 3.12+\n- Ollama installed locally\n- Gemma 3 (27B) model pulled via Ollama\n- [Brave Search API](https://brave.com/search/api/) key (free tier available with 2,000 queries/month)\n\n## 🚦 Getting Started\n\n### 1. Installation Steps\n\nClone this repository:\n```bash\ngit clone https://github.com/arjunprabhulal/adk-gemma3-function-calling.git\ncd adk-gemma3-function-calling\n```\n\n### 2. Setup\n\n#### Create and activate a virtual environment:\n```bash\npython -m venv venv\nsource venv/bin/activate  # On Windows: venv\\Scripts\\activate\n```\n\n#### Install dependencies:\n```bash\npip install google-adk\npip install \"google-adk[extensions]\"\n```\n# Note: This will install:\n# - google-adk - Core Agent Development Kit\n# - google-adk[extensions] - Additional extensions for ADK functionality\n\n#### Set up your Brave Search API key:\n```bash\nexport BRAVE_API_KEY=your_api_key_here\n```\nYou can get your API key by signing up at [Brave Search API](https://brave.com/search/api/) - a free tier is available with up to 2,000 queries per month.\n\n#### Pull the Gemma 3 model:\n```bash\nollama pull gemma3:27b\n```\n\n### 3. Usage\n\nThere are multiple ways to interact with your agent:\n\n#### Option 1: Web-based UI (Recommended for debugging)\nRun the agent using ADK's browser-based developer UI:\n```bash\n# Navigate to the parent directory of the gemma3 package\ncd adk-gemma3-function-calling\n\n# Start the web interface\nadk web\n```\n\nThen open the URL provided (usually `http://localhost:8000`) in your browser.\n- Select \"gemma3\" from the dropdown menu in the top-left corner\n- Type your query in the chat interface\n- You can inspect function calls, model responses, and see detailed execution flow\n\nThis is particularly useful for debugging as it provides a visual representation of tool calls and responses.\n\n#### Option 2: Terminal with ADK CLI (Recommended)\nRun the agent directly in the terminal using ADK's command line interface:\n```bash\n# Navigate to the parent directory of the gemma3 package\ncd adk-gemma3-function-calling\n\n# Run the agent using ADK's CLI\nadk run gemma3\n```\n\nThis will start an interactive chat session in your terminal. Type your questions and the agent will respond, indicating when it's using tools.\n\nTo exit, use Cmd/Ctrl+C.\n\n#### Option 3: API Server\nStart a FastAPI server to interact with your agent via HTTP requests:\n```bash\n# Navigate to the parent directory of the gemma3 package\ncd adk-gemma3-function-calling\n\n# Start the API server\nadk api_server\n```\n\nThis enables you to test local cURL requests or integrate with other applications, which is useful for development and testing before deployment.\n\n## 🔄 How It Works\n\nThe implementation follows these steps:\n\n1. **Agent Initialization**:\n   - Creates an LlmAgent with a reference to the Ollama-hosted Gemma 3 model\n   - Configures the agent with appropriate instructions\n   - Adds the web search tool to the agent's capabilities\n\n2. **Tool Definition**:\n   - Defines a BraveSearchTool instance from CrewAI\n   - Wraps it with CrewaiTool for ADK compatibility using the pattern:\n     ```python\n     from google.adk.tools.crewai_tool import CrewaiTool\n     from crewai_tools import BraveSearchTool\n     \n     # Instantiate the CrewAI tool (requires BRAVE_API_KEY env var)\n     search_tool_instance = BraveSearchTool()\n     \n     # Wrap it with CrewaiTool for ADK, providing name and description\n     search_tool = CrewaiTool(\n         name=\"web_search\",\n         description=\"Searches the internet using Brave Search to find current information.\",\n         tool=search_tool_instance\n     )\n     ```\n   - The ADK documentation emphasizes providing clear name and description to help the model understand when to use the tool\n\n3. **Query Processing**:\n   - User query is passed to the agent\n   - Gemma 3 decides whether to use the search tool based on the query\n   - If needed, the model formulates an appropriate search query\n   - Results are incorporated into the final response\n\n4. **Response Generation**:\n   - The agent processes all information and generates a coherent response\n   - Output is returned to the user in natural language\n\n## 📁 Project Structure\n\nFollowing the structure recommended in the [ADK documentation](https://google.github.io/adk-docs/get-started/quickstart/):\n\n```\nadk-gemma3-function-calling/\n├── gemma3/\n│   ├── __init__.py         # Package initialization (imports agent.py)\n│   └── agent.py            # Agent implementation with ADK\n├── .gitignore              # Git ignore file\n├── README.md               # Project documentation\n└── requirements.txt        # Dependencies\n```\n\n## 🔄 Key Considerations\n\n1. **Model Selection**\n   - Gemma 3 (27B) provides a good balance of performance and efficiency for local deployment.\n   - Ensure your system has adequate GPU resources to run the model effectively.\n\n2. **Tool Description**\n   - The quality of tool use depends on clear, concise tool descriptions.\n   - For best results, make sure tool descriptions explain exactly what the tool does and when to use it.\n\n3. **API Credentials**\n   - Keep your Brave Search API key secure.\n   - Consider using a proper secrets management approach for production deployments.\n\n4. **Ollama Configuration**\n   - Ensure Ollama is running and accessible before starting the agent.\n   - Monitor Ollama's resource usage, especially for the 27B parameter model.\n\n## ⚠️ Troubleshooting\n\n1. **Model Loading Issues**:\n   - Ensure Ollama is running: `ollama list` should show the gemma3:27b model.\n   - If the model fails to load, try: `ollama pull gemma3:27b` again.\n\n2. **API Key Issues**:\n   - Verify your Brave API key is correctly set in the environment.\n   - Test the API key independently to ensure it's valid.\n\n3. **Memory Constraints**:\n   - The 27B model requires significant RAM/VRAM.\n   - Consider using a smaller model like gemma3:7b if experiencing memory issues.\n\n4. **Function Calling Problems**:\n   - If the model doesn't use tools properly, try making the tool description more explicit.\n   - Ensure your query clearly requires external information.\n\n5. **LiteLLM/Ollama KeyError Bug**:\n   - There's a known issue with Ollama's JSON format responses and LiteLLM's parsing that can cause a KeyError: 'name' error.\n   - This happens when Ollama returns JSON format that isn't specifically a tool call format.\n   - Error looks like: `KeyError: 'name'` in `litellm/llms/ollama/completion/transformation.py`\n   - A fix has been submitted in [PR #9966](https://github.com/BerriAI/litellm/pull/9966) for the LiteLLM package but is still pending approval and merging.\n   - This bug might cause your application to crash or enter an infinite loop when using function calling with Ollama models.\n   - **Temporary workarounds**:\n     - Manually patch your local LiteLLM installation with the changes from PR #9966\n     - Avoid using `format=json` in Ollama requests if possible\n     - Wait for the PR to be merged and update to the next LiteLLM release that includes the fix\n\n## 📦 Repository\n\nThis project is available on GitHub at [arjunprabhulal/adk-gemma3-function-calling](https://github.com/arjunprabhulal/adk-gemma3-function-calling).\n\nFor another related project on ADK with MCP, check out [arjunprabhulal/adk-python-mcp-client](https://github.com/arjunprabhulal/adk-python-mcp-client).\n\n## 👨‍💻 Author\n\nCreated by Arjun Prabhulal. For more articles on AI/ML and Generative AI, follow [Arjun Prabhulal on Medium](https://medium.com/@arjun-prabhulal).\n\n## 📄 License\n\nThis project is released under a free and open license. Anyone is free to use, modify, distribute, or build upon this code for any purpose, including commercial applications, without restriction. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farjunprabhulal%2Fadk-gemma3-function-calling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farjunprabhulal%2Fadk-gemma3-function-calling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farjunprabhulal%2Fadk-gemma3-function-calling/lists"}