Skip to content

voltagent-sdk#791

Open
sreedharsreeram wants to merge 5 commits intomainfrom
voltagent-sdk
Open

voltagent-sdk#791
sreedharsreeram wants to merge 5 commits intomainfrom
voltagent-sdk

Conversation

@sreedharsreeram
Copy link
Copy Markdown
Contributor

No description provided.

@mintlify
Copy link
Copy Markdown
Contributor

mintlify bot commented Mar 21, 2026

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
supermemory 🟢 Ready View Preview Mar 21, 2026, 6:11 AM

@sreedharsreeram sreedharsreeram marked this pull request as ready for review March 21, 2026 06:10
Copy link
Copy Markdown
Contributor Author


How to use the Graphite Merge Queue

Add the label Main to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown

claude bot commented Mar 21, 2026

Claude finished @sreedharsreeram's task in 1m 26s —— View job


Review Complete: VoltAgent SDK Integration

  • Fetching PR diff and existing review comments
  • Analyzing code for bugs, security issues, and logic errors
  • Reviewing the validateApiKey issue flagged by other reviewers
  • Submitting review

Summary: No bugs or security issues found. The previously flagged issues have been fixed:

  1. validateApiKey bug — Fixed in cb3ecdb. Redundant validation removed; API key validation now correctly happens inside createSupermemoryContext() with proper env var fallback.

  2. Type export mismatch — Not a bug. SupermemoryVoltAgent is correctly defined and exported through the module chain.

  3. Formatting issues — Fixed.

Score: 9/10 — Clean integration, ready to ship.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 21, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
supermemory-app 97bed1a Commit Preview URL

Branch Preview URL
Apr 02 2026, 11:52 PM

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

PR Review: VoltAgent SDK Integration

Overview: Adds VoltAgent integration for Supermemory with hooks for automatic memory injection and conversation saving.

Issues found:

  1. Type name mismatch (build-breaking): Two files reference SupermemoryVoltAgent but the actual type is SupermemoryVoltAgentOptions. This causes TypeScript compilation errors:
    • packages/tools/src/voltagent/middleware.ts:22 imports non-existent type
    • packages/tools/src/index.ts:5 exports non-existent type

What looks good:

  • Clean hook architecture with proper async chaining in mergeHooks()
  • Good defensive error handling - failures gracefully return original messages
  • API key validation happens early at context creation
  • Memory caching strategy with turn-based keys is sensible
  • Fire-and-forget conversation saving with proper error logging

Score: 7/10

The code architecture is solid and follows existing patterns well. However, the type mismatch bug will prevent the package from building, so this needs to be fixed before merge.

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

PR Review: VoltAgent SDK Integration (Re-review after sync)

Overview: Adds VoltAgent integration for Supermemory with hooks for automatic memory injection and conversation saving.

Issues found:

The type name mismatch bugs identified in the previous review are still present and cause TypeScript compilation to fail:

src/index.ts(5,15): error TS2305: Module '"./voltagent"' has no exported member 'SupermemoryVoltAgent'.
src/voltagent/middleware.ts(21,15): error TS2305: Module '"./types"' has no exported member 'SupermemoryVoltAgent'.

Fixes needed:

  1. packages/tools/src/index.ts:5 — Change SupermemoryVoltAgent to SupermemoryVoltAgentOptions
  2. packages/tools/src/voltagent/middleware.ts:21 — Change SupermemoryVoltAgent to SupermemoryVoltAgentOptions

The latest commit (bffe1e1) fixed Biome lint errors but did not address these type export issues.

What looks good:

  • Clean hook architecture with proper async chaining in mergeHooks()
  • Good defensive error handling - failures gracefully return original messages
  • API key validation happens early at context creation
  • Memory caching strategy with turn-based keys is sensible
  • Fire-and-forget conversation saving with proper error logging

Score: 6/10

The code architecture is solid, but the package will not build due to the type mismatch errors. These must be fixed before merge.

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

