Skip to content

Commit b379c08

Browse files
authored
fix(memory): fix the memory compression functionality (#1107)
1 parent 7e49340 commit b379c08

File tree

3 files changed

+94
-10
lines changed

3 files changed

+94
-10
lines changed

CONTRIBUTING.md

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,27 @@ examples/
185185

186186
### Adding New Examples
187187

188-
We highly encourage contributions of new examples that showcase the capabilities of AgentScope.
189-
Please add them to the `examples/` directory with a clear README explaining the purpose and usage of the example.
188+
We highly encourage contributions of new examples that showcase the capabilities of AgentScope! Your examples help others learn and get inspired.
190189

191-
Now our examples are organized into subdirectories based on their type:
190+
**📝 About the Examples Directory:**
191+
192+
To maintain code quality and keep the repository accessible for everyone, we've designed the `examples/` directory in the main AgentScope repository to focus on **demonstrating AgentScope's functionalities**. Think of these as educational references and feature showcases that help developers quickly understand what AgentScope can do.
193+
194+
**What makes a great example here:**
195+
- Clearly demonstrates specific AgentScope features or capabilities
196+
- Easy to understand and follow along
197+
- Serves as a learning material or reference implementation
198+
- Focused and concise
199+
200+
**For More Complex Applications:**
201+
202+
Have you built something amazing with AgentScope? Perhaps a more sophisticated, production-ready application? That's fantastic! 🎉
203+
204+
We'd love to see your work in our **[agentscope-samples](https://github.com/agentscope-ai/agentscope-samples)** repository. This dedicated space is perfect for showcasing complete, real-world applications and sharing your AgentScope-based projects with the community. It's a great way to inspire others and demonstrate the full potential of the AgentScope ecosystem!
205+
206+
**Example Organization:**
207+
208+
Examples in the main repository are organized into subdirectories based on their type:
192209

193210
- `examples/agent/` for specialized agents
194211
- `examples/functionality/` for showcasing specific functionalities of AgentScope
@@ -208,6 +225,31 @@ examples/
208225
└── ... # The other scripts
209226
```
210227

228+
### Adding New Memory Databases
229+
230+
The memory module in AgentScope currently supports:
231+
232+
- **In-memory storage**: For lightweight, temporary memory needs
233+
- **Relational databases via SQLAlchemy**: For persistent, structured data storage
234+
- **NoSQL databases**: For flexible schema requirements (e.g., Redis)
235+
236+
**⚠️ Important Notice:**
237+
238+
For **relational databases**, we use **SQLAlchemy** as a unified abstraction layer. SQLAlchemy already supports a wide
239+
range of SQL databases including PostgreSQL, MySQL, SQLite, Oracle, Microsoft SQL Server, and many others.
240+
241+
**Therefore, we do not accept separate implementations for relational databases that are already supported by SQLAlchemy.**
242+
If you need support for a specific relational database, please ensure it works through the existing SQLAlchemy integration.
243+
244+
**If you wish to contribute a new memory database implementation**, please consider:
245+
246+
1. **For relational databases**: Use the existing SQLAlchemy integration.
247+
248+
2. **For NoSQL databases**: If you're adding support for a new NoSQL database (e.g., MongoDB, Cassandra), please:
249+
- Implement a new memory class that extends the appropriate base class
250+
- Add comprehensive unit tests
251+
- Update documentation accordingly
252+
211253

212254
## Do's and Don'ts
213255

CONTRIBUTING_zh.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,30 @@ examples/
182182

183183
### 添加新的示例
184184

185+
欢迎开源社区贡献新的示例来展示 AgentScope 的各种功能!
185186

186-
请将它们添加到 `examples/` 目录,并附上清晰的 README 说明示例的目的和用法。
187+
**📝 关于示例目录:**
187188

188-
目前我们的示例根据类型组织到子目录中:
189-
- `examples/functionality/` 用于展示 AgentScope 的特定基础功能
190-
- `examples/evaluation/` 用于评估
189+
为了避免仓库变得过于臃肿,我们将 AgentScope 仓库中的 `examples/` 目录设计为专注于**展示 AgentScope 的功能性**。可以把这些示例看作是指导性的参考和功能展示,帮助开发者快速理解 AgentScope 能做什么。
190+
191+
**什么样的示例适合放在这里:**
192+
- 清晰地展示 AgentScope 的特定功能或能力
193+
- 易于理解和跟随学习
194+
- 作为学习材料或参考实现
195+
- 专注且简洁
196+
197+
**对于更复杂的应用:**
198+
199+
对于更加复杂,生产就绪的应用,我们非常期待在 **[agentscope-samples](https://github.com/agentscope-ai/agentscope-samples)** 仓库中看到您的作品。这个仓库专门用于展示、分享基于 AgentScope 生态搭建的完整的、真实世界的应用。
200+
201+
**示例组织方式:**
202+
203+
主仓库中的示例根据类型组织到子目录中:
204+
205+
- `examples/agent/` 用于专门的智能体
206+
- `examples/functionality/` 用于展示 AgentScope 的特定功能
207+
- `examples/game/` 用于游戏相关示例
208+
- `examples/evaluation/` 用于评估脚本
191209
- `examples/workflows/` 用于工作流演示
192210
- `examples/training/` 用于训练相关示例
193211

@@ -202,6 +220,30 @@ examples/
202220
└── ... # 其他脚本
203221
```
204222

223+
### 添加新的记忆数据库
224+
225+
AgentScope 的记忆模块目前支持:
226+
227+
- **内存存储**:用于轻量级的临时记忆需求
228+
- **通过 SQLAlchemy 支持关系型数据库**:用于持久化的结构化数据存储
229+
- **NoSQL 数据库**:用于灵活的模式需求(例如 Redis)
230+
231+
**⚠️ 请注意:**
232+
233+
对于**关系型数据库**,我们使用 **SQLAlchemy** 作为统一的抽象层。SQLAlchemy 已经支持多种 SQL 数据库,包括 PostgreSQL、MySQL、SQLite、Oracle、Microsoft SQL Server 等。
234+
235+
**因此,为了保持 AgentScope 代码的整洁,目前不接受为 SQLAlchemy 已经支持的关系型数据库单独实现新的支持。**
236+
如果您需要支持特定的关系型数据库,请确保通过现有的 SQLAlchemy 集成来实现。
237+
238+
**如果您希望贡献新的记忆数据库实现**,请考虑以下几点:
239+
240+
1. **对于关系型数据库**:使用现有的 SQLAlchemy 集成。
241+
242+
2. **对于 NoSQL 数据库**:如果您要添加对新 NoSQL 数据库的支持(例如 MongoDB、Cassandra),请:
243+
- 实现一个扩展适当基类的新记忆类
244+
- 添加全面的单元测试
245+
- 相应地更新文档
246+
205247

206248
## Do's and Don'ts
207249

src/agentscope/agent/_react_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,6 @@ async def reply( # pylint: disable=too-many-branches
401401
# Retrieve relevant documents from the knowledge base(s) if any
402402
await self._retrieve_from_knowledge(msg)
403403

404-
# -------------- Memory compression --------------
405-
await self._compress_memory_if_needed()
406-
407404
# Control if LLM generates tool calls in each reasoning step
408405
tool_choice: Literal["auto", "none", "required"] | None = None
409406

@@ -433,6 +430,9 @@ async def reply( # pylint: disable=too-many-branches
433430
structured_output = None
434431
reply_msg = None
435432
for _ in range(self.max_iters):
433+
# -------------- Memory compression --------------
434+
await self._compress_memory_if_needed()
435+
436436
# -------------- The reasoning process --------------
437437
msg_reasoning = await self._reasoning(tool_choice)
438438

0 commit comments

Comments
 (0)