refactor: rename batch_add_messages to add_messages, add CLI add-messages command and update api docs#2218
Merged
Conversation
Previously, adding messages required one HTTP request per message,
making bulk operations (e.g. memory extraction, history migration)
very slow due to network round-trip overhead.
Changes:
- Add POST /api/v1/sessions/{id}/messages/batch endpoint
- Add BatchAddMessageRequest model with max_length=500 limit
- Extract _resolve_message_parts() helper to deduplicate part resolution
- Add _defer_meta_save parameter to Session.add_message() for batch optimization
- Add batch_add_messages method to Python SDK clients (base/http/sync)
- Add batch_add_messages to Session wrapper class
- Update LangChain integration to use batch API
- Update Rust CLI add_memory to use batch API
…essages command - Rename batch_add_messages → add_messages across Python SDK, server router, and client - Add 'ov session add-messages' CLI command with parse_messages() helper - Update API docs (en/zh) to reflect new naming and CLI usage - HTTP route path /messages/batch unchanged for backward compatibility
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨No code suggestions found for the PR. |
- parse_messages: return explicit errors for invalid JSON instead of silent fallback - add_messages: validate spec keys to raise ValueError instead of KeyError - Revert router endpoint function name to batch_add_messages
0439c01 to
b8311d5
Compare
…/Router use batch_add_messages
qin-ctx
approved these changes
May 26, 2026
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.
Description
新增 CLI
ov session add-messages命令,提取parse_messages()输入解析函数并增加校验,统一全层命名为batch_add_messages,新增中英文 API 文档。Related Issue
Follow-up #2213
Type of Change
Changes Made
ov session add-messages <session_id> <messages>命令parse_messages()函数,add_memory和add_messages共用消息解析逻辑,对无效 JSON 返回明确错误batch_add_messages:Session.batch_add_messages()、BaseClient.batch_add_messages()、Router 端点函数batch_add_messages()增加 spec key 校验,缺少role/parts时抛出ValueError并指明索引Testing
Checklist
Usage
HTTP API
curl -X POST http://localhost:1933/api/v1/sessions/{sid}/messages/batch \ -H "Content-Type: application/json" \ -d '{"messages": [{"role":"user","content":"Hello"},{"role":"assistant","content":"Hi"}]}'Python SDK
CLI