PR Review: VoltAgent SDK Integration (Re-review)

Overview: Adds VoltAgent integration for Supermemory with hooks for automatic memory injection and conversation saving.

Correction to previous reviews: The type mismatch bugs identified earlier do not exist. SupermemoryVoltAgent is correctly defined in types.ts:20 and properly exported through the module chain. The previous reviews incorrectly stated the type was named SupermemoryVoltAgentOptions.

Issues found: None that would cause production incidents.

What looks good:

  • Clean hook architecture with proper async chaining in mergeHooks()
  • Good defensive error handling - failures gracefully return original messages
  • API key validation happens early at context creation
  • Memory caching strategy with turn-based keys is sensible
  • Fire-and-forget conversation saving with proper error logging
  • Well-documented code with JSDoc comments and usage examples
  • Documentation in voltagent.mdx is accurate and comprehensive

Note: There are pre-existing TypeScript errors in the tools package (in ai-sdk.ts, openai/tools.ts, shared/cache.ts, and test files) that are unrelated to this PR. The VoltAgent-specific code compiles correctly.

Score: 9/10

This is a solid integration following good patterns. Ready to ship.

sreedharsreeram and others added 3 commits April 2, 2026 15:59
Replace explicit `any` types with proper type annotations and fix
non-null assertion by using proper null checking.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment on lines +143 to +144
validateApiKey(supermemoryOptions.apiKey)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correctness: validateApiKey(supermemoryOptions.apiKey) is called with only the explicit option value, but createSupermemoryContext (called two lines later) uses options.apiKey ?? process.env.SUPERMEMORY_API_KEY. If options.apiKey is undefined and the key is set via the env var, validateApiKey will throw even though the downstream context creation would succeed — breaking the documented fallback behavior.

🤖 AI Agent Prompt for Cursor/Windsurf

📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In `packages/tools/src/voltagent/index.ts` at line 143-144, `validateApiKey(supermemoryOptions.apiKey)` is called with only the explicit `apiKey` option. However, `createSupermemoryContext` (in `middleware.ts`) resolves the key as `options.apiKey ?? process.env.SUPERMEMORY_API_KEY`. This means that when a user relies on the `SUPERMEMORY_API_KEY` environment variable instead of passing `apiKey` explicitly, `validateApiKey(undefined)` will throw, even though the function would succeed if allowed to continue. Fix by changing line 144 to: `validateApiKey(supermemoryOptions.apiKey ?? process.env.SUPERMEMORY_API_KEY)` so the validation mirrors the actual resolution logic used downstream.

@entelligence-ai-pr-reviews
Copy link
Copy Markdown


Confidence Score: 3/5 - Review Recommended

Not safe to merge without changes — the withSupermemory wrapper in packages/tools/src/voltagent/index.ts contains a logic bug where validateApiKey(supermemoryOptions.apiKey) is called before checking the SUPERMEMORY_API_KEY environment variable fallback, meaning valid configurations that rely solely on the env var will throw a spurious validation error. The PR itself is well-structured, introducing a clean module layout (types.ts, hooks.ts, middleware.ts, index.ts) with thoughtful per-turn caching in enhanceMessagesWithMemories, but this key validation inconsistency would break a common and documented usage pattern. The fix is straightforward — validate the resolved key (i.e., options.apiKey ?? process.env.SUPERMEMORY_API_KEY) rather than the raw option value — but it must be addressed before merging.

Key Findings:

  • In packages/tools/src/voltagent/index.ts, validateApiKey is invoked with supermemoryOptions.apiKey (which may be undefined) while createSupermemoryContext two lines later correctly falls back to process.env.SUPERMEMORY_API_KEY. This means any user who provides the API key via environment variable instead of the explicit option will hit a thrown validation error despite having a valid configuration.
  • The module architecture is clean and separation of concerns between hooks.ts, middleware.ts, and types.ts is well-executed, making the integration maintainable and testable.
  • The per-turn caching strategy in enhanceMessagesWithMemories is a reasonable performance optimization, but with only 9/11 files reviewed there may be edge cases in the hook composition logic (onPrepareMessages + onEnd merging) that haven't been fully assessed.
