mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-17 12:20:04 +00:00
## 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
162 lines
3.5 KiB
Text
162 lines
3.5 KiB
Text
---
|
|
title: "Quickstart - 5 mins"
|
|
description: "Learn how to integrate supermemory into your application"
|
|
---
|
|
|
|
## Authentication
|
|
|
|
Head to [supermemory's Developer Platform](https://console.supermemory.ai) built to help you monitor and manage every aspect of the API.
|
|
|
|
All API requests require authentication using an API key. Include your API key as follows:
|
|
|
|
<CodeGroup>
|
|
|
|
```bash cURL
|
|
Authorization: Bearer YOUR_API_KEY
|
|
```
|
|
|
|
```typescript Typescript
|
|
// npm install supermemory
|
|
|
|
const client = new supermemory({
|
|
apiKey: "YOUR_API_KEY",
|
|
});
|
|
```
|
|
|
|
```python Python
|
|
# pip install supermemory
|
|
|
|
client = supermemory(
|
|
api_key="YOUR_API_KEY",
|
|
)
|
|
```
|
|
|
|
</CodeGroup>
|
|
|
|
## Installing the clients
|
|
|
|
You can use supermemory through the APIs, or using our SDKs
|
|
|
|
<CodeGroup>
|
|
|
|
```bash cURL
|
|
https://api.supermemory.ai/v3
|
|
```
|
|
|
|
```bash Typescript
|
|
npm i supermemory
|
|
```
|
|
|
|
```bash Python
|
|
pip install supermemory
|
|
```
|
|
|
|
</CodeGroup>
|
|
|
|
## Add your first memory
|
|
|
|
<CodeGroup>
|
|
|
|
```bash cURL
|
|
curl https://api.supermemory.ai/v3/documents \
|
|
--request POST \
|
|
--header 'Content-Type: application/json' \
|
|
--header 'Authorization: Bearer SUPERMEMORY_API_KEY' \
|
|
-d '{"content": "This is the content of my first memory."}'
|
|
```
|
|
|
|
```typescript Typescript
|
|
await client.memory.add({
|
|
content: "This is the content of my first memory.",
|
|
});
|
|
```
|
|
|
|
```python Python
|
|
client.memory.add(
|
|
content="This is the content of my first memory.",
|
|
)
|
|
```
|
|
|
|
</CodeGroup>
|
|
|
|
This will add a new memory to your supermemory account.
|
|
|
|
Try it out in the API Reference tab.
|
|
|
|
## Content Processing
|
|
|
|
<Accordion title="Processing steps" icon="sparkles">
|
|
When you add content to supermemory, it goes through several processing steps:
|
|
|
|
1. **Queued**: Initial state when content is submitted
|
|
2. **Extracting**: Content is being extracted from the source
|
|
3. **Chunking**: Content is being split into semantic chunks
|
|
4. **Embedding**: Generating vector embeddings for search
|
|
5. **Indexing**: Adding content to the search index
|
|
6. **Done**: Processing complete
|
|
</Accordion>
|
|
|
|
<Accordion title="Advanced Chunking" icon="sparkles">
|
|
The system uses advanced NLP techniques for optimal chunking:
|
|
|
|
- Sentence-level splitting for natural boundaries
|
|
- Context preservation with overlapping chunks
|
|
- Smart handling of long content
|
|
- Semantic coherence optimization
|
|
|
|
</Accordion>
|
|
|
|
## Search your memories
|
|
|
|
<CodeGroup>
|
|
|
|
```bash cURL
|
|
curl https://api.supermemory.ai/v3/search \
|
|
--request POST \
|
|
--header 'Content-Type: application/json' \
|
|
--header 'Authorization: Bearer SUPERMEMORY_API_KEY' \
|
|
-d '{"q": "This is the content of my first memory."}'
|
|
```
|
|
|
|
```typescript Typescript
|
|
await client.search.execute({
|
|
q: "This is the content of my first memory.",
|
|
});
|
|
```
|
|
|
|
```python Python
|
|
client.search.execute(
|
|
q="This is the content of my first memory.",
|
|
)
|
|
```
|
|
|
|
</CodeGroup>
|
|
|
|
Try it out in the API Reference tab.
|
|
|
|
You can do a lot more with supermemory, and we will walk through everything you need to.
|
|
|
|
Next, explore the features available in supermemory
|
|
|
|
<CardGroup cols={2}>
|
|
<Card title="Adding memories" icon="plus" href="/memory-api/creation/adding-memories">
|
|
Adding memories
|
|
</Card>
|
|
<Card
|
|
title="Searching and filtering"
|
|
icon="search"
|
|
href="/memory-api/searching/searching-memories"
|
|
>
|
|
Searching for items
|
|
</Card>
|
|
<Card
|
|
title="Connectors and Syncing"
|
|
icon="plug"
|
|
href="/memory-api/connectors/overview"
|
|
>
|
|
Connecting external sources
|
|
</Card>
|
|
<Card title="Features" icon="sparkles" href="/memory-api/features/filtering">
|
|
Explore Features
|
|
</Card>
|
|
</CardGroup>
|