Skip to content

feat: add read-only runtime memory mode#1141

Merged
omeraplak merged 1 commit intomainfrom
feat/memory-readonly-mode
Mar 6, 2026
Merged

feat: add read-only runtime memory mode#1141
omeraplak merged 1 commit intomainfrom
feat/memory-readonly-mode

Conversation

@omeraplak
Copy link
Member

@omeraplak omeraplak commented Mar 6, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

Runtime memory always persists new messages/steps when memory is enabled, and working memory tools always include write operations.

What is the new behavior?

When memory.options.readOnly: true is provided for a call:

  • Memory context is still read.
  • Conversation persistence writes are skipped.
  • Step persistence writes are skipped.
  • Background input persistence during context hydration is skipped.
  • Object response memory writes are skipped.
  • Working memory write tools are disabled (update_working_memory, clear_working_memory), while get_working_memory remains available.
  • Server schema/options now accept memory.options.readOnly.

fixes (issue)

N/A

Notes for reviewers

  • Added/updated tests in @voltagent/core and @voltagent/server-core.
  • Verified with:
    • pnpm --filter @voltagent/core exec vitest run src/agent/agent.spec.ts
    • pnpm --filter @voltagent/server-core exec vitest run src/schemas/agent.schemas.spec.ts
    • pnpm --filter @voltagent/core typecheck
    • pnpm --filter @voltagent/server-core typecheck

Summary by cubic

Add a per-call read-only memory mode so agents can read context without persisting any new state. Enable via memory.options.readOnly and disable working memory write tools for that request.

  • New Features
    • Accept memory.options.readOnly in runtime and server schemas.
    • Skip memory writes: conversation messages, step checkpoints, background input during hydration, and object response persistence.
    • Working memory tools: expose get_working_memory only; disable update_working_memory and clear_working_memory.
    • Guard agent persistence paths and queues to honor read-only mode.
    • Added tests in core and server-core; updated docs and API references.

Written for commit 3b31084. Summary will update on new commits.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added memory read-only mode via memory.options.readOnly flag for per-call control
    • When enabled, agents access existing conversation context and working memory without persisting any new state or writes
    • Read-only mode disables memory write operations while keeping read functionality available
  • Documentation

    • Updated API reference, integration guides, and memory documentation with read-only mode examples and usage instructions

@changeset-bot
Copy link

changeset-bot bot commented Mar 6, 2026

🦋 Changeset detected

Latest commit: 3b31084

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@voltagent/core Patch
@voltagent/server-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@joggrbot

This comment has been minimized.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2026

📝 Walkthrough

Walkthrough

Introduces per-call memory read-only mode via memory.options.readOnly flag. When enabled, agents read existing conversation and working memory context while suppressing all memory persistence writes, including conversation messages, steps, background input, and working memory updates. Tools for reading memory remain available.

Changes

Cohort / File(s) Summary
Type Definitions & Core Types
packages/core/src/agent/types.ts, packages/server-core/src/utils/options.ts
Added optional readOnly?: boolean field to memory behavior options, propagating through CommonRuntimeMemoryBehaviorOptions and CommonResolvedRuntimeMemoryOptions type signatures.
Schema & Validation
packages/server-core/src/schemas/agent.schemas.ts, packages/server-core/src/schemas/agent.schemas.spec.ts
Extended RuntimeMemoryBehaviorOptionsSchema and GenerateOptionsSchema to accept optional readOnly: boolean field with validation that memory reads are permitted without persistence when enabled.
Agent Core Implementation
packages/core/src/agent/agent.ts
Introduced isReadOnlyMemoryForContext() and shouldPersistMemoryForContext() helper methods; refactored all memory persistence paths (conversation messages, steps, background input, working memory updates, UI persistence) to conditionally gate writes based on read-only flag; suppressed update_working_memory and clear_working_memory tools when read-only is active; added readOnly field resolution in resolveMemoryRuntimeOptions.
Memory Persistence Control
packages/core/src/memory/manager/memory-manager.ts
Extended prepareConversationContext() signature with optional options?: { persistInput?: boolean } parameter to gate background input persistence during context preparation.
Type Declarations & Tests
packages/core/src/agent/agent.spec-d.ts, packages/core/src/agent/agent.spec.ts
Added type test for optional readOnly field in public options; introduced test cases verifying memory reads occur while persistence writes are suppressed in read-only mode and write tools are disabled.
Documentation
website/docs/agents/memory/overview.md, website/docs/agents/memory/working-memory.md, website/docs/api/api-reference.md, website/docs/api/endpoints/agents.md, website/docs/ui/ai-sdk-integration.md, .changeset/read-only-memory-mode.md
Added guidance and examples documenting read-only memory mode behavior, tool exposure restrictions, and usage patterns for one-off memory reads without persistence.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through memory's gate,
Read the past, don't hesitate—
But write? Not now, we'll pause that fate,
Read-only mode keeps contexts straight! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add read-only runtime memory mode' clearly and concisely summarizes the main feature being added. It directly reflects the primary change of introducing a read-only memory mode.
Description check ✅ Passed The PR description covers all required sections from the template: checklist items completed, current behavior explained, new behavior detailed with specific examples, tests and docs confirmed, and changesets added. The description is comprehensive with verification commands.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/memory-readonly-mode

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 14 files

