Commit Graph

17 Commits

Author SHA1 Message Date
minecraft1024a
9d705463ce ruff fix但指定了--unsafe-fixes 2025-10-05 21:48:32 +08:00
John Richard
7923eafef3 re-style: 格式化代码 2025-10-02 20:26:01 +08:00
John Richard
ecb02cae31 style: 格式化代码 2025-10-02 19:38:39 +08:00
Windpicker-owo
dc39fd26c7 feat(memory): 重构记忆系统并移除插件热重载
重构记忆系统核心模块,引入全局记忆作用域、记忆指纹去重机制和查询规划器,优化多阶段检索性能。移除插件热重载系统及其相关依赖。

主要变更:
- 引入全局记忆作用域,简化记忆管理
- 实现记忆指纹去重,避免重复记忆存储
- 新增查询规划器,支持语义查询规划和记忆类型过滤
- 优化多阶段检索,增加语义重排和权重配置
- 改进向量存储,支持嵌入维度自动解析和查询向量生成
- 增强元数据索引,支持主体索引和更新操作
- 记忆构建器支持多主体和自然语言展示
- 移除watchdog依赖和插件热重载模块
- 更新配置模板,简化记忆配置项

BREAKING CHANGE: 移除插件热重载系统,相关API和命令不再可用。记忆系统接口有较大调整,使用该系统的模块需要适配新接口。
2025-10-01 04:56:32 +08:00
雅诺狐
898208f425 perf(methods): 通过移除不必要的 self 参数优化方法签名
在包括 chat、plugin_system、schedule 和 mais4u 在内的多个模块中,消除冗余的实例引用。此次改动将无需访问实例状态的实用函数转换为静态方法,从而提升了内存效率,并使方法依赖关系更加清晰。
2025-09-20 10:55:06 +08:00
Windpicker-owo
8149731925 修复代码格式和文件名大小写问题 2025-08-31 20:50:17 +08:00
minecraft1024a
eb1feeeb0b refactor(cache): 重构工具缓存机制并优化LLM请求重试逻辑
将工具缓存的实现从`ToolExecutor`的装饰器模式重构为直接集成。缓存逻辑被移出`cache_manager.py`并整合进`ToolExecutor.execute_tool_call`方法中,简化了代码结构并使其更易于维护。

主要变更:
- 从`cache_manager.py`中移除了`wrap_tool_executor`函数。
- 在`tool_use.py`中,`execute_tool_call`现在包含完整的缓存检查和设置逻辑。
- 调整了`llm_models/utils_model.py`中的LLM请求逻辑,为模型生成的空回复或截断响应增加了内部重试机制,增强了稳定性。
- 清理了项目中未使用的导入和过时的文档文件,以保持代码库的整洁。
2025-08-28 20:10:32 +08:00
minecraft1024a
7ba3b7f34d refactor(core): remove tool history manager and integrate cache into tool executor
Removes the `ToolHistoryManager` and its associated functionalities, including history recording, querying, and prompt generation. This simplifies the architecture by decoupling tool execution history from the core logic.

The tool caching mechanism is now directly integrated into the `ToolExecutor` by wrapping the `execute_tool_call` method. This ensures that caching is applied consistently for all tool executions that have it enabled, improving performance and reducing redundant calls.

- Deletes `src/common/tool_history.py`.
- Removes tool history related functions from `prompt_builder.py` and `tool_api.py`.
- Adds a `wrap_tool_executor` function in `cache_manager.py` to apply caching logic directly to the `ToolExecutor`.
2025-08-28 18:42:17 +08:00
minecraft1024a
4ced72010b feat(core): 集成统一向量数据库服务并重构相关模块
本次提交引入了一个统一的、可扩展的向量数据库服务层,旨在解决代码重复、实现分散以及数据库实例泛滥的问题。

主要变更:

新增向量数据库抽象层:

在 src/common/vector_db/ 目录下创建了 VectorDBBase 抽象基类,定义了标准化的数据库操作接口。
创建了 ChromaDBImpl 作为具体的实现,并采用单例模式确保全局只有一个数据库客户端实例。
重构语义缓存 (CacheManager):

移除了对 chromadb 库的直接依赖。
改为调用统一的 vector_db_service 来进行向量的添加和查询操作。
重构瞬时记忆 (VectorInstantMemoryV2):

彻底解决了为每个 chat_id 创建独立数据库实例的问题。
现在所有记忆数据都存储在统一的 instant_memory 集合中,并通过 metadata 中的 chat_id 进行数据隔离和查询。
新增使用文档:

在 docs/ 目录下添加了 vector_db_usage_guide.md,详细说明了如何使用新的 vector_db_service 代码接口。
带来的好处:

高内聚,低耦合: 业务代码与具体的向量数据库实现解耦。
易于维护和扩展: 未来可以轻松替换或添加新的向量数据库支持。
性能与资源优化: 整个应用共享一个数据库连接,显著减少了文件句柄和内存占用
2025-08-27 19:18:28 +08:00
雅诺狐
4a44ba9866 全面更换orjson 2025-08-26 14:20:26 +08:00
minecraft1024a
9149407370 fix(cache): 兼容元组形式的 embedding_result
get_embedding 方法的返回值可能是一个包含向量和模型名称的元组
2025-08-19 20:19:51 +08:00
雅诺狐
5e91f9ef5f Remove unused imports across multiple modules
Cleaned up various files by removing unused or redundant import statements to improve code readability and reduce potential confusion. No functional changes were made.
2025-08-19 11:55:24 +08:00
minecraft1024a
fb02896359 feat(cache): 用文件修改时间替换源码哈希生成缓存键
BREAKING CHANGE: CacheManager 的 _generate_key/get/set 方法签名变更,现在需要传入 tool_file_path 而非 tool_class 实例,所有调用方需跟进适配。
2025-08-18 20:07:59 +08:00
雅诺狐
bcbcabb0d8 Refactor cache L2 storage to use SQLAlchemy DB
Replaces the L2 cache layer's SQLite implementation with an async SQLAlchemy-based database model (CacheEntries). Updates cache_manager.py to use db_query and db_save for cache operations, adds semantic cache handling with ChromaDB, and introduces async cache clearing and expiration cleaning methods. Adds the CacheEntries model and integrates it into the database API.
2025-08-18 18:30:17 +08:00
minecraft1024a
c47d666d07 chore(deps): 移除未使用的 ModelTaskConfig 导入
从 cache_manager.py 文件中删除了对 `src.config.api_ada_configs` 中 `ModelTaskConfig` 的导入,因为它在该文件中并未被使用。

添加了记忆系统的大饼

Co-authored-by: 雅诺狐 <foxcyber907@users.noreply.github.com>
2025-08-18 11:54:00 +08:00
minecraft1024a
51c0d2a1e8 refactor(cache): 重构缓存系统为分层语义缓存
将原有的基于文件的 `ToolCache` 替换为全新的 `CacheManager`,引入了更复杂和高效的分层语义缓存机制。

新系统特性:
- **分层缓存**:
  - L1 缓存: 内存字典 (KV) + FAISS (向量),用于极速访问。
  - L2 缓存: SQLite (KV) + ChromaDB (向量),用于持久化存储。
- **语义缓存**: 利用嵌入模型 (Embedding) 对查询进行向量化,实现基于语义相似度的缓存命中,显著提高了缓存命中率。
- **自动失效**: 缓存键包含工具源代码的哈希值,当工具代码更新时,相关缓存会自动失效,避免了脏数据问题。
- **异步支持**: 缓存的 `get` 和 `set` 方法现在是异步的,以适应项目中异步化的工具调用流程。

`web_search_tool` 已更新以使用新的 `CacheManager`,在调用缓存时传递 `tool_class` 和 `semantic_query` 以充分利用新功能。

Co-Authored-By: tt-P607 <68868379+tt-P607@users.noreply.github.com>
2025-08-17 22:18:26 +08:00
雅诺狐
74ae472005 Add ToolCache class for tool result caching
Introduces a ToolCache class to manage caching of tool invocation results with support for both exact and approximate (similarity-based) query matching. Includes methods for cache retrieval, storage, expiration, cleanup, and statistics. This helps improve efficiency by reusing previous results and reducing redundant tool executions.

Co-Authored-By: tt-P607 <68868379+tt-P607@users.noreply.github.com>
2025-08-17 21:06:25 +08:00