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

Phidata memory storage fails with Gemini models #1696

Closed
renatomorenocz opened this issue Jan 4, 2025 · 3 comments
Closed

Phidata memory storage fails with Gemini models #1696

renatomorenocz opened this issue Jan 4, 2025 · 3 comments
Labels

Comments

@renatomorenocz
Copy link

When using the Gemini model with function call enabled, the storage fails with the error:

Exception upserting into table: Object of type RepeatedComposite is not JSON serializable

Steps to Reproduce

  1. Use the example script provided below.
  2. Configure Gemini as the model and PgAgentStorage or SqlLite for storage.
  3. Run the script.

Environment

Phi Version: 2.7.6
Python Version: 3.12.6

import os

from dotenv import load_dotenv
from phi.agent import Agent
from phi.model.google import Gemini
from phi.storage.agent.postgres import PgAgentStorage

load_dotenv()
database_url = os.getenv("POSTGRES_CONNECTION", "")


agent = Agent(
  debug_mode=True,
  role="Your a helpful assistant",
  markdown=True,
  model=Gemini(api_key=os.getenv("GOOGLE_API_KEY"), id="gemini-2.0-flash-exp"),
  storage=PgAgentStorage(table_name="web_agent", schema="public", db_url=database_url, auto_upgrade_schema=True),
  # storage=sqlitestorage,
  add_history_to_messages=True,
  num_history_responses=5,
  read_chat_history=True,
  # Tools
  show_tool_calls=True,
  tool_call_limit=20,
  read_tool_call_history=True,
  add_datetime_to_instructions=True,
  prevent_hallucinations=True,
  monitoring=True,
  stream_intermediate_steps=False,
)


def main():
  agent.run("How many messages did I send?")


if __name__ == "__main__":
  main()

Debug output

DEBUG    Debug logs enabled                                                                                                                                                                                                                                                               
DEBUG    *********** Agent Run Start: 3c932284-710e-4768-8e7b-8f1a1a7205c3 ***********                                                                                                                                                                                                    
DEBUG    Function 'get_chat_history' added to model.                                                                                                                                                                                                                                      
DEBUG    Function 'get_tool_call_history' added to model.                                                                                                                                                                                                                                 
DEBUG    Getting messages from last 5 runs                                                                                                                                                                                                                                                
DEBUG    Messages from last 5 runs: 0                                                                                                                                                                                                                                                     
DEBUG    ---------- Gemini Response Start ----------                                                                                                                                                                                                                                      
DEBUG    ============== system ==============                                                                                                                                                                                                                                             
DEBUG    Your role is: Your a helpful assistant                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                          
         ## Instructions                                                                                                                                                                                                                                                                  
         - **Do not make up information:** If you don't know the answer or cannot determine from the provided references, say 'I don't know'.                                                                                                                                             
         - Use markdown to format your answers.                                                                                                                                                                                                                                           
         - The current time is 2025-01-04 15:59:04.205918                                                                                                                                                                                                                                 
DEBUG    ============== user ==============                                                                                                                                                                                                                                               
DEBUG    How many messages did I send?                                                                                                                                                                                                                                                    
DEBUG    ============== model ==============                                                                                                                                                                                                                                              
DEBUG    I can only see the chat history, which includes both your messages and my messages. If you want, I can count how many messages are in the chat history. Would you like me to do that?                                                                                            
                                                                                                                                                                                                                                                                                          
DEBUG    **************** METRICS START ****************                                                                                                                                                                                                                                  
DEBUG    * Time to generate response:   1.5482s                                                                                                                                                                                                                                           
DEBUG    * Tokens per second:           27.1279 tokens/s                                                                                                                                                                                                                                  
DEBUG    * Input tokens:                422                                                                                                                                                                                                                                               
DEBUG    * Output tokens:               42                                                                                                                                                                                                                                                
DEBUG    * Total tokens:                464                                                                                                                                                                                                                                               
DEBUG    **************** METRICS END ******************                                                                                                                                                                                                                                  
DEBUG    ---------- Gemini Response End ----------                                                                                                                                                                                                                                        
DEBUG    Added 2 Messages to AgentMemory                                                                                                                                                                                                                                                  
DEBUG    Added AgentRun to AgentMemory                                                                                                                                                                                                                                                    
DEBUG    Exception upserting into table: Object of type RepeatedComposite is not JSON serializable                                                                                                                                                                                        
DEBUG    Checking if table exists: web_agent                                                                                                                                                                                                                                              
DEBUG    --**-- Logging Agent Run                                                                                                                                                                                                                                                         
DEBUG    *********** Agent Run End: 3c932284-710e-4768-8e7b-8f1a1a7205c3 ***********    
@ysolanky
Copy link
Contributor

ysolanky commented Jan 6, 2025

Hello @renatomorenocz !

Sorry about this. It is a known issue and we are working on a fix. Hoping to share updates soon.

@mstrYoda
Copy link

mstrYoda commented Jan 8, 2025

I got a similar issue:

DEBUG    ============== tool ==============                                                                                                                                                                      
DEBUG    ['[\n  {\n    "title": "11 Best Hotels in Fatih, \\u0130stanbul",\n    "url": "https://www.agoda.com/fatih/maps/istanbul-tr.html",\n    "description": "Sultanahmet is also home to many great hotels,  
         including the Otantik Hotel and the Porta Romanos Hotel. Another great neighborhood to stay in is Balat, which is\\u00a0..."\n  },\n  {\n    "title": "The best hotels in Fatih, Istanbul, Turkey",\n   
         "url": "https://www.booking.com/district/tr/istanbul/fatih.html",\n    "description": "Featured Hotels in Fatih ; Bentley Hotel Old City-Special Class \\u00b7 9.3. Wonderful . 1,245 reviews ; Rayelin 
         Hotel Istanbul Old City \\u00b7 9.2. Wonderful . 1,108 reviews."\n  },\n  {\n    "title": "Best 10 Hotels Near Fatih: Luxury Accommodation",\n    "url":                                                
         "https://www.safaraq.com/en/turkey/blog/the-best-hotels-in-fatih",\n    "description": "Dec 27, 2024 \\u2014 1. Royal Hotel \\u00b7 2. Ramada Hotel \\u00b7 3. Holiday Inn Hotel \\u00b7 4. Barcelo     
         Istanbul \\u00b7 5. Akgun Istanbul Hotel \\u00b7 6. All Seasons Hotel \\u00b7 7. Topkapi Hotel \\u00b7 8."\n  },\n  {\n    "title": "HOTEL FATIH ISTANBUL - Prices & Reviews (T\\u00fcrkiye)",\n        
         "url": "https://www.tripadvisor.com/Hotel_Review-g293974-d3620231-Reviews-Hotel_Fatih_Istanbul-Istanbul.html",\n    "description": "Hotel Fatih Istanbul is an excellent choice for travelers visiting  
         Istanbul, offering many helpful amenities designed to enhance your stay."\n  }\n]']                                                                                                                     
DEBUG    ============== model ==============                                                                                                                                                                     
DEBUG    I am sorry, but I could not find a list of hotels with ratings in the search results.  The search results provided links to pages that may contain hotel information, but they don't present a          
         structured list of 10 hotels with ratings in a readily extractable format.  To get the information you need, I would need access to hotel review APIs or web scraping capabilities, which are not       
         currently available.                                                                                                                                                                                    
                                                                                                                                                                                                                 
DEBUG    **************** METRICS START ****************                                                                                                                                                         
DEBUG    * Time to generate response:   1.9339s                                                                                                                                                                  
DEBUG    * Tokens per second:           43.9525 tokens/s                                                                                                                                                         
DEBUG    * Input tokens:                1548                                                                                                                                                                     
DEBUG    * Output tokens:               85                                                                                                                                                                       
DEBUG    * Total tokens:                1633                                                                                                                                                                     
DEBUG    **************** METRICS END ******************                                                                                                                                                         
DEBUG    ---------- Gemini Response End ----------                                                                                                                                                               
DEBUG    Added 4 Messages to AgentMemory                                                                                                                                                                         
DEBUG    Added AgentRun to AgentMemory                                                                                                                                                                           
DEBUG    Exception upserting into table: (builtins.TypeError) Object of type RepeatedComposite is not JSON serializable                                                                                          
         [SQL: INSERT INTO agent_sessions (session_id, agent_id, user_id, memory, agent_data, user_data, session_data, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT (session_id) DO UPDATE SET        
         agent_id = ?, user_id = ?, memory = ?, agent_data = ?, user_data = ?, session_data = ?, updated_at = ?]                                                                                                 
         [parameters: [{}]]                                                                                                                                                                                      
DEBUG    Checking if table exists: agent_sessions                                                                                                                                                                
DEBUG    Table does not exist: agent_sessions                                                                                                                                                                    
DEBUG    Creating table and retrying upsert                                                                                                                                                                      
DEBUG    Checking if table exists: agent_sessions                                                                                                                                                                
DEBUG    Creating table: agent_sessions                                                                                                                                                                          
DEBUG    Exception upserting into table: (builtins.TypeError) Object of type RepeatedComposite is not JSON serializable                                                                                          
         [SQL: INSERT INTO agent_sessions (session_id, agent_id, user_id, memory, agent_data, user_data, session_data, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT (session_id) DO UPDATE SET        
         agent_id = ?, user_id = ?, memory = ?, agent_data = ?, user_data = ?, session_data = ?, updated_at = ?]                                                                                                 
         [parameters: [{}]]                                                                           

image

Copy link

This issue has been automatically marked as stale due to 14 days of inactivity and will now be closed.

@github-actions github-actions bot added the stale label Jan 23, 2025
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants