{"id":195831,"date":"2025-03-16T04:00:27","date_gmt":"2025-03-16T09:00:27","guid":{"rendered":"https:\/\/narcolepticnerd.com\/2025\/03\/16\/beyond-the-chatbot-agentic-ai-with-gemma\/"},"modified":"2025-03-16T04:00:27","modified_gmt":"2025-03-16T09:00:27","slug":"beyond-the-chatbot-agentic-ai-with-gemma","status":"publish","type":"post","link":"https:\/\/narcolepticnerd.com\/2025\/03\/16\/beyond-the-chatbot-agentic-ai-with-gemma\/","title":{"rendered":"Beyond the Chatbot: Agentic AI with Gemma"},"content":{"rendered":"
<\/p>\n
<\/p>\n
Gemma<\/a> is a family of lightweight, generative artificial intelligence (AI) open models, built from the same research and technology used to create the Gemini<\/a> models. In a blog post last year<\/a>, we showcased a text-based adventure game creation using Gemma. In this blog post, you will learn how to use Gemma with a form of AI called Agentic AI, which offers a different way to use Large Language Models (LLMs).<\/p>\n Most common AIs today are reactive<\/b>. They respond to specific commands, like a smart speaker playing music when asked. They\u2019re useful, but can only do what they\u2019re told.<\/p>\n In contrast, Agentic AI is proactive and autonomous<\/b>. It makes its own decisions to reach goals. A key feature is using external tools like search engines, specialized software, and other programs to get information beyond their inherent knowledge base. This lets Agentic AI work and solve problems very independently and effectively.<\/p>\n Here, we\u2019ll provide a practical guide to constructing a Gemma 2<\/a> based Agentic AI system, covering key technical concepts like “Function Calling”<\/b>, “ReAct”<\/b> and “Few-shot prompting”<\/b>. This AI system will serve as a dynamic lore generator for a fictional game, actively expanding its history and providing a distinct, perpetually evolving narrative landscape for players.<\/p>\n Before we dive into the coding, let’s understand Gemma’s agentic AI capabilities. You can experiment directly with it through Google AI Studio<\/a>. Google AI Studio offers several Gemma 2 models. The 27B model is recommended for the best performance, but the smaller model like 2B can also be used as you can see below. In this example, we tell Gemma that there\u2019s a This result shows that Gemma 2 does not suggest calling the Gemma\u2019s built-in function calling capabilities are limited, which limits its ability to act as an agent. However, its strong instruction-following capabilities can be used to compensate for this missing functionality. Let\u2019s see how we can harness these capabilities to expand Gemma\u2019s functionality.<\/p>\n We will implement a prompt based on the ReAct (Reasoning and Acting)<\/a> prompting style. ReAct defines available tools<\/b> and a specific format<\/b> for interaction. This structure enables Gemma to engage in cycles of Thought<\/b> (reasoning), Action<\/b> (utilizing tools), and Observation<\/b> (analyzing the output).<\/p>\n<\/div>\n As you can see, Gemma is attempting to use the Awesome! Now you\u2019ve witnessed Gemma\u2019s function calling in action. This function calling ability allows it to execute operations autonomously in the background, executing tasks without requiring direct user interaction.<\/p>\n Let\u2019s get our hands dirty with the actual demo, building a History AI Agent!<\/p>\n All the prompts below are in the “Agentic AI with Gemma 2<\/a>” notebook in Gemma’s Cookbook<\/a>. One difference when using Gemma in Google AI Studio versus directly with Python on Colab is that you must use a specific format like Let\u2019s imagine a fictional game world where AI agents craft dynamic content.<\/p>\n These agents, designed with specific objectives, can generate in-game content like books, poems, and songs, in response to a player choice or significant events within the game\u2019s narrative.<\/p>\n A key feature of these AI agents is their ability to break down complex goals into smaller actionable steps. They can analyze different approaches, evaluate potential outcomes, and adapt their plans based on new information.<\/p>\n Where Agentic AI truly shines is that they\u2019re not just passively spitting out information. They can interact with digital (and potentially physical) environments, execute tasks, and make decisions autonomously to achieve their programmed objectives.<\/p>\n Here\u2019s an example ReAct style prompt designed for an AI agent that generates in-game content, with the capability to use function calls to retrieve historical information.<\/p>\n<\/div>\n Let\u2019s try to write a book. See the example outputs below:<\/p>\n As you can see, Gemma may struggle with function calling due to a lack of training in that area.<\/p>\n To address this limitation, we can employ “One-shot prompting<\/b>“, a form of in-context learning, where demonstrations are embedded within the prompt. This example will serve as a guide for Gemma, allowing it to understand the intended task and improve its performance through contextual learning.<\/p>\n (Note: the green section is a provided example, the actual prompt comes after it)<\/i><\/p>\n<\/div>\n Notably, the model performs better since For more complex tasks, use “Few-shot prompting”<\/b>. It works by providing a small set of examples (usually 2-5, but sometimes more) that demonstrate the desired input-output relationship, allowing the model to grasp the underlying pattern.<\/p>\n Now, we received a function name Note that the agent used the provided information to create a book about Eldoria’s Rebel Leader.<\/p>\n We\u2019re still in the early stages of Agentic AI development, but the progress is rapid. As these systems become more sophisticated, we can expect them to play an increasingly significant role in our lives.<\/p>\n Here are some potential applications, focused primarily on gaming:<\/p>\n But with implications beyond:<\/p>\n The era of passive, reactive AI is gradually giving way to a future where AI is proactive, goal-oriented, and capable of independent action. This is the dawn of Agentic AI, and it’s a future worth getting excited about.<\/p>\nBridging the Gap<\/h2>\n
get_current_time()<\/code> function and ask Gemma to tell us the time in Tokyo and Paris.<\/p>\n<\/div>\n
<\/p><\/div>\n<\/div>\n
get_current_time()<\/code> function. This model capability is called “Function Calling”<\/b>, which is a key feature for enabling AI to interact with external systems and APIs to retrieve data.<\/p>\n
<\/p><\/div>\n<\/div>\n
get_current_time()<\/code> function for both Tokyo and Paris. A Gemma model cannot simply execute on its own. To make this operational, you\u2019ll need to run the generated code yourself or as part of your system. Without it, you can still proceed and observe Gemma\u2019s response, similar to the one provided below.<\/p>\n<\/div>\n
<\/p><\/div>\n<\/div>\n
Demo Setup<\/b><\/h2>\n
So, how does it work?<\/h2>\n
Zero-shot prompting<\/b><\/h3>\n<\/div>\n<\/p><\/div>\n<\/div>\n
One-Shot Prompting<\/b><\/h3>\n
<\/p><\/div>\n<\/div>\n
Action<\/code> contains the correct input.<\/p>\n
Few-shot prompting<\/b><\/h3>\nget_person_info<\/code> and parameter values
\"name: Anya, the Rebel Leader\"<\/code>, the game must connect to an API and call the function. We will use a synthetic response payload for this API interaction.<\/p>\n<\/div>\n
<\/p><\/div>\n<\/div>\n
The Future is Agentic<\/h2>\n
\n
\n
Next steps<\/h2>\n