Prerequisites
Install Package
First, install PraisonAI Agents:
pip install "praisonaiagents[llm]"
praisonaiagents[llm] includes all Google Gemini dependencies.
For No-Code implementation, also install: pip install langchain-google-genai
Set API Key
Set your Gemini API key:
export GEMINI_API_KEY=xxxxxxxxxxx
Code
from praisonaiagents import Agent
agent = Agent(
instructions="You are a helpful assistant",
llm="gemini/gemini-1.5-flash-8b",
self_reflect=True,
verbose=True
)
agent.start("Why sky is Blue?")
Code Implementation
Basic Usage
The simplest way to use Gemini with PraisonAI Agents:
from praisonaiagents import Agent
agent = Agent(
instructions="You are a helpful assistant",
llm="gemini/gemini-1.5-flash-8b",
self_reflect=True,
verbose=True
)
agent.start("Why sky is Blue?")
Multi-Agent Setup
Create multiple agents working together:
from praisonaiagents import Agent, Task, PraisonAIAgents
agent = Agent(
instructions="You are a helpful assistant",
llm="gemini/gemini-1.5-flash-8b",
self_reflect=True,
verbose=True
)
task = Task(
description="Why sky is Blue?",
agent=agent,
)
agents = PraisonAIAgents(
agents=[agent],
tasks=[task],
)
agents.start()
This uses Litellm to connect to Google Gemini.
Gemini 2.0 Flash Thinking
LLM Configuration
llm_config = {
"model": "gemini/gemini-2.0-flash-thinking-exp-01-21",
"response_format": {"type": "text"} # type is text, because json_object is not supported
}
Install Package
Install required packages:
pip install "praisonaiagents[llm]"
Set API Key
Set your Gemini API key:
export GEMINI_API_KEY=xxxxxxxxxxx
Code
from praisonaiagents import Agent
llm_config = {"model": "gemini/gemini-2.0-flash-thinking-exp-01-21","response_format": {"type": "text"}}
agent = Agent(
instructions="You are a helpful assistant",
llm=llm_config
)
result = agent.start("Why sky is Blue?")
print(result)
Alternative Setup
Using Environment Variables
No-Code Implementation
pip install langchain-google-genai
export GOOGLE_API_KEY=xxxxxxxxxx
YAML Configuration
Create an agents.yaml
file:
framework: crewai
topic: create movie script about cat in mars
roles:
researcher:
backstory: Skilled in finding and organizing information, with a focus on research
efficiency.
goal: Gather information about Mars and cats
role: Researcher
llm:
model: "google/gemini-1.5-flash-001"
tasks:
gather_research:
description: Research and gather information about Mars, its environment,
and cats, including their behavior and characteristics.
expected_output: Document with research findings, including interesting facts
and information.
tools:
- ''
Additional Resources