# I prove to use agent ai with gemini but give a value error and it want an openaikey

**URL:** <https://community.crewai.com/t/i-prove-to-use-agent-ai-with-gemini-but-give-a-value-error-and-it-want-an-openaikey/3146>\
**Category:** CrewAI Community Support\
**Tags:** agent\
**Created:** [January 23, 2025, 8:08am UTC](https://community.crewai.com/t/i-prove-to-use-agent-ai-with-gemini-but-give-a-value-error-and-it-want-an-openaikey/3146 "2025-01-23T08:08:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mattia\_Castiello](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/mattia_castiello/32/2208_2.png) [@Mattia\_Castiello](https://community.crewai.com/u/Mattia_Castiello)\
**Post date:** [January 23, 2025, 8:08am UTC](https://community.crewai.com/t/i-prove-to-use-agent-ai-with-gemini-but-give-a-value-error-and-it-want-an-openaikey/3146/1 "2025-01-23T08:08:11Z")

</div>

from crewai import Agent, Task, Crew, LLM  
from dotenv import load\_dotenv  
load\_dotenv()  
from langchain\_google\_genai import ChatGoogleGenerativeAI  
import os

‘’‘llm=ChatGoogleGenerativeAI(model=“gemini-1.5-pro”,  
verbose=True,  
temperature=0.5,  
google\_api\_key=os.getenv(’…'),  
)

llm = LLM(  
model=“gemini-1.5-pro”,  
base\_url= “[https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=GEMINI\_API\_KEY](https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=GEMINI_API_KEY)”,  
os.environ[“GEMINI\_API\_KEY”] = “AIzaSyDS\_ZRVF7CvEAtExVlhqXfRNBatY-Vyw3I”

)  
‘’’  
‘’’  
api\_gemini = os.environ.get(“GEMINI-API-KEY”)

llm = ChatGoogleGenerativeAI(  
model=“gemini-pro”, verbose=True, temperature=0.1, google\_api\_key=api\_gemini  
)  
‘’’

# Definizione degli agenti

triage\_agent = Agent(  
role=“Assistente di Triage in Sicurezza Informatica”,  
goal=(  
"Identificare possibili attacchi (ransomware, phishing, smishing, DoS, defacement, USB) "  
“e delegare a un agente specializzato se necessario.”  
),  
backstory=(  
"Sei un esperto di sicurezza informatica incaricato di diagnosticare "  
"diverse tipologie di attacchi informatici. "  
"Poni sempre una sola domanda alla volta e attendi la risposta "  
"dell’utente prima di procedere. "  
“Se riconosci i sintomi di un certo attacco, delega il lavoro all’agente corrispondente.”  
),  
verbose=True,  
llm=LLM(  
model=“gemini/gemini-1.5-flash”,  
temperature=0.5,  
),  
allow\_delegation=True  
)

ransomware\_agent = Agent(  
role=“Esperto in Ransomware”,  
goal=“Guidare l’utente nel mitigare un attacco ransomware e proteggere i dati”,  
backstory=(  
"Sei un assistente esperto in sicurezza informatica, specializzato nella gestione di incidenti ransomware. "  
"Aiuta l’utente a identificare, contenere e mitigare l’attacco, proteggendo i dati "  
"e raccogliendo informazioni per eventuali analisi successive. "  
“Fornisci istruzioni pratiche e poni sempre una sola domanda alla volta.”  
),  
verbose=True,  
llm=LLM(  
model=“gemini/gemini-1.5-flash”,  
temperature=0.5,  
),  
allow\_delegation=False

)

# Definizione dei task

diagnosi\_iniziale = Task(  
description=(  
"Il TriageAgent deve chiedere all’utente: "Cosa c’è che non va con il tuo PC?" "  
"e capire in base ai sintomi se potrebbe trattarsi di Ransomware (o altro). "  
“Se capisce che è Ransomware, delega il lavoro al RansomwareAgent.”  
),  
expected\_output=(  
“1) Una domanda iniziale all’utente;\n”  
"2) Se trova parole chiave legate a Ransomware (‘riscatto’, ‘file criptati’, ‘estensione strana’), "  
“delega a RansomwareAgent.”  
),  
agent=triage\_agent  
)

ransomware\_handling = Task(  
description=(  
"Se il triage rivela un attacco Ransomware, questo task va al RansomwareAgent. "  
"Fai domande mirate (installazioni sospette, estensioni, file di riscatto), "  
"istruisci a disconnettere il device dalla rete, non spegnere il PC, e fornisci linee guida su segnalazione "  
“ed eventuali best practice (backup, cambi password, ecc.).”  
),  
expected\_output=(  
“Fornisci un supporto passo-passo per mitigare il Ransomware, facendo UNA domanda alla volta.”  
),  
agent=ransomware\_agent  
)

# Configura il Crew

crew = Crew(  
agents=[triage\_agent, ransomware\_agent],  
tasks=[  
diagnosi\_iniziale,  
ransomware\_handling,  
],  
memory=True # conserva il contesto  
)

# Funzione principale

def main():  
print(“=== Assistente Triage & Ransomware (gemini-1.5-pro) ===”)  
print(“Digita ‘exit’ o ‘quit’ per uscire.\n”)

```
# Interazione con l'utente
current_task = diagnosi_iniziale
while True:
    user_message = input("Tu: ")
    if user_message.lower() in ["exit", "quit"]:
        print("Fine. Grazie e arrivederci!")
        break

    # Passa il messaggio al task corrente
    result = current_task.run({"user_input": user_message})
    print("Assistente:", result, "\n")

    # Passa al prossimo task se delegato
    if current_task.agent.delegate_to:
        current_task = ransomware_handling

```

if **name** == “ **main** ”:  
main()

and give me this error  
LLM value is already an LLM object  
LLM value is already an LLM object  
Traceback (most recent call last):  
File “/Users/mattiacastiello/Desktop/crewAI/agenticrewAi.py”, line 98, in   
crew = Crew(  
^^^^^  
File “/opt/anaconda3/envs/pacy/lib/python3.12/site-packages/pydantic/main.py”, line 214, in **init**  
validated\_self = self. **pydantic\_validator**.validate\_python(data, self\_instance=self)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
pydantic\_core.\_pydantic\_core.ValidationError: 1 validation error for Crew  
Value error, Please provide an OpenAI API key. You can get one at [https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys) [type=value\_error, input\_value={‘agents’: [Agent(role=As…olta.)], ‘memory’: True}, input\_type=dict]

---

<div class="post-metadata">

**Author:** ![Tomasz](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@Tomasz](https://community.crewai.com/u/Tomasz)\
**Post date:** [January 23, 2025, 9:33am UTC](https://community.crewai.com/t/i-prove-to-use-agent-ai-with-gemini-but-give-a-value-error-and-it-want-an-openaikey/3146/2 "2025-01-23T09:33:43Z")

</div>

It looks like the problem is in the os.getenv() function call. Instead of the value of the key, its name should be ‘GEMINI\_API\_KEY’  
(remove the key value from the code for security & privacy reason)  
so the correct line of code should be as follows:

google\_api\_key=os.getenv(‘GEMINI\_API\_KEY’)

The second issue is the name of the GEMINI\_API\_KEY key. It looks like you have two different names for the same environment variable

GEMINI\_API\_KEY  
GEMINI-API-KEY

Perhaps this is the second source of the problem

Improve the code and maybe it will start working, although I still suspect problems with the model aisles. but maybe it will come out later.

Tomasz

---

<div class="post-metadata">

**Author:** ![Mattia\_Castiello](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/mattia_castiello/32/2208_2.png) [@Mattia\_Castiello](https://community.crewai.com/u/Mattia_Castiello)\
**Post date:** [January 23, 2025, 10:04am UTC](https://community.crewai.com/t/i-prove-to-use-agent-ai-with-gemini-but-give-a-value-error-and-it-want-an-openaikey/3146/3 "2025-01-23T10:04:56Z")

</div>

thanks but it doesn’t work
