Skip to content

feat: memorycollection implement#32

Merged
2 commits merged intoServerless-Devs:mainfrom
penghuima:dev
Jan 13, 2026
Merged

feat: memorycollection implement#32
2 commits merged intoServerless-Devs:mainfrom
penghuima:dev

Conversation

@penghuima
Copy link
Collaborator

Change-Id: I096c2a825dac99b411fa69db63cc6693cd67630e
Co-developed-by: Cursor noreply@cursor.com

Thank you for creating a pull request to contribute to Serverless Devs agentrun-sdk-python code! Before you open the request please answer the following questions to help it be more easily integrated. Please check the boxes "[ ]" with "[x]" when done too.
Please select one of the PR types below to complete


Fix bugs

Bug detail

The specific manifestation of the bug or the associated issue.

Pull request tasks

  • Add test cases for the changes
  • Passed the CI test

Update docs

Reason for update

Why do you need to update your documentation?

Pull request tasks

  • Update Chinese documentation
  • Update English documentation

Add contributor

Contributed content

  • Code
  • Document

Content detail

if content_type == 'code' || content_type == 'document':
    please tell us `PR url`,like: https://github.com/Serverless-Devs/agentrun-sdk-python/pull/1
else:
    please describe your contribution in detail

Others

Reason for update

Why do you need to update your documentation?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_collection module with client, models, high-level API, and control API
  • Implements mem0ai integration through a to_mem0_memory method that converts MemoryCollection to mem0 Memory client
  • Adds optional dependency agentrun-mem0ai>=0.0.3 in 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.

Comment on lines 1 to 844
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
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
# 方式一:使用 Client
# Method 1: Using Client
print("=== 使用 MemoryCollectionClient ===")
client = MemoryCollectionClient(config)
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Variable client is not used.

Copilot uses AI. Check for mistakes.

# 创建记忆集合
# Create memory collection
create_input = MemoryCollectionCreateInput(
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Variable create_input is not used.

Copilot uses AI. Check for mistakes.
Defines data models and enumerations related to memory collections.
"""

from typing import Any, Dict, List, Optional
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Import of 'Any' is not used.
Import of 'Dict' is not used.

Suggested change
from typing import Any, Dict, List, Optional
from typing import List, Optional

Copilot uses AI. Check for mistakes.
久氢 added 2 commits January 13, 2026 12:08
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>
@OhYee OhYee closed this pull request by merging all changes into Serverless-Devs:main in d762343 Jan 13, 2026
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.

2 participants