Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Gemini agent with memory errors with empty formatted_messages #2164

Closed
jeffbryner opened this issue Feb 18, 2025 · 2 comments · Fixed by #2167
Closed

[Bug] Gemini agent with memory errors with empty formatted_messages #2164

jeffbryner opened this issue Feb 18, 2025 · 2 comments · Fixed by #2167
Assignees
Labels
bug Something isn't working

Comments

@jeffbryner
Copy link

Description

Was trying out the fixes for gemini in v1.1.4 and got a strange error once hooking up memory with sqlite to an agent.

Steps to Reproduce

Add tools, memory and storage to an agent and set everything to True:
create_user_memories=True,
create_session_summary=True, # seems especially troublesome
update_user_memories_after_run=True,
update_session_summary_after_run=True,

agent = Agent(
    model=model_flash,
    tools=[DuckDuckGoTools(), CsvTools(csvs=[imdb_csv])],
    markdown=True,
    show_tool_calls=True,
    telemetry=False,
    monitoring=False,
    instructions=[
        "You have a local CSV file named imdb.csv with IMDB movie data",
        "You can run a query with this csv file to answer questions.",
        "You can also search the internet with DuckDuckGo.",
    ],
    storage=SqliteAgentStorage(table_name="chat_agent", db_file=agent_storage),
    # Adds the current date and time to the instructions
    add_datetime_to_instructions=True,
    # Adds the history of the conversation to the messages
    add_history_to_messages=True,
    # Number of history responses to add to the messages
    num_history_responses=15,
    memory=AgentMemory(
        db=SqliteMemoryDb(db_file="tmp/agent_memory.db"),
        create_user_memories=True,
        create_session_summary=True,  # troublesome
        update_user_memories_after_run=True,
        update_session_summary_after_run=True,
        classifier=MemoryClassifier(model=model_flash),
        summarizer=MemorySummarizer(model=model_pro),
        manager=MemoryManager(model=model_flash),
    ),
)

Agent Configuration (if applicable)

Agent using the most recent gemini fixes.

Expected Behavior

Expected memory/session summaries to work

Actual Behavior

Odd error kept occurring:

    return self.get_client().models.generate_content(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jeffbryner/development/agno-playground/.venv/lib/python3.12/site-packages/google/genai/models.py", line 4672, in generate_content
    response = self._generate_content(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jeffbryner/development/agno-playground/.venv/lib/python3.12/site-packages/google/genai/models.py", line 3807, in _generate_content
    request_dict = _GenerateContentParameters_to_vertex(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jeffbryner/development/agno-playground/.venv/lib/python3.12/site-packages/google/genai/models.py", line 1180, in _GenerateContentParameters_to_vertex
    for item in t.t_contents(
                ^^^^^^^^^^^^^
  File "/Users/jeffbryner/development/agno-playground/.venv/lib/python3.12/site-packages/google/genai/_transformers.py", line 321, in t_contents
    raise ValueError('contents are required.')
ValueError: contents are required.

Environment

  • Agno Version: v1.1.4
  • External Dependency Versions: duckduck go tools, csv tools

Possible Solutions (optional)

A simple exit if empty will fix the issue for me locally:

        if not formatted_messages:
            return GenerateContentResponse()
        try:
            return self.get_client().models.generate_content(
                model=self.id,
                contents=formatted_messages,
                **request_kwargs,
            )
...

in each of the functions that gather formatted messages before calling the model

  • invoke
  • invoke_stream
  • ainvoke
  • ainvoke_stream

Additional Context

It appears that the

formatted_messages, system_message = self._format_messages(messages)

which is made before calling the gemini model

        try:
            return self.get_client().models.generate_content(
                model=self.id,
                contents=formatted_messages,
                **request_kwargs,
            )

can result in empty 'formatted_messages' .

When I added some logging I got logs showing calls with no messages:

INFO     Sending messages to Gemini model: []
@jeffbryner jeffbryner added the bug Something isn't working label Feb 18, 2025
@dirkbrnd dirkbrnd self-assigned this Feb 18, 2025
@pritipsingh
Copy link
Contributor

Hey @jeffbryner thanks for raising this. @dirkbrnd has a pr out to fix this. will be fixed in the next release!

dirkbrnd added a commit that referenced this issue Feb 19, 2025
This fixes an issue with using Gemini in the memory summarizer. 

Fixes #2164
@dirkbrnd
Copy link
Contributor

Hi!
This was fixed in release 1.1.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants