Skip to content

Suggestion: Database schema for conversations could be better #1385

@habema

Description

@habema

Right now, we're storing all the parts of a conversation (user messages, tool calls, tool outputs, AI responses) as a simple list of events in one table. Each event is basically a JSON blob.

Here's what it looks like:

id session_id message_data created_at
1 user_123 {"content": "What's the time?", "role": "user"} 2025-08-06 14:06:39
2 user_123 {"arguments": "{}", "call_id": "call_ErZ8...", "name": "get_server_time", "type": "function_call", "id": "fc_6893...", "status": "completed"} 2025-08-06 14:06:39
3 user_123 {"call_id": "call_ErZ8...", "output": "2025-08-06T17:06:37.796774", "type": "function_call_output"} 2025-08-06 14:06:39
4 user_123 {"id": "msg_6893...", "content": [{"annotations": [], "text": "Hello! The current server time is 5:06 PM on August 6, 2025. How can I assist you today?", "type": "output_text", "logprobs": []}], "role": "assistant", "status": "completed", "type": "message"} 2025-08-06 14:06:39

This works, but it's not great for a few reasons:

  • Querying for specific things (like all messages and their respective responses) is a pain because you have to parse JSON in the query.
  • I am specifically running into this problem as I'm trying to implement an "edit message" functionality, which needs to change the course of a conversation at a specific message in the session history.

We should probably switch to a more structured schema with separate tables, especially considering the ongoing developments on extending the session functionality.

Perhaps something like:

A runs table to hold the main conversation thread:

  • id
  • session_id
  • user_message
  • assistant_message
  • created_at

And a tool_calls table to log all the tool activity for a run:

  • id
  • run_id (foreign key to runs)
  • tool_name
  • arguments
  • output
  • created_at

This would make our lives a lot easier when it comes to analyzing or debugging conversations.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions