Skip to content

Commit 132ed4b

Browse files
feat: add configurable LLM settings for mem0_memory tool (#221)
- Add support for MEM0_LLM_PROVIDER, MEM0_LLM_MODEL, MEM0_LLM_TEMPERATURE, MEM0_LLM_MAX_TOKENS environment variables - Add support for MEM0_EMBEDDER_PROVIDER, MEM0_EMBEDDER_MODEL environment variables - Fix DEFAULT_CONFIG to properly use os.environ.get() with defaults - Add comprehensive tests for environment variable configuration - Update README.md documentation with new configuration options - Add module docstring documentation for new environment variables Fixes #220 Co-authored-by: Hemanth <[email protected]>
1 parent 4e999d8 commit 132ed4b

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,12 +759,19 @@ The Mem0 Memory Tool supports three different backend configurations:
759759
| OPENSEARCH_HOST | OpenSearch Host URL | None | OpenSearch |
760760
| AWS_REGION | AWS Region for OpenSearch | us-west-2 | OpenSearch |
761761
| DEV | Enable development mode (bypasses confirmations) | false | All modes |
762+
| MEM0_LLM_PROVIDER | LLM provider for memory processing | aws_bedrock | All modes |
763+
| MEM0_LLM_MODEL | LLM model for memory processing | anthropic.claude-3-5-haiku-20241022-v1:0 | All modes |
764+
| MEM0_LLM_TEMPERATURE | LLM temperature (0.0-2.0) | 0.1 | All modes |
765+
| MEM0_LLM_MAX_TOKENS | LLM maximum tokens | 2000 | All modes |
766+
| MEM0_EMBEDDER_PROVIDER | Embedder provider for vector embeddings | aws_bedrock | All modes |
767+
| MEM0_EMBEDDER_MODEL | Embedder model for vector embeddings | amazon.titan-embed-text-v2:0 | All modes |
768+
762769

763770
**Note**:
764771
- If `MEM0_API_KEY` is set, the tool will use the Mem0 Platform
765772
- If `OPENSEARCH_HOST` is set, the tool will use OpenSearch
766773
- If neither is set, the tool will default to FAISS (requires `faiss-cpu` package)
767-
774+
- LLM configuration applies to all backend modes and allows customization of the language model used for memory processing
768775
#### Memory Tool
769776

770777
| Environment Variable | Description | Default |

src/strands_tools/mem0_memory.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,16 @@ class Mem0ServiceClient:
150150
"""Client for interacting with Mem0 service."""
151151

152152
DEFAULT_CONFIG = {
153-
"embedder": {"provider": "aws_bedrock", "config": {"model": "amazon.titan-embed-text-v2:0"}},
153+
"embedder": {
154+
"provider": os.environ.get("MEM0_EMBEDDER_PROVIDER", "aws_bedrock"),
155+
"config": {"model": os.environ.get("MEM0_EMBEDDER_MODEL", "amazon.titan-embed-text-v2:0")},
156+
},
154157
"llm": {
155-
"provider": "aws_bedrock",
158+
"provider": os.environ.get("MEM0_LLM_PROVIDER", "aws_bedrock"),
156159
"config": {
157-
"model": "anthropic.claude-3-5-haiku-20241022-v1:0",
158-
"temperature": 0.1,
159-
"max_tokens": 2000,
160+
"model": os.environ.get("MEM0_LLM_MODEL", "anthropic.claude-3-5-haiku-20241022-v1:0"),
161+
"temperature": float(os.environ.get("MEM0_LLM_TEMPERATURE", 0.1)),
162+
"max_tokens": int(os.environ.get("MEM0_LLM_MAX_TOKENS", 2000)),
160163
},
161164
},
162165
"vector_store": {

tests/test_mem0.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,18 @@ def extract_result_text(result):
5454
return str(result)
5555

5656

57-
@patch.dict(os.environ, {"OPENSEARCH_HOST": "test.opensearch.amazonaws.com"})
57+
@patch.dict(
58+
os.environ,
59+
{
60+
"MEM0_LLM_PROVIDER": "openai",
61+
"MEM0_LLM_MODEL": "gpt-4o",
62+
"MEM0_LLM_TEMPERATURE": "0.2",
63+
"MEM0_LLM_MAX_TOKENS": "4000",
64+
"MEM0_EMBEDDER_PROVIDER": "openai",
65+
"MEM0_EMBEDDER_MODEL": "text-embedding-3-large",
66+
"OPENSEARCH_HOST": "test.opensearch.amazonaws.com",
67+
},
68+
)
5869
@patch("strands_tools.mem0_memory.Mem0Memory")
5970
@patch("strands_tools.mem0_memory.boto3.Session")
6071
def test_store_memory(mock_boto3_session, mock_mem0_memory, mock_tool):

0 commit comments

Comments
 (0)