Skip to content

feat(session): persist metadata + inject into memory extraction prompt (#2414)#2667

Open
yeyitech wants to merge 1 commit into
volcengine:mainfrom
yeyitech:feat/2414-session-metadata
Open

feat(session): persist metadata + inject into memory extraction prompt (#2414)#2667
yeyitech wants to merge 1 commit into
volcengine:mainfrom
yeyitech:feat/2414-session-metadata

Conversation

@yeyitech

Copy link
Copy Markdown
Contributor

Summary

Closes #2414. Today the only way to express project-level personalization (architectural style, tech-stack preferences) is to allocate a different agent_id per project. This PR ships the foundational piece — arbitrary session-level metadata that persists end-to-end and is injected into the memory extractor's prompt context — so a single agent can keep distinct memory layers across projects.

Surface

  • Model + storage: Session.metadata: dict | None, JSON-serializable, capped at 16 KB / 64 keys (module constants, no config field).
  • API:
    • POST /api/v1/sessions — accepts optional metadata on create.
    • GET /api/v1/sessions/{id} — includes metadata in the response.
    • PATCH /api/v1/sessions/{id}/metadata — merges by default; ?replace=true overwrites.
  • Extractor: when metadata is present, a [Session metadata] block is added to the system prompt the LLM sees during memory extraction.
  • CLI: ov session set-metadata <id> --key K --value V (repeatable).

Per-schema multi-layer memory (the issue's longer-term ask) is intentionally out of scope and lands as a follow-up — this PR just makes the foundation available.

Test plan

  • pytest tests/server/test_session_metadata.py -x -q passes (7 cases).
  • Manual: curl -X PATCH /api/v1/sessions/{id}/metadata -d '{\"project\":\"alpha\"}' then GET returns it; commit a session and verify the LLM extractor saw the metadata block.
  • Existing session tests still pass.

Closes #2414

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2414 - Partially compliant

Compliant requirements:

  • 服务端增加session metadata 额外字段持久保存
  • vlm抽取记忆时,将session metadata 加入到系统上下文

Non-compliant requirements:

  • schema配合实现多层记忆抽取 (marked as out of scope)
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🏅 Score: 85
🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 Multiple PR themes

Sub-PR theme: feat(session): core metadata support (persistence, API, extractor injection)

Relevant files:

  • openviking/server/routers/sessions.py
  • openviking/service/session_service.py
  • openviking/session/compressor_v2.py
  • openviking/session/memory/session_extract_context_provider.py
  • openviking/session/session.py
  • openviking/session/session_metadata.py
  • tests/server/test_session_metadata.py

Sub-PR theme: feat(cli): add session set-metadata command

Relevant files:

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

⚡ Recommended focus areas for review

Invalid Default for Telemetry Field

The telemetry field in CreateSessionRequest and UpdateMetadataRequest uses False as a default value, which is likely incompatible with the TelemetryRequest type. This will cause Pydantic validation errors for requests that don't explicitly provide telemetry data, breaking existing functionality.

    telemetry: TelemetryRequest = False


class UpdateMetadataRequest(BaseModel):
    """Request model for updating session metadata."""

    metadata: Dict[str, Any] = Field(default_factory=dict)
    telemetry: TelemetryRequest = False

@github-actions

Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

volcengine#2414)

Sessions can now carry an arbitrary metadata dict (project name,
tech-stack preferences, architectural style, etc.) that survives
through commit and is included in the system context the memory
extractor sees. Today the only way to express project-level
personalization was to allocate a separate agent_id per project; with
this change, a single agent can keep distinct memory layers across
projects via session metadata.

- Session model + storage gain a metadata field (dict, JSON-serializable,
  size-capped at 16 KB, key-count-capped at 64).
- API: POST /api/v1/sessions accepts metadata; PATCH
  /api/v1/sessions/{id}/metadata merges by default, replace=true overrides.
- Memory extractor: when metadata is present, a [Session metadata] block
  is added to the prompt's system context.
- CLI: ov session set-metadata --key K --value V.

Closes volcengine#2414

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@yeyitech yeyitech force-pushed the feat/2414-session-metadata branch from 7245e05 to c00a0c7 Compare June 17, 2026 10:09
@ZaynJarvis ZaynJarvis added enhancement New feature or request scenario:kernel Core server, runtime, storage, retrieval, SDK, CLI, or Studio behavior. urgency:suggestion Feature/RFC/improvement, not immediate bug. needs:architecture Maintainer architecture decision needed before coding. labels Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request needs:architecture Maintainer architecture decision needed before coding. Review effort 3/5 scenario:kernel Core server, runtime, storage, retrieval, SDK, CLI, or Studio behavior. urgency:suggestion Feature/RFC/improvement, not immediate bug.

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

[Feature]: 增加session metadata, 丰富schema可配置数据来源

2 participants