Skip to main content

Installation

Install AG2 with Gemini features:

Dependencies of This Notebook

In this notebook, we will explore how to use Gemini in AG2 alongside other tools. Install the necessary dependencies with the following command:
If you have been using autogen or ag2, all you need to do is upgrade it using:
or
as autogen and ag2 are aliases for the same PyPI package.

Features

There’s no need to handle OpenAI or Google’s GenAI packages separately; AG2 manages all of these for you. You can easily create different agents with various backend LLMs using the assistant agent. All models and agents are readily accessible at your fingertips. Support features:
  • Function/tool calling
  • Structured Outputs (Notebook example)
  • Token usage and cost correctly as per Google’s API costs (as of December 2024)

Main Distinctions

  • Gemini accepts system instructions to guide model behavior. If provided, a system message is passed to Gemini’s system_instruction field.
  • If no API key is specified for Gemini, then authentication will happen using the default google auth mechanism for Google Cloud. Service accounts are also supported, where the JSON key file has to be provided.
Sample OAI_CONFIG_LIST
You can put your Google Gemini API key in an environment variable named GOOGLE_GEMINI_API_KEY instead of using the api_key in your LLM configuration.For guidance on using environment variables, see our LLMs documentation.

Gemini coding example

Gemini vision example

Gemini’s models have vision capabilitiesso we can create multimodal agents. Here, we ask a question about Coding Example