@cloudflare-workers-and-pages
Copy link

Deploying voltagent with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3b31084
Status: ✅  Deploy successful!
Preview URL: https://81ef0b84.voltagent.pages.dev
Branch Preview URL: https://feat-memory-readonly-mode.voltagent.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/core/src/agent/agent.ts (1)

1327-1361: ⚠️ Potential issue | 🟠 Major

Don't return a writable feedback handle from read-only calls.

Both text paths now suppress conversation persistence, but the returned feedback handle still closes over this.markFeedbackProvided(...), which writes metadata back to memory. That re-opens a write path after a read-only call, and it can also point at message IDs that were never persisted. Please either suppress the handle for read-only requests or make its markFeedbackProvided callback a no-op.

Also applies to: 1549-1568

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/agent/agent.ts` around lines 1327 - 1361, The feedback
handle currently closes over this.markFeedbackProvided and can re-open writes
for read-only requests; modify the creation of feedbackValue (the call to
createFeedbackHandleHelper) so that when persistence is suppressed (e.g.,
shouldPersistMemory is false or the request is a read-only path where persist
was deferred), you either return null for feedbackValue or pass a no-op
markFeedbackProvided and a resolveMessageId that returns null; specifically
update the block that builds feedbackValue (which references feedbackMetadata,
createFeedbackHandleHelper, resolveMessageId => findFeedbackMessageIdHelper, and
markFeedbackProvided) to short-circuit for read-only cases or replace
markFeedbackProvided with a no-op closure and resolveMessageId with a safe
null-returning function.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/core/src/agent/agent.ts`:
- Around line 1327-1361: The feedback handle currently closes over
this.markFeedbackProvided and can re-open writes for read-only requests; modify
the creation of feedbackValue (the call to createFeedbackHandleHelper) so that
when persistence is suppressed (e.g., shouldPersistMemory is false or the
request is a read-only path where persist was deferred), you either return null
for feedbackValue or pass a no-op markFeedbackProvided and a resolveMessageId
that returns null; specifically update the block that builds feedbackValue
(which references feedbackMetadata, createFeedbackHandleHelper, resolveMessageId
=> findFeedbackMessageIdHelper, and markFeedbackProvided) to short-circuit for
read-only cases or replace markFeedbackProvided with a no-op closure and
resolveMessageId with a safe null-returning function.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cbc79d97-470f-4678-94f9-e958a699b305

📥 Commits

Reviewing files that changed from the base of the PR and between cb0803d and 3b31084.

📒 Files selected for processing (14)
  • .changeset/read-only-memory-mode.md
  • packages/core/src/agent/agent.spec-d.ts
  • packages/core/src/agent/agent.spec.ts
  • packages/core/src/agent/agent.ts
  • packages/core/src/agent/types.ts
  • packages/core/src/memory/manager/memory-manager.ts
  • packages/server-core/src/schemas/agent.schemas.spec.ts
  • packages/server-core/src/schemas/agent.schemas.ts
  • packages/server-core/src/utils/options.ts
  • website/docs/agents/memory/overview.md
  • website/docs/agents/memory/working-memory.md
  • website/docs/api/api-reference.md
  • website/docs/api/endpoints/agents.md
  • website/docs/ui/ai-sdk-integration.md

@omeraplak omeraplak merged commit faa5023 into main Mar 6, 2026
24 checks passed
@omeraplak omeraplak deleted the feat/memory-readonly-mode branch March 6, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant