Skip to content

[Bug]: PostgresChatStore throws serialization error when storing chat history: "Unable to serialize unknown type: <class 'google.ai.generativelanguage_v1beta.types.content.FunctionCall'>" #19992

@Thanveer1086

Description

@Thanveer1086

Bug Description

When using PostgresChatStore to persist chat history with a FunctionAgent that uses Google's Generative AI (Gemini), the application throws a serialization error when attempting to store messages containing function calls.
Error Message:
pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'google.ai.generativelanguage_v1beta.types.content.FunctionCall'>

Version

0.14.3

Steps to Reproduce

chat_store = SerializableChatStore.from_uri(
uri="postgresql+asyncpg://postgres:[email protected]:5432/TestDB",
)

chat_memory = ChatMemoryBuffer.from_defaults(
token_limit=3000,
chat_store=chat_store,
chat_store_key="user2",
)

Relevant Logs/Tracbacks

Traceback (most recent call last):
  File "D:\workspace\Agentic-RAG-with-LangChain\Agent_over_RAG_2.py", line 204, in <module>
    asyncio.run(run_agent_query(query_str))
  File "C:\Users\Thanveer\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\Thanveer\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Thanveer\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "D:\workspace\Agentic-RAG-with-LangChain\Agent_over_RAG_2.py", line 172, in run_agent_query
    result = await agent.run(query, memory=chat_memory)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\Agentic-RAG-with-LangChain\venv\Lib\site-packages\workflows\workflow.py", line 407, in _run_workflow
    raise exception_raised
  File "D:\workspace\Agentic-RAG-with-LangChain\venv\Lib\site-packages\workflows\context\context.py", line 822, in _step_worker
    new_ev = await instrumented_step(**kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\Agentic-RAG-with-LangChain\venv\Lib\site-packages\llama_index_instrumentation\dispatcher.py", line 386, in async_wrapper
    result = await func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\Agentic-RAG-with-LangChain\venv\Lib\site-packages\llama_index\core\agent\workflow\base_agent.py", line 435, in parse_agent_output
    output = await self.finalize(ctx, ev, memory)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\Agentic-RAG-with-LangChain\venv\Lib\site-packages\llama_index\core\agent\workflow\function_agent.py", line 189, in finalize
    await memory.aput_messages(scratchpad)
  File "D:\workspace\Agentic-RAG-with-LangChain\venv\Lib\site-packages\llama_index\core\memory\types.py", line 63, in aput_messages
    await asyncio.to_thread(self.put_messages, messages)
  File "C:\Users\Thanveer\AppData\Local\Programs\Python\Python312\Lib\asyncio\threads.py", line 25, in to_thread
    return await loop.run_in_executor(None, func_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Thanveer\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\Agentic-RAG-with-LangChain\venv\Lib\site-packages\llama_index\core\memory\types.py", line 59, in put_messages
    self.put(message)
  File "D:\workspace\Agentic-RAG-with-LangChain\venv\Lib\site-packages\llama_index\core\memory\types.py", line 130, in put
    self.chat_store.add_message(self.chat_store_key, message)
  File "D:\workspace\Agentic-RAG-with-LangChain\venv\Lib\site-packages\llama_index\storage\chat_store\postgres\base.py", line 260, in add_message
    params = {"key": key, "value": [message.model_dump_json()]}
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\workspace\Agentic-RAG-with-LangChain\venv\Lib\site-packages\pydantic\main.py", line 519, in model_dump_json
    return self.__pydantic_serializer__.to_json(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'google.ai.generativelanguage_v1beta.types.content.FunctionCall'>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageIssue needs to be triaged/prioritized

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions