Commit graph

2 commits

Author SHA1 Message Date
abhay-codes07
a2328e8ace
fix(python-sdks): stop mishandling SDK model objects in memory dedup/format
The pipecat, cartesia, and agent-framework packages all pass
search results from the Supermemory SDK (pydantic models, attribute
access, snake_case fields) into dedup/format helpers written for plain
dicts. The consequences differed by package but all killed the
feature's primary path:

- pipecat: deduplicate_memories called r.get() on a Result model ->
  AttributeError -> the outer handler logs "Error processing frame"
  and forwards the frame unchanged, so memories are never injected for
  any user whose profile lookup returns search results
- cartesia: identical crash, swallowed by _enrich_event_with_memories'
  generic except -> memory_context silently comes back empty and the
  previous memory block is stripped from the system prompt
- agent-framework: extract_memory_text only handled dict/str, so model
  objects fell through to `return None` and every search-result memory
  was silently dropped from the injected context

(The OpenAI package shares the same helper shape but works because it
fetches profile data over raw aiohttp and receives dicts — that
asymmetry is what hid this.)

pipecat/cartesia gain an extract_search_result_fields helper that reads
memory/updatedAt off dicts (camelCase keys) or SDK models (snake_case
attributes, datetime-tolerant), used by both deduplicate_memories and
format_memories_to_text; the formatter also no longer prints raw object
reprs for non-dict items. agent-framework's extract_memory_text gains a
model-object branch.

Verified against the real SDK: built a
supermemory.types.search_memories_response.Result from an API-shaped
payload and ran it through dedup -> extract -> format (crashed with
AttributeError before, renders "- [1 Jan] User prefers async" after).
Test suites: pipecat 7 passed, cartesia 7 passed, agent-framework 56
passed (agent-framework-core pinned to 1.0.0rc3 — newer releases have
dropped BaseContextProvider, which breaks the package import
independently of this change).
2026-08-22 05:27:35 +05:30
Dhravya
984297b62d
Add Supermemory integration for Microsoft Agent Framework (#775)
## Summary

This PR introduces comprehensive Supermemory integration for the Microsoft Agent Framework, providing three complementary approaches to add persistent memory capabilities to agents: middleware for automatic memory injection, context providers for session-based memory management, and tools for explicit memory operations.

## Key Changes

- **SupermemoryChatMiddleware**: Automatic memory injection middleware that fetches relevant memories from Supermemory before LLM calls and optionally saves conversations. Supports three modes:
  - `"profile"`: Injects all static and dynamic profile memories
  - `"query"`: Searches for memories relevant to the current user message
  - `"full"`: Combines both profile and query modes

- **SupermemoryContextProvider**: Idiomatic context provider following the Agent Framework pattern (similar to built-in Mem0 integration). Integrates with the session pipeline via `before_run()` and `after_run()` hooks for automatic memory retrieval and storage.

- **SupermemoryTools**: FunctionTool-compatible tools that agents can use for explicit memory operations:
  - `search_memories()`: Search for specific memories
  - `add_memory()`: Add new memories
  - `get_profile()`: Retrieve user profile

- **Utility Functions**: Helper functions for:
  - Memory deduplication across static, dynamic, and search result sources
  - Profile-to-markdown conversion for LLM consumption
  - Message extraction and conversation formatting
  - Logging with configurable verbosity

- **Exception Hierarchy**: Custom exceptions for better error handling:
  - `SupermemoryConfigurationError`: Missing/invalid configuration
  - `SupermemoryAPIError`: API request failures
  - `SupermemoryNetworkError`: Network connectivity issues
  - `SupermemoryMemoryOperationError`: Memory operation failures

- **Comprehensive Documentation**: README with quick start examples, configuration options, and API reference for all three integration approaches.

- **Test Suite**: Unit tests covering middleware, context provider, tools, and utility functions with proper mocking and error scenarios.

## Implementation Details

- Supports both async (aiohttp) and sync (requests) HTTP clients with automatic fallback
- Handles multiple message formats (dict, objects with attributes, content arrays)
- Configurable memory storage with optional conversation grouping via `conversation_id`
- Environment variable fallback for API key configuration (`SUPERMEMORY_API_KEY`)
- Background task management for non-blocking memory operations in middleware
- Proper async/sync compatibility for the Supermemory SDK

https://claude.ai/code/session_012idB5y6UGK3zmeFULgTc4z
2026-03-10 01:49:45 +00:00