[Gemma 3]Function Calling Routing And Monitoring Using Gemma Google Genai
Copyright 2025 Google LLC.
Function Calling Router for Gemma-3: Implement and Monitor Agentic RAG workflow
Overview
Gemma-3 natively doesn’t support Function calling at Inference with Ollama or HuggingFace. Gemma-3 models pulled from the official Ollama registry do not advertise dedicated tool/function calling tags, and Ollama will return an error if requesting native tool support through direct means.
Our approach:
- Perform function calling by prompt engineering using delimiters hardcoded rather than by native tokens or system templates.
- Structured outputs and Agentic workflows are possible, but developers need to provide clear function definitions and parse model outputs for tool invocation details.
Author Details
- Author: Tarun Jain
- GitHub: @lucifertrj
- LinkedIn: @Tarun R Jain
Installation
Document processing
Data loading- Raw data extraction
With reference to this PDF Parser comparison paper, PDFium performs well on Financial documents. arxiv.org/abs/2410.09871
3
{'producer': 'Microsoft® Word LTSC',
, 'creator': 'Microsoft® Word LTSC',
, 'creationdate': '2025-07-23T13:00:52+05:30',
, 'title': '',
, 'author': 'aDMIN',
, 'subject': '',
, 'keywords': '',
, 'moddate': '2025-07-23T13:00:52+05:30',
, 'source': 'data/23AI5PCOTM-OTML.pdf',
, 'total_pages': 3,
, 'page': 0} Initialize Dense and Sparse Embeddings
Initialize your Vector database and config the collection- Hybrid Search
True
Index your data
['df3ed049-d3a2-435d-aefd-097d1e90dff5', , '8bcc0506-491a-462d-b5d3-c9cf867e6107', , 'ee11554a-7a8b-4802-9646-9c707cccb315']
storage.sqlite
Data is ingested, its time for the inference and building LangGraph nodes for Agentic RAG.
3
{'producer': 'Microsoft® Word LTSC',
, 'creator': 'Microsoft® Word LTSC',
, 'creationdate': '2025-07-23T13:00:52+05:30',
, 'title': '',
, 'author': 'aDMIN',
, 'subject': '',
, 'keywords': '',
, 'moddate': '2025-07-23T13:00:52+05:30',
, 'source': 'data/23AI5PCOTM-OTML.pdf',
, 'total_pages': 3,
, 'page': 0,
, '_id': 'df3ed049-d3a2-435d-aefd-097d1e90dff5',
, '_collection_name': 'agenticrag'} Agentic Setup: Answer Generation (Implement Function calling router)
Function calling lets you connect models to external tools and APIs. Instead of generating text responses, the model determines when to call specific functions and provides the necessary parameters to execute real-world actions. This allows the model to act as a bridge between natural language and real-world actions and data.
Image credits: https://ai.google.dev/gemini-api/docs/function-calling
Our goal:
- Have 2 tools: Knowledge base and Web Search tool
- If query is from knowledge base, route to retrieve_docs tool
- If query is not from knowledge base, route to web_search tool
Fig.1: Function calling workflow
Tool-1: Knowledge base retriever:
Retrieve right document from the knowledge base.
Tool-2: Web Search
Get information from DuckDuckGo Search using the pre-defined tool kit from Langchain
Execution: Execute the function tool logic
Our goal is to let LLM chose what function is right for the given user query and then call that function along with the required arguments and then execute that code in the runtime using the interpreter: eval() function.
LangGraph Implementation
We will use the same two above tools: retrieve_docs and web_search tool along with the execution tool to get context. This function calling workflow we will replicate using LangGraph as demonstrated in the previous about image, Fig.1.
Get Credentials
- Get your OPIK API Key: OPIK- Trace and Monitor
- Get your Gemini API Key: Gemma-3-27b
Node-1: Given the user query, pick right tool
This is where we use the first LLM function call, where LLM decide for the given user task which is the right tool. We define the delimiters.
- Send user message with instructions and function definitons and first user message.
- Handle Model response when a tool/function is used using
tool_codedelimiters - Execute local function and create tool output string using execute_tool_call, the result should have
tool_outputdelimiters.
Node-2: Final Answer Generation
Once you get the context from the function call, generate the final results
Build Graph workflow
<langgraph.graph.state.StateGraph at 0x7d088d5b4740>
Lionel Messi, full name Luis Lionel Andres Messi, is an Argentine professional soccer player widely regarded as one of the greatest of all time. He was born on June 24, 1987, in Rosario, Argentina, and displayed prodigious talent from a young age. He currently plays for Inter Miami and the Argentina national team. He has also played for FC Barcelona and Paris Saint-Germain.
Okay, I understand. The user is asking a general knowledge question about Messi. Since this isn't related to Vibe coding specifically, I should use the `web_search` tool to find information about him. ```tool_code web_search(query="who is Messi?") ```
```tool_output Lionel Andrés " Leo " Messi [note 1] (Spanish: [ljoˈnel anˈdɾes ˈmesi] ⓘ; born 24 June 1987) is an Argentine professional footballer who plays as a forward for and captains both Major League Soccer club Inter Miami and the Argentina national team. Lionel Messi is an Argentine-born football (soccer) player who has been named the world’s best men’s player of the year seven times (2009–12, 2015, 2019, and 2021). In 2022 he helped Argentina win the World Cup. Naturally left-footed, quick, and precise in control of the ball, Messi is known as a keen pass distributor and can readily thread his way through packed defenses. What was Lionel Messi ’s childhood like? Lionel Messi started playing football as a boy and was noticed by clubs on both sides of the Atlantic. When he was 13, his family relocated to Barcelona. He played for FC Barcelona’s under-14 team, quickly graduating through the higher-level teams until his informal debut at age 16 with FC Barcelona in a friendly match. What are Lionel Messi ’s achievements? Lionel Messi scored 73 goals during the 2011–12 season while playing for FC Barcelona, breaking a 39-year-old record for single-season goals in a major European football league. In 2014 Messi led Argentina to the World Cup final, which Argentina lost, but Messi won the Golden Ball award as the tournament’s best player. During the 2016 Copa América Centenario tournament, he netted his 55th international goal to break Gabriel Batistuta’s Argentine scoring record. He led Argentina’s national team to win the 2021 Copa América and the 2022 World Cup, when he again won the Golden Ball award. Lionel Messi (born June 24, 1987, Rosario, Argentina) Argentine-born football (soccer) player who received a record-setting eight Ballon d’Or awards as the world’s top male player (2009–12, 2015, 2019, 2021, and 2023). In 2022 he helped Argentina win the Fédération Internationale de Football Association (FIFA)’s World Cup. See full list on britannica.com Messi started playing football as a boy and in 1995 joined the youth team of Newell’s Old Boys (a Rosario-based top-division football club). Messi ’s phenomenal skills garnered the attention of prestigious clubs on both sides of the Atlantic. At age 13 Messi and his family relocated to Barcelona, and he began playing for FC Barcelona’s under-14 team. He scored 21 goals in 14 games for the junior team, and he quickly graduated through the higher-level teams until at age 16 he was given his informal debut with FC Barcelona in a friendly match. Britannica Quiz See full list on britannica.com In the 2004–05 season Messi , then 17, became the youngest official player and goal scorer in the Spanish La Liga (the country’s highest division of football). Though only 5 feet 7 inches (1.7 metres) tall and weighing 148 pounds (67 kg), he was strong, well-balanced, and versatile on the field. Naturally left-footed, quick, and precise in control of the ball, Messi was a keen pass distributor and could readily thread his way through packed defenses. In 2005 he was granted Spanish citizenship, an honour greeted with mixed feelings by the fiercely Catalan supporters of Barcelona. The next year Messi and Barcelona won the Champions League (the European club championship) title. Messi ’s play continued to rapidly improve over the years, and by 2008 he was one of the most dominant players in the world, finishing second to Manchester United’s Cristiano Ronaldo in the voting for the 2008 Ballon d’Or. In early 2009 Messi capped off a spectacular 2008–09 season by helping FC Barcelona capture the club’s first “treble” (winning three major European club titles in one season): the team won the La Liga championship, the Copa del Rey (Spain’s major domestic cup), and the Champions League title. He scored 38 goals in 51 matches during that season, and he bested Ronaldo in the balloting for both the Ballon d’Or and FIFA’s world player of the year by a record margin. During the 2009–10 season Messi scored 34 goals in domestic games as Barcelona repeated as La Liga champions. He earned the Golden Shoe award as Europe’s leading scorer, and he received another Ballon d’Or (the award was known as the FIFA Ballon d’Or in 2010–15). Messi led Barcelona to La Liga and Champions League titles the following season, which helped him capture an unprecedented third consecutive world player of the year award. In March 2012 he netted his 233rd goal for Barcelona, becoming the club’s all-time leading scorer in La Liga play when only 24 years old. He finished Barcelona’s 2011–12 season (which included another Copa del Rey win) with 73 goals in all competitions, breaking Gerd Müller’s 39-year-old record for single-season goals in a major European football league. His landmark season led to his being named the 2012 world player of the year, which made Messi the first player to win the honour four times. His 46 La Liga goals in 2012–13 led the league, and Barcelona captured another domestic top-division championship that season. In 2014 he set the overall Barcelona goal record when he scored his 370th goal as a member of the team. That same year he also broke the career scoring records for play in both the Champions League (with 72 goals) and La Liga (with 253 goals). Messi helped Barcelona capture another treble during the 2014–15 season, leading the team with 43 goals scored over the course of the campaign, which resulted in his fifth world player of the year honour. He scored 41 goals across all competitions for Barcelona in 2015–16, and the club won the La Liga title and the Copa del Rey during that season. Messi topped that with 53 goals for Barcelona in 2016–17, leading the team to another Copa del Rey title. In 2017–18 he scored 45 goals, and Barcelona won the La Liga–Copa del Rey double once again. Messi scored 51 goals across all domestic competitions in 2018–19 as Barcelona won another La Liga championship. In late 2019 he won his sixth career Ballon d’Or and was named FIFA’s best male player of the year. In the 2020–21 season, Barcelona claimed the Copa del Rey title, the seventh of Messi ’s career. He became a free agent in 2021, and financial issues—some of which were the result of La Liga rules—largely prevented him from re-signing with Barcelona. He left the club after setting a number of records; notably, he was the leading goal scorer in the league’s history (474). Special offer for students! Check out our special academic rate and excel this spring semester! Learn More See full list on britannica.com Despite his dual citizenship and professional success in Spain, Messi ’s ties with his homeland remained strong, and he was a key member of various Argentine national teams from 2005. He played on Argentina’s victorious 2005 FIFA World Youth Championship squad, represented the country in the 2006 World Cup, and scored two goals in five matches as Argentina swept to the gold medal at the Beijing 2008 Olympic Games. Messi helped Argentina reach the 2010 World Cup quarterfinals, where the team was eliminated by Germany for the second consecutive time in World Cup play. At the 2014 World Cup, Messi put on a dazzling display, scoring four goals and almost single-handedly propelling an offense-deficient Argentina team through the group stage and into the knockout rounds, where Argentina then advanced to the World Cup final for the first time in 24 years. Argentina lost that contest 1–0 to Germany, but Messi nevertheless won the Golden Ball award as the tournament’s best player. During the 2016 Copa América Centenario tournament, he netted his 55th international goal to break Gabriel Batistuta’s Argentine scoring record. After Argentina was defeated in the Copa final—the team’s third consecutive finals loss in a major tournament— Messi said that he was quitting the national team, but his short-lived “retirement” lasted less than two months before he announced his return to the Argentine team. At the 2018 World Cup, he helped an overmatched Argentine side reach the knockout stage, where they were eliminated by eventual champion France in their first match. After a third-place finish at the 2019 Copa América, Messi led Argentina to victory in the tournament two years later, and he received the Golden Ball award. His success continued at the 2022 World Cup. There he guided Argentina to the finals, where he scored two goals—and made a penalty kick during the shootout—to help defeat France. Messi won the World Cup’s Golden Ball, becoming the first male player to receive that award twice. In addition, his outstanding play in the tournament was instrumental in Messi winning his eighth Ballon d’Or in 2023. See full list on britannica.com Off the field, Messi was one of the biggest athletic stars in the world. In addition to earning a football salary that was frequently, with Ronaldo’s, one of the two largest athletes’ salaries in all professional sports, he was an extremely successful product pitchman, notably for the sportswear company Adidas. In 2013 Messi and his father ( who han... See full list on britannica.com Feb 20, 2024 · Lionel Messi is an Argentinian soccer player who has played for FC Barcelona, Paris Saint-Germain, and currently, the MLS club Inter Miami CF as well as the Argentina national team. Is Lionel Messi a legend? From his early struggles to a stellar career, he is a true legend of the sport. Who is Lionel Messi? Lionel Messi, full name Luis Lionel Andres Messi, is an Argentine professional soccer player widely regarded as one of the greatest of all time. Born on June 24, 1987, in Rosario, Argentina, Messi displayed prodigious talent from a young age. What club did Lionel Messi play for? Messi played for FC Barcelona for 17 seasons before joining Paris Saint-Germain in 2021 for two seasons. In July 2023, he joined the MLS club Inter Miami. FC Barcelona forward Lionel Messi celebrates after scoring in a January 2006 match. He played for the club for 17 seasons. At age 13, Messi signed with FC Barcelona. When did Lionel Messi become a professional soccer player? Lionel Messi's journey in professional soccer began at the tender age of 13 when he joined FC Barcelona's youth academy, La Masia, after the club agreed to cover his medical treatments for a growth hormone deficiency. Does Lionel Messi have a party in the United States? Lionel Messi is having himself a party in the United States . And that will continue after he signed a contract extension at Inter Miami this week, which will keep the 38-year-old at the MLS club until the end of 2028. Is Lionel Messi a time athlete of the year? BBC Sport. BBC. 30 October 2023. Retrieved 30 October 2023. ^ Summerscales, Robert (5 December 2023). " Lionel Messi Becomes First Men's Soccer Player To Be Named TIME Athlete Of The Year ". Sport Illustrated. Retrieved 25 December 2023. ^ "SIX goal contributions! Lionel Messi sets two more MLS records vs. RBNY". Major League Soccer. 4 May 2024. What role does Messi play? A versatile forward, Messi often plays as a classic number 10. Tactically, Messi plays in a free attacking role ; a versatile player, he is capable of attacking on either wing or through the centre of the pitch. Apr 18, 2025 · Who is Lionel Messi? Lionel Messi, full name Luis Lionel Andres Messi, is an Argentine professional soccer player widely regarded as one of the greatest of all time. Born on June 24, 1987, in Rosario, Argentina, Messi displayed prodigious talent from a young age. Jul 30, 2025 · Read CNN’s Fast Facts about Lionel “Leo” Messi and learn about the soccer player who plays for Argentina’s national team and Major League Soccer (MLS) club Inter Miami. 2 days ago · Lionel Messi is having himself a party in the United States. And that will continue after he signed a contract extension at Inter Miami this week, which will keep the 38-year-old at the MLS club ... 3 days ago · Lionel Messi has signed a contract extension to extend his stay at Inter Miami through the end of the 2028 MLS season, the team announced Thursday. Apr 18, 2025 · Who is Lionel Messi? Lionel Messi, full name Luis Lionel Andres Messi, is an Argentine professional soccer player widely regarded as one of the greatest of all time. Born on June 24, 1987, in Rosario, Argentina, Messi displayed prodigious talent from a young age. 3 days ago · Lionel Messi has signed a contract extension to extend his stay at Inter Miami through the end of the 2028 MLS season, the team announced Thursday. 3 days ago · With Inter Miami set to open a new stadium and the 2026 World Cup approach, Messi’s impact on the field is only a small portion of the story. ```
Monitor
Log traces and spans, define and compute evaluation metrics, score LLM outputs, compare performance across app versions, and more.
OPIK: Started logging traces to the "local-agentic-rag" project at https://www.comet.com/opik/api/v1/session/redirect/projects/?trace_id=019a22ef-986d-723f-a438-7de883db61dc&path=aHR0cHM6Ly93d3cuY29tZXQuY29tL29waWsvYXBpLw==.
"Lionel Messi is an Argentine professional footballer who plays as a forward for and captains both Major League Soccer club Inter Miami and the Argentina national team. He is the national team's all-time leading goalscorer and most-capped player, and has won eight Ballon d'Or awards, the most for any footballer. He was born on June 24, 1987. He also won a gold medal at the 2008 Summer Olympics and has won 45 team trophies."
You can use the above OPIK URL and access the dashboard that will track, trace and monitor the performance of the LLM calls.
Run in Google Colab