Skip to content
Merged
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


repos:
- repo: https://github.com/pycqa/flake8.git
rev: 4.0.0
Expand All @@ -7,7 +9,8 @@ repos:
(?x)^(
thirdparty/|
examples/|
tests/run.py
tests/run.py|
ms_agent/utils/prompts.py
)$
- repo: https://github.com/PyCQA/isort.git
rev: 4.3.21
Expand Down
2 changes: 1 addition & 1 deletion ms_agent/agent/agent.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
llm:
service: modelscope
model: Qwen/Qwen3-235B-A22B
model: Qwen/Qwen3-235B-A22B-Instruct-2507
modelscope_api_key:
modelscope_base_url: https://api-inference.modelscope.cn/v1

Expand Down
6 changes: 3 additions & 3 deletions ms_agent/agent/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ms_agent.config import Config
from ms_agent.config.config import ConfigLifecycleHandler
from ms_agent.llm import Message
from omegaconf import DictConfig
from omegaconf import DictConfig, OmegaConf

DEFAULT_YAML = os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'agent.yaml')
Expand Down Expand Up @@ -43,10 +43,10 @@ def __init__(self,
trust_remote_code: bool = False):
if config_dir_or_id is not None:
self.config: DictConfig = Config.from_task(config_dir_or_id, env)
elif config is not None:
self.config: DictConfig = config
else:
self.config: DictConfig = Config.from_task(DEFAULT_YAML)
if config is not None and isinstance(config, DictConfig):
self.config = OmegaConf.merge(self.config, config)

if tag is None:
self.tag = getattr(config, 'tag', None) or self.DEFAULT_TAG
Expand Down
29 changes: 18 additions & 11 deletions ms_agent/agent/llm_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,24 @@ async def _prepare_messages(
messages = await self.rag.query(messages[1].content)
return messages

async def _prepare_memory(self):
async def _prepare_memory(self,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add function comments for key functions in the form of:

"""
Prepare memory ...

Args:
...

Returns:
...

Raises: (Optional)
....
"""

messages: Optional[List[Message]] = None,
**kwargs):
"""Load and initialize memory components from the config."""
config, runtime, cache_messages = self._read_history(
messages, **kwargs)
if hasattr(self.config, 'memory'):
for _memory in (self.config.memory or []):
assert _memory.name in memory_mapping, (
f'{_memory.name} not in memory_mapping, '
f'which supports: {list(memory_mapping.keys())}')
self.memory_tools.append(memory_mapping[_memory.name](
self.config))
memory_type = getattr(self.config.memory, 'name', 'default_memory')
assert memory_type in memory_mapping, (
f'{memory_type} not in memory_mapping, '
f'which supports: {list(memory_mapping.keys())}')

self.memory_tools.append(memory_mapping[memory_type](
self.config, conversation_id=self.task))

if messages != cache_messages:
runtime.should_stop = False
return config, runtime, cache_messages

async def _prepare_planer(self):
"""Load and initialize the planer component from the config."""
Expand Down Expand Up @@ -469,13 +478,11 @@ async def _run(self, messages: Union[List[Message], str],
self._prepare_llm()
self._prepare_runtime()
await self._prepare_tools()
await self._prepare_memory()
await self._prepare_planer()
await self._prepare_rag()
self.runtime.tag = self.tag

self.config, self.runtime, messages = self._read_history(
self.config, self.runtime, messages = await self._prepare_memory(
messages, **kwargs)
self.runtime.tag = self.tag

if self.runtime.round == 0:
# 0 means no history
Expand Down
2 changes: 1 addition & 1 deletion ms_agent/agent/memory/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Copyright (c) Alibaba, Inc. and its affiliates.
from .base import Memory
from .utils import memory_mapping
from .utils import DefaultMemory, memory_mapping
3 changes: 3 additions & 0 deletions ms_agent/agent/memory/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
class Memory:
"""The memory refine tool"""

def __init__(self, config):
self.config = config

@abstractmethod
async def run(self, messages: List[Message]) -> List[Message]:
"""Refine the messages
Expand Down
Loading
Loading