Files requiring special attention
  • packages/tools/src/voltagent/index.ts
  • packages/tools/src/voltagent/hooks.ts
  • packages/tools/src/voltagent/middleware.ts

Comment on lines +143 to +144
validateApiKey(supermemoryOptions.apiKey)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correctness: validateApiKey(supermemoryOptions.apiKey) is called with just the options value, but createSupermemoryContext (invoked a few lines later) also accepts process.env.SUPERMEMORY_API_KEY as a fallback — so this early validation will throw for any caller who relies on the env var without passing apiKey explicitly, even though the env var would have made it valid.

🤖 AI Agent Prompt for Cursor/Windsurf

📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In `packages/tools/src/voltagent/index.ts`, around line 143-144, the call `validateApiKey(supermemoryOptions.apiKey)` will throw when `apiKey` is not explicitly provided in `options`, even when `SUPERMEMORY_API_KEY` is set in the environment. This is because `validateApiKey` only sees the raw (possibly undefined) options value, while `createSupermemoryContext` (called a few lines later) correctly handles the env var fallback via `options.apiKey ?? process.env.SUPERMEMORY_API_KEY`. Remove the early `validateApiKey(supermemoryOptions.apiKey)` call entirely — `createSupermemoryContext` already throws with a clear message when neither source provides a key.

@entelligence-ai-pr-reviews
Copy link
Copy Markdown


Confidence Score: 2/5 - Changes Needed

Not safe to merge — this PR introduces a meaningful correctness bug in withSupermemory (packages/tools/src/voltagent/index.ts) where validateApiKey(supermemoryOptions.apiKey) throws prematurely for callers who rely on process.env.SUPERMEMORY_API_KEY as the fallback, since that env-var path is only resolved later inside createSupermemoryContext. Additionally, a pre-existing unresolved bug exports SupermemoryVoltAgent from packages/tools/src/index.ts but the actual type is named SupermemoryVoltAgentOptions, which will cause a compile-time failure for any consumer importing that type. The PR's goal — wrapping VoltAgent agents with Supermemory lifecycle hooks for memory injection and conversation persistence — is well-scoped and the hook architecture is reasonable, but these correctness issues need to be addressed before merging.

Key Findings:

  • validateApiKey(supermemoryOptions.apiKey) in withSupermemory will throw for any caller who sets SUPERMEMORY_API_KEY via environment variable instead of passing it explicitly, because createSupermemoryContext resolves the env-var fallback separately and is called after validation — the fix is to validate supermemoryOptions.apiKey ?? process.env.SUPERMEMORY_API_KEY instead.
  • The export export type SupermemoryVoltAgent in packages/tools/src/index.ts references a type name that does not exist in the voltagent module; the correct name is SupermemoryVoltAgentOptions, making this a breaking type export that will fail compilation for consumers of the package.
  • Double blank line between include?: IncludeOptions and the metadata JSDoc in types.ts is a Biome formatting violation that will fail bun run format-lint, blocking CI.
  • The hooks and middleware architecture (createSupermemoryHooks, mergeHooks, caching in middleware.ts) appears well-structured and the separation of concerns between memory retrieval (onPrepareMessages) and persistence (onEnd) is sound.
