Skip to content

feat: Add tool_calls support to JdbcChatMemoryRepository #3343

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

astor-dev
Copy link

Description

This PR implements support for persisting tool_calls in JdbcChatMemoryRepository to resolve issues with tool calling functionality in JDBC-based chat memory implementations.

Issues Addressed

Fixes #3342 - Support persisting tool_calls in JdbcChatMemoryRepository

It can also serve as a preliminary step to fix the issues below:
#3339 - ToolResponseMessage results in null content, causing SQLIntegrityConstraintViolationException

Changes

Database Schema

  • Added tool_calls column to all database schemas (PostgreSQL, MySQL, SQL Server, HSQLDB)
  • PostgreSQL uses JSONB type with explicit ::jsonb casting
  • Other databases use TEXT/LONGVARCHAR for JSON storage

Implementation

  • Serialize List<AssistantMessage.ToolCall> to JSON on insert
  • Deserialize tool calls when loading from database
  • Updated all dialect classes to include tool_calls in SELECT and INSERT queries
  • Added error handling for malformed JSON with warning logs

Database Dialects Updated

  • PostgresChatMemoryRepositoryDialect
  • MysqlChatMemoryRepositoryDialect
  • SqlServerChatMemoryRepositoryDialect
  • HsqldbChatMemoryRepositoryDialect

@astor-dev astor-dev force-pushed the feat-jdbc-memory-tool-calls branch from cbf3844 to f11ac75 Compare May 27, 2025 05:41
- Add tool_calls column to all database schemas (PostgreSQL, MySQL, SQL Server, HSQLDB)

- Implement JSON serialization/deserialization for AssistantMessage.ToolCall objects

- Update all dialect classes to include tool_calls in SELECT and INSERT queries

- Add PostgreSQL JSONB type support with explicit casting (::jsonb)

- Add comprehensive unit tests for tool calls functionality

- Add integration tests for tool calls across all supported databases

- Maintain backward compatibility with existing chat memory data

This enhancement allows the JDBC chat memory repository to persist and retrieve tool call information from AI assistant messages, enabling full conversation context preservation including function calls and their metadata.

Signed-off-by: astor-dev <[email protected]>
@astor-dev astor-dev force-pushed the feat-jdbc-memory-tool-calls branch from f11ac75 to 18eda40 Compare May 28, 2025 00:04
@markpollack
Copy link
Member

Thanks for this, I need to spend more time reviewing this, but in the 1.0.x branch we won't be able to merge any schema breaking changed, we can for 1.1.x No firm timeline on the 1.1.x release date yet, just starting to review what we can do and publish a public roadmap.

@markpollack markpollack added this to the 1.1.x milestone May 29, 2025
case ASSISTANT -> new AssistantMessage(content);
case ASSISTANT -> {
List<AssistantMessage.ToolCall> toolCalls = List.of();
if (toolCallsJson != null && !toolCallsJson.trim().isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trim() is not aware of unicode whitespace characters and so strip() is the preferred way to remove whitespace characters since Java 11.

For this specific case, you can use isBlank() which is available since Java 11 and also unicode aware.

Suggested modification:

- !toolCallsJson.trim().isEmpty()
+ !toolCallsJson.isBlank()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, updated to isBlank() as suggested. Thanks!

…icode whitespace in JdbcChatMemoryRepository

Signed-off-by: astor-dev <[email protected]>
@astor-dev astor-dev force-pushed the feat-jdbc-memory-tool-calls branch from d4aee39 to 54da813 Compare May 31, 2025 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support persisting tool_calls in JdbcChatMemoryRepository
3 participants