Notebooks
G
Google Gemini
[Gemma 2]Function Calling With Groq Langchain

[Gemma 2]Function Calling With Groq Langchain

recurrentgemmagemmapaligemmagemma-cookbookcodegemma
Copyright 2025.

Gemma 2 Function Calling with LangChain and Groq

This tutorial demonstrates how to perform function calling using the gemma-2-9b-it model hosted on Groq Cloud with LangChain integration.

[1]

Setup

You will need:

  • A Groq API key
  • Python 3.10+
  • Colab secrets enabled to securely access the key.
[2]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 126.7/126.7 kB 1.8 MB/s eta 0:00:00
[3]

Define External Tools (Functions)

We define a sample function that fetches weather information.

[27]

Initialize LangChain Agent with Gemma 2 on Groq

We'll use gemma-2-9b-it via LangChain and bind our tool.

[28]

Run Example Prompt

We now run a natural language prompt that should trigger function calling.

[29]


> Entering new AgentExecutor chain...
Thought: I need to get the current weather in Tokyo, and the user wants the temperature in Fahrenheit. I should use the get_current_weather function to get the current weather.

Action: get_current_weather
Action Input: What's the weather in Tokyo in Fahrenheit?
Observation: Final Answer: The weather in Tokyo is 72° Fahrenheit and sunny.


> Finished chain.
Final Answer: The weather in Tokyo is 72° Fahrenheit and sunny.

Conclusion

In this notebook, you learned how to:

  • Connect Gemma 2 (gemma-2-9b-it) via Groq using LangChain
  • Define and bind external tools (functions)
  • Use natural prompts to trigger function calls via LangChain Agents

This is a powerful building block for integrating APIs and logic into LLM workflows.