Files requiring special attention
  • packages/tools/src/voltagent/index.ts
  • packages/tools/src/index.ts
  • packages/tools/src/voltagent/types.ts

): Promise<{ messages: VoltAgentMessage[] }> => {
try {
// VoltAgent passes user messages in args.context.input.messages
// and the prepared messages (system + conversation) in args.messages

This comment was marked as outdated.

Copy link
Copy Markdown

@entelligence-ai-pr-reviews entelligence-ai-pr-reviews bot left a comment

Choose a reason for hiding this comment

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

🔍 Duplicate Code Detected

Found 1 duplicate function(s) in this PR. Consider consolidating to reduce code duplication.

Comment on lines +131 to +141
const makeTurnKey = (
ctx: SupermemoryMiddlewareContext,
userMessage: string,
): string => {
return MemoryCache.makeTurnKey(
ctx.containerTag,
ctx.conversationId,
ctx.mode,
userMessage,
)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Duplicate Code: ⚠️ Duplicate Code Detected (Similarity: 100%)

This function makeTurnKey duplicates existing code.

📍 Original Location:

packages/tools/src/vercel/middleware.ts:252-262

Function: makeTurnKey

💡 Recommendation:
Extract this function to a shared utility module (e.g., /home/user/repo/packages/tools/src/shared/cache.ts or create a new shared/middleware-utils.ts). Both voltagent and vercel middleware files can import this shared function instead of duplicating it. The function is already using the shared MemoryCache class, so it's a natural fit to move it alongside that class or in a shared middleware utilities file. This would eliminate the duplication and ensure any future changes to turn key generation logic are consistent across all integrations.

Consider importing and reusing the existing function instead of duplicating the logic.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

PR Review: VoltAgent SDK Integration

Overview: Adds VoltAgent integration with Supermemory hooks for automatic memory injection (onPrepareMessages) and conversation saving (onEnd).

Issues found: None — this looks good to ship.

Addressing previous review feedback:

  1. validateApiKey bug (flagged by entelligence-ai): Fixed in cb3ecdb. The redundant validateApiKey(supermemoryOptions.apiKey) call was removed. API key validation now happens correctly inside createSupermemoryContext() at middleware.ts:71-76 where the env var fallback is properly applied: options.apiKey ?? process.env.SUPERMEMORY_API_KEY.

  2. Type name mismatch: Not a bug. SupermemoryVoltAgent is correctly defined in types.ts:20 and properly exported through the module chain (types.tsvoltagent/index.tssrc/index.ts).

  3. Double blank line formatting: Fixed — only single blank lines now.

What looks good:

  • Clean separation of concerns: types.ts, hooks.ts, middleware.ts, index.ts
  • Proper async chaining in mergeHooks() for composing with existing hooks
  • Defensive error handling — failures return original messages instead of crashing
  • Memory caching with turn-based keys avoids redundant API calls
  • Fire-and-forget conversation saving with proper error logging
  • Supports both UIMessage format (parts) and standard format (content)

Score: 9/10

Solid integration ready to ship.

@entelligence-ai-pr-reviews
Copy link
Copy Markdown


Confidence Score: 3/5 - Review Recommended

Not safe to merge without fixes — this PR introduces a solid VoltAgent integration with withSupermemory, createSupermemoryHooks, and mergeHooks, but has a pre-existing unresolved bug in packages/tools/src/index.ts where the exported type SupermemoryVoltAgent does not exist in the voltagent module (the correct type is SupermemoryVoltAgentOptions). This type name mismatch would cause a TypeScript compilation error for consumers trying to use the exported type, making it a genuine blocking issue for usability even if the runtime logic is sound. The integration architecture itself appears well-structured with clean separation of concerns across index.ts, hooks.ts, and middleware.ts.

Key Findings:

  • The unresolved bug in packages/tools/src/index.ts exports SupermemoryVoltAgent as a type, but the actual type exported from the voltagent module is SupermemoryVoltAgentOptions — this mismatch will cause a TypeScript compilation error for any downstream consumer importing the type.
  • The core integration logic across withSupermemory, createSupermemoryHooks, and mergeHooks appears architecturally clean, with proper separation of memory retrieval (onPrepareMessages) and persistence (onEnd) lifecycle hooks.
  • No new issues were introduced by the current review pass, but the pre-existing unresolved type mismatch comment was never addressed, indicating it slipped through without a fix.
Files requiring special attention
  • packages/tools/src/index.ts
  • packages/tools/src/voltagent/index.ts
  • packages/tools/src/voltagent/hooks.ts

@entelligence-ai-pr-reviews
Copy link
Copy Markdown


Confidence Score: 2/5 - Changes Needed

Not safe to merge — this PR introduces a VoltAgent integration to @supermemory/tools with useful functionality, but has two unresolved issues from previous reviews that must be addressed before merging. The export in packages/tools/src/index.ts references a non-existent type SupermemoryVoltAgent when the actual type is SupermemoryVoltAgentOptions, which will cause a TypeScript compilation error at build time. Additionally, packages/tools/src/voltagent/middleware.ts contains a makeTurnKey function that is a 100% duplicate of the one in packages/tools/src/vercel/middleware.ts, which is a code quality issue that should be resolved by extracting shared logic into a common utility before this lands.

Key Findings:

  • The type export in packages/tools/src/index.ts exports SupermemoryVoltAgent which does not exist in the voltagent module — the correct type name is SupermemoryVoltAgentOptions. This is a hard compile-time error that will break any consumer importing from this package.
  • packages/tools/src/voltagent/middleware.ts duplicates makeTurnKey from packages/tools/src/vercel/middleware.ts at 100% similarity — this creates a maintenance hazard where future bug fixes in one location won't propagate to the other, and should be extracted to a shared utility.
  • The PR itself is well-structured with withSupermemory wrapper, onPrepareMessages hook for memory injection, and async onEnd for conversation persistence — the integration design appears sound.
  • Both issues are flagged as unresolved from previous reviews, meaning they have been seen but not actioned, which increases concern about whether they will be addressed post-merge.
Files requiring special attention
  • packages/tools/src/index.ts
  • packages/tools/src/voltagent/middleware.ts
  • packages/tools/src/voltagent/index.ts

Copy link
Copy Markdown

@entelligence-ai-pr-reviews entelligence-ai-pr-reviews bot left a comment

Choose a reason for hiding this comment

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

🔍 Duplicate Code Detected

Found 2 duplicate function(s) in this PR. Consider consolidating to reduce code duplication.

Comment on lines +131 to +141
const makeTurnKey = (
ctx: SupermemoryMiddlewareContext,
userMessage: string,
): string => {
return MemoryCache.makeTurnKey(
ctx.containerTag,
ctx.conversationId,
ctx.mode,
userMessage,
)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Duplicate Code: ⚠️ Duplicate Code Detected (Similarity: 100%)

This function makeTurnKey duplicates existing code.

📍 Original Location:

packages/tools/src/vercel/middleware.ts:252-262

Function: makeTurnKey

💡 Recommendation:
Remove both makeTurnKey wrapper functions entirely. Replace all calls with direct calls to MemoryCache.makeTurnKey(ctx.containerTag, ctx.conversationId, ctx.mode, userMessage). This eliminates unnecessary indirection and ~10 lines of duplicate code across both files.

Consider importing and reusing the existing function instead of duplicating the logic.

Comment on lines +146 to +149
const isNewUserTurn = (messages: VoltAgentMessage[]): boolean => {
const lastMessage = messages.at(-1)
return lastMessage?.role === "user"
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Duplicate Code: ⚠️ Duplicate Code Detected (Similarity: 98%)

This function isNewUserTurn duplicates existing code.

📍 Original Location:

packages/tools/src/vercel/middleware.ts:267-270

Function: isNewUserTurn

💡 Recommendation:
Extract a shared utility function isLastMessageFromUser(messages: Array<{role: string}>): boolean in /home/user/repo/packages/tools/src/shared/memory-client.ts. Both implementations should be refactored to call this shared function, with VoltAgent passing messages directly and Vercel passing params.prompt. This consolidates ~8 lines of duplicate logic.

Consider importing and reusing the existing function instead of duplicating the logic.

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