RavenDB-24609 Add GetConversationMessages operation for AI agent conversations#302
Open
redknightlois wants to merge 1 commit into
Open
Conversation
Python port of the RavenDB C# client's GetConversationMessages feature (ravendb/ravendb#22619). Adds AiOperations.get_conversation_messages() with timestamp-based paging (before/after cursors) and detail-level filtering (Simple/Detailed/Full), presenting a unified message timeline across conversation history documents. New models: AiConversationMessage, AiToolCallResult, AiConversationMessagesResult, GetConversationMessagesOptions, AiConversationDetailLevel, AiMessageRole; split per-concern mirroring the C# source layout. See: https://issues.hibernatingrhinos.com/issue/RavenDB-24609
7b2800a to
5444d91
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
https://issues.hibernatingrhinos.com/issue/RavenDB-24609
Source (C# client): ravendb/ravendb#22619
What changed
Brings the
GetConversationMessagesread operation to the Python client, mirroring the C# client(ravendb/ravendb#22619). It fetches an AI agent
conversation's message history from
GET /databases/{db}/ai/agent/conversation/messages, with:beforeandaftercursors (mutually exclusive), serialized in Raven'sdefault UTC format (
yyyy-MM-ddTHH:mm:ss.fffffffZ), UTC-coerced before formatting so a naive ornon-UTC datetime yields a correct cursor.
Simple(default),Detailed,Full; passed to the server for filtering.New module
ravendb/documents/operations/ai/agents/get_conversation_messages_operation.py:GetConversationMessagesOperation/GetConversationMessagesCommand— aMaintenanceOperationwith an inner read
RavenCommand.GetConversationMessagesOptions— parameter object with eager client-side validation (rejects anempty/whitespace
conversation_id,beforeandaftertogether, andpage_size <= 0).AiConversationMessagesResult,AiConversationMessage,AiToolCallResult— snake_case Pythonattributes with
from_json/to_jsonmapping to/from the server's PascalCase keys.AiMessageRole(System,User,Assistant,Summary,Internal) andAiConversationDetailLevel(Simple,Detailed,Full).AiUsageis reused fromrun_conversation_operation— not duplicated.A convenience
AiOperations.get_conversation_messages()accepts either a conversation-id string or aGetConversationMessagesOptions.Response-timestamp parsing normalizes the fractional-seconds precision so it is compatible with the
package's declared Python floor (
~=3.9):datetime.fromisoformatbefore 3.11 accepts only 3 or 6fractional digits and rejects a
Zsuffix, whereas Raven emits 7-digit (100 ns tick)...Ztimestamps — both are normalized before parsing.
Tests: 43 unit tests (no mocks, no live server), covering URL/query construction, validation,
PascalCase↔snake_case round-trips through the real parser with representative server JSON (nested
tool calls, usage, sub-conversation ids), null-response handling, and datetime formatting/parsing.
Files (5): the new operation module and its test file; re-exports in
ravendb/documents/operations/ai/agents/__init__.pyandravendb/__init__.py; the conveniencemethod in
ravendb/documents/ai/ai_operations.py.Checklist
Known risks / not verified here
string falls within the fractional-digit/offset grammar that pre-3.11
fromisoformataccepts) andby the suite passing on 3.13/3.14, but was not executed under a <3.11 interpreter — none is
installed here. Worth a CI run on 3.9 to confirm.
Implemented by hugin-bot, created on behalf of @redknightlois.