Conversation
There was a problem hiding this comment.
Pull request overview
This pull request implements the MemoryCollection module for managing memory collections in the agentrun SDK, including integration with mem0ai for memory management capabilities.
Changes:
- Adds new
agentrun.memory_collectionmodule with client, models, high-level API, and control API - Implements mem0ai integration through a
to_mem0_memorymethod that converts MemoryCollection to mem0 Memory client - Adds optional dependency
agentrun-mem0ai>=0.0.3in pyproject.toml - Includes example code demonstrating MemoryCollection usage
- Updates build configuration (Makefile) to include memory_collection code generation
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Adds mem0 optional dependency for agentrun-mem0ai package |
| examples/memory_collection_example.py | Provides usage examples for MemoryCollection with client and high-level API |
| codegen/configs/memory_collection_control_api.yaml | Configuration for code generation of control API |
| agentrun/memory_collection/model.py | Defines data models for MemoryCollection including configs and input/output types |
| agentrun/memory_collection/memory_collection.py | High-level API for MemoryCollection with CRUD operations and mem0 integration |
| agentrun/memory_collection/client.py | Client implementation with async/sync methods for memory collection management |
| agentrun/memory_collection/api/control.py | Control API layer for making HTTP requests to backend service |
| agentrun/memory_collection/api/init.py | API module initialization and exports |
| agentrun/memory_collection/__memory_collection_async_template.py | Template for generating async MemoryCollection implementation |
| agentrun/memory_collection/init.py | Module initialization and public API exports |
| agentrun/memory_collection/__client_async_template.py | Template for generating async client implementation |
| agentrun/init.py | Updates root module to export MemoryCollection types and classes |
| Makefile | Adds memory_collection to code generation targets |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if history_db_path: | ||
| mem0_config["history_db_path"] = history_db_path | ||
|
|
||
| return mem0_config | ||
|
|
||
| @staticmethod | ||
| async def _resolve_model_service_config_async( | ||
| model_service_name: str, config: Optional[Config] | ||
| ) -> Tuple[str, str]: | ||
| """解析 ModelService 配置获取 baseUrl 和 apiKey(异步) | ||
|
|
||
| Args: | ||
| model_service_name: ModelService 名称 | ||
| config: AgentRun 配置 | ||
|
|
||
| Returns: | ||
| Tuple[str, str]: (base_url, api_key) | ||
|
|
||
| Raises: | ||
| ValueError: 如果配置信息不完整 | ||
| """ | ||
| from agentrun.credential import Credential | ||
| from agentrun.model import ModelService | ||
|
|
||
| # 使用高层 API 获取 ModelService | ||
| model_service = await ModelService.get_by_name_async( | ||
| model_service_name, config=config | ||
| ) | ||
|
|
||
| # 获取 provider_settings | ||
| if not model_service.provider_settings: | ||
| raise ValueError( | ||
| f"ModelService {model_service_name} providerSettings is empty" | ||
| ) | ||
|
|
||
| base_url = model_service.provider_settings.base_url or "" | ||
| api_key = model_service.provider_settings.api_key or "" | ||
|
|
||
| # 如果有 credentialName,使用高层 API 获取 credential secret | ||
| credential_name = model_service.credential_name | ||
| if credential_name: | ||
| credential = await Credential.get_by_name_async( | ||
| credential_name, config=config | ||
| ) | ||
| if credential.credential_secret: | ||
| api_key = credential.credential_secret | ||
|
|
||
| if not base_url: | ||
| raise ValueError( | ||
| f"ModelService {model_service_name} baseUrl is empty" | ||
| ) | ||
|
|
||
| return base_url, api_key | ||
|
|
||
| @staticmethod | ||
| def _resolve_model_service_config( | ||
| model_service_name: str, config: Optional[Config] | ||
| ) -> Tuple[str, str]: | ||
| """解析 ModelService 配置获取 baseUrl 和 apiKey(同步) | ||
|
|
||
| Args: | ||
| model_service_name: ModelService 名称 | ||
| config: AgentRun 配置 | ||
|
|
||
| Returns: | ||
| Tuple[str, str]: (base_url, api_key) | ||
|
|
||
| Raises: | ||
| ValueError: 如果配置信息不完整 | ||
| """ | ||
| from agentrun.credential import Credential | ||
| from agentrun.model import ModelService | ||
|
|
||
| # 使用高层 API 获取 ModelService | ||
| model_service = ModelService.get_by_name( | ||
| model_service_name, config=config | ||
| ) | ||
|
|
||
| # 获取 provider_settings | ||
| if not model_service.provider_settings: | ||
| raise ValueError( | ||
| f"ModelService {model_service_name} providerSettings is empty" | ||
| ) | ||
|
|
||
| base_url = model_service.provider_settings.base_url or "" | ||
| api_key = model_service.provider_settings.api_key or "" | ||
|
|
||
| # 如果有 credentialName,使用高层 API 获取 credential secret | ||
| credential_name = model_service.credential_name | ||
| if credential_name: | ||
| credential = Credential.get_by_name(credential_name, config=config) | ||
| if credential.credential_secret: | ||
| api_key = credential.credential_secret | ||
|
|
||
| if not base_url: | ||
| raise ValueError( | ||
| f"ModelService {model_service_name} baseUrl is empty" | ||
| ) | ||
|
|
||
| return base_url, api_key |
There was a problem hiding this comment.
The new MemoryCollection module lacks test coverage. The repository has comprehensive test coverage for other modules (agent_runtime, credential, model, toolset) in the tests/unittests directory, but there are no tests for the memory_collection module. Consider adding unit tests to cover the client, model, and memory_collection classes, especially for critical functionality like the mem0 integration and error handling.
| # 方式一:使用 Client | ||
| # Method 1: Using Client | ||
| print("=== 使用 MemoryCollectionClient ===") | ||
| client = MemoryCollectionClient(config) |
There was a problem hiding this comment.
Variable client is not used.
|
|
||
| # 创建记忆集合 | ||
| # Create memory collection | ||
| create_input = MemoryCollectionCreateInput( |
There was a problem hiding this comment.
Variable create_input is not used.
agentrun/memory_collection/model.py
Outdated
| Defines data models and enumerations related to memory collections. | ||
| """ | ||
|
|
||
| from typing import Any, Dict, List, Optional |
There was a problem hiding this comment.
Import of 'Any' is not used.
Import of 'Dict' is not used.
| from typing import Any, Dict, List, Optional | |
| from typing import List, Optional |
Change-Id: I096c2a825dac99b411fa69db63cc6693cd67630e Co-developed-by: Cursor <noreply@cursor.com> Signed-off-by: 久氢 <mapenghui.mph@alibaba-inc.com>
Change-Id: I187d0e5d54abc79d4ed3d256253bd442988a9ff7 Co-developed-by: Cursor <noreply@cursor.com> Signed-off-by: 久氢 <mapenghui.mph@alibaba-inc.com>
d762343
Change-Id: I096c2a825dac99b411fa69db63cc6693cd67630e
Co-developed-by: Cursor noreply@cursor.com
Fix bugs
Bug detail
Pull request tasks
Update docs
Reason for update
Pull request tasks
Add contributor
Contributed content
Content detail
Others
Reason for update