Skip to content

refactor: rename batch_add_messages to add_messages, add CLI add-messages command and update api docs#2218

Merged
qin-ctx merged 5 commits into
volcengine:mainfrom
sponge225:feat/batch-add-messages
May 26, 2026
Merged

refactor: rename batch_add_messages to add_messages, add CLI add-messages command and update api docs#2218
qin-ctx merged 5 commits into
volcengine:mainfrom
sponge225:feat/batch-add-messages

Conversation

@sponge225
Copy link
Copy Markdown
Collaborator

@sponge225 sponge225 commented May 25, 2026

Description

新增 CLI ov session add-messages 命令,提取 parse_messages() 输入解析函数并增加校验,统一全层命名为 batch_add_messages,新增中英文 API 文档。

Related Issue

Follow-up #2213

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • 新增 CLI ov session add-messages <session_id> <messages> 命令
  • 提取 parse_messages() 函数,add_memoryadd_messages 共用消息解析逻辑,对无效 JSON 返回明确错误
  • 统一全层命名为 batch_add_messagesSession.batch_add_messages()BaseClient.batch_add_messages()、Router 端点函数
  • batch_add_messages() 增加 spec key 校验,缺少 role/parts 时抛出 ValueError 并指明索引
  • 新增中英文 API 文档

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

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

result = await client.batch_add_messages(
    session_id="a1b2c3d4",
    messages=[
        {"role": "user", "content": "Hello"},
        {"role": "assistant", "content": "Hi"},
    ],
)

CLI

ov session add-messages <session_id> '[{"role":"user","content":"Hello"}]'
ov add-memory '[{"role":"user","content":"Hello"}]'  # 内部自动使用批量接口

sponge225 added 2 commits May 25, 2026 16:42
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
@github-actions
Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2213 - Partially compliant

Compliant requirements:

  • 新增 CLI ov session add-messages 命令
  • 提取 parse_messages 函数共用消息解析逻辑
  • 更新中英文 API 文档

Non-compliant requirements:

  • 未保留 batch_add_messages 作为别名,导致 SDK 向后不兼容
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🏅 Score: 85
🧪 No relevant tests
🔒 No security concerns identified
✅ No TODO sections
🔀 Multiple PR themes

Sub-PR theme: Add CLI add-messages command and refactor message parsing

Relevant files:

  • crates/ov_cli/src/commands/session.rs
  • crates/ov_cli/src/handlers.rs
  • crates/ov_cli/src/main.rs

Sub-PR theme: Update API docs for add_messages

Relevant files:

  • docs/en/api/05-sessions.md
  • docs/zh/api/05-sessions.md

⚡ Recommended focus areas for review

Breaking API Change

Renamed batch_add_messages to add_messages in the SDK without maintaining backward compatibility. Existing code using batch_add_messages will break.

async def add_messages(
    self,
    session_id: str,
    messages: list[dict],
    telemetry: TelemetryRequest = False,
) -> Dict[str, Any]:
Breaking API Change

Removed batch_add_messages method from the client session, breaking existing calls.

async def add_messages(
    self,
    messages: List[Dict[str, Any]],
) -> Dict[str, Any]:
    """Add multiple messages to the session in a single request.

    Args:
        messages: List of dicts, each with "role" and optionally "content",
                  "parts", "created_at", "role_id".

    Returns:
        Result dict with session_id, message_count, and added count.
    """
    return await self._client.add_messages(
        self.session_id,
        messages=messages,
    )

@github-actions
Copy link
Copy Markdown

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
@sponge225 sponge225 force-pushed the feat/batch-add-messages branch from 0439c01 to b8311d5 Compare May 25, 2026 09:51
@qin-ctx qin-ctx merged commit 8be3d4d into volcengine:main May 26, 2026
12 of 13 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants