* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 读取的接口,去掉全局锁
* 输出数组
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化测试接口
* 反思优化测试接口
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 把group_id替换end_user_id
* 把group_id替换end_user_id_
* 把group_id替换end_user_id_
* config_config替换成memory_config
* config_config替换成memory_config
* [fix]Fix the memory interface to use end_user_id.
* config_config替换成memory_config
* config_config替换成memory_config
* config_config替换成memory_config
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID,与develop校对恢复
* 检查项目,修复group_id的遗留问题
* 检查项目,修复group_id的遗留问题
* Fix/interface home (#182)
* [fix]Fix the interface for statistics of recent activities and applications
* [changes]Modify the code based on the AI review
1.Use the boolean auxiliary methods provided by SQLAlchemy instead of using == True in the is_active filter.
2.The calculation of the "PROJECT_ROOT" has now been hardcoded with five levels of nested os.path.dirname calls.
* [fix]Fix the interface for statistics of recent activities and applications
* [changes]Modify the code based on the AI review
1.Use the boolean auxiliary methods provided by SQLAlchemy instead of using == True in the is_active filter.
2.The calculation of the "PROJECT_ROOT" has now been hardcoded with five levels of nested os.path.dirname calls.
* Fix/optimize inerface (#183)
* [changes]Optimize the time consumption of the "/end_users" interface
* [fix]Optimize the time consumption of the "/hot_memory_tags" interface
* [changes]Optimize the time consumption of the "/end_users" interface
* [fix]Optimize the time consumption of the "/hot_memory_tags" interface
* [changes]Improve the code based on AI review
* Fix/memory mcp2 1 (#184)
* 优化快速检索的回复内容
* 优化快速检索的回复内容
* Fix/memory mcp2 1 (#185)
* 优化快速检索的回复内容
* 优化快速检索的回复内容
* 路径的BUG修复
* 路径的BUG修复
* 路径的BUG修复
* 路径的BUG修复
* 路径的BUG修复
* Fix/memory mcp2 1 (#188)
* 优化快速检索的回复内容
* 优化快速检索的回复内容
* 路径的BUG修复
* 路径的BUG修复
* 路径的BUG修复
* 路径的BUG修复
* 路径的BUG修复
* LLM生存缺少config_id认证,修复BUG
* LLM生存缺少config_id认证,修复BUG
* LLM生存缺少config_id认证,修复BUG
* 解决冲突
* 解决冲突
* feat(home page): version description update
* Fix/memory mcp2 1 (#190)
* 优化快速检索的回复内容
* 优化快速检索的回复内容
* 路径的BUG修复
* 路径的BUG修复
* 路径的BUG修复
* 路径的BUG修复
* 路径的BUG修复
* LLM生存缺少config_id认证,修复BUG
* LLM生存缺少config_id认证,修复BUG
* LLM生存缺少config_id认证,修复BUG
* 深度检索优化,搜索不到数据/提问的概念过于蘑菇,以引导的方式继续提问
* 深度检索优化,搜索不到数据/提问的概念过于蘑菇,以引导的方式继续提问
* 深度检索优化,搜索不到数据/提问的概念过于蘑菇,以引导的方式继续提问
* end_user_id清理干净
* end_user_id清理干净
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* feat(web): memory related interface parameter transfer adjustment
* 感知meta_data字段BUG修复
* Fix/memory bug fix (#171)
* feat(sandbox): add Python 3 code execution sandbox support
* feat(workflow): emit SSE events for node exception output
* perf(sandbox): optimize code encryption handling
* perf(workflow): update standard node output structure
* [add] migration script
* [modify] migration script
* feat(web): add workflow runtime info
* fix(web): handleSSE bugfix
* fix(sandbox): prevent imports from being blocked when network is disabled
* user_id->现实为config_id_old
* user_id->显示为config_id_old传输
* Fix/memory bug fix (#199)
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 读取的接口,去掉全局锁
* 输出数组
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化测试接口
* 反思优化测试接口
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 把group_id替换end_user_id
* 把group_id替换end_user_id_
* 把group_id替换end_user_id_
* config_config替换成memory_config
* config_config替换成memory_config
* [fix]Fix the memory interface to use end_user_id.
* config_config替换成memory_config
* config_config替换成memory_config
* config_config替换成memory_config
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID,与develop校对恢复
* 检查项目,修复group_id的遗留问题
* 检查项目,修复group_id的遗留问题
* 解决冲突
* 解决冲突
* end_user_id清理干净
* end_user_id清理干净
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 感知meta_data字段BUG修复
* user_id->现实为config_id_old
* user_id->显示为config_id_old传输
---------
Co-authored-by: lanceyq <1982376970@qq.com>
* user_id->显示为config_id_old传输
* feat(web): update read_all_config select valueKey
* user_id->显示为config_id_old传输
* feat(workflow): Add a new node for executing code
* fix(web): KnowledgeConfigModal bugfix
* fix(web): iteration's variable add parameter-extractor node
* fix(sandbox): treat non-zero exit codes as errors instead of relying only on stderr
* Fix/memory bug fix (#200)
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 读取的接口,去掉全局锁
* 输出数组
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化测试接口
* 反思优化测试接口
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 把group_id替换end_user_id
* 把group_id替换end_user_id_
* 把group_id替换end_user_id_
* config_config替换成memory_config
* config_config替换成memory_config
* [fix]Fix the memory interface to use end_user_id.
* config_config替换成memory_config
* config_config替换成memory_config
* config_config替换成memory_config
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID,与develop校对恢复
* 检查项目,修复group_id的遗留问题
* 检查项目,修复group_id的遗留问题
* 解决冲突
* 解决冲突
* end_user_id清理干净
* end_user_id清理干净
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 感知meta_data字段BUG修复
* user_id->现实为config_id_old
* user_id->显示为config_id_old传输
* user_id->显示为config_id_old传输
* user_id->显示为config_id_old传输
---------
Co-authored-by: lanceyq <1982376970@qq.com>
* Refactor/benchmark test (#196)
* [changes]refactor locomo_test
* [fix]Fix the circular import of ModelParameters
* [changes]The benchmark test can run stably.
* [fix]Complete end-to-end LoCoMo repair
* [fix]Complete the end-to-end longmemeval and memsciqa fixes
* [changes]Complete the benchmark test description document to ensure that the configuration parameters take effect.
* [changes]refactor locomo_test
* [fix]Fix the circular import of ModelParameters
* [changes]The benchmark test can run stably.
* [fix]Complete end-to-end LoCoMo repair
* [fix]Complete the end-to-end longmemeval and memsciqa fixes
* [changes]Complete the benchmark test description document to ensure that the configuration parameters take effect.
* [changes]Benchmark test adaptation for end_user_id
* [changes]refactor locomo_test
* [fix]Fix the circular import of ModelParameters
* [changes]The benchmark test can run stably.
* [fix]Complete end-to-end LoCoMo repair
* [fix]Complete the end-to-end longmemeval and memsciqa fixes
* [changes]Complete the benchmark test description document to ensure that the configuration parameters take effect.
* [fix]Complete the end-to-end longmemeval and memsciqa fixes
* [changes]Complete the benchmark test description document to ensure that the configuration parameters take effect.
* [changes]Benchmark test adaptation for end_user_id
* [modify] migration script
* delete benchmark-test (#204)
* Refactor: Move evaluation folder to redbear-mem-benchmark submodule
* [changes]Restore .gitmodules
* feat(web): workflow add code node
* 检查需要更改的格式问题
* Fix/redbear benchmark (#205)
* Refactor: Move evaluation folder to redbear-mem-benchmark submodule
* [changes]Update submodule reference
* Refactor: Move evaluation folder to redbear-mem-benchmark submodule
* [changes]Update submodule reference
* Remove duplicate evaluation submodule, use redbear-mem-benchmark instead
* Fix/memory bug fix (#207)
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 读取的接口,去掉全局锁
* 输出数组
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化测试接口
* 反思优化测试接口
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 把group_id替换end_user_id
* 把group_id替换end_user_id_
* 把group_id替换end_user_id_
* config_config替换成memory_config
* config_config替换成memory_config
* [fix]Fix the memory interface to use end_user_id.
* config_config替换成memory_config
* config_config替换成memory_config
* config_config替换成memory_config
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID,与develop校对恢复
* 检查项目,修复group_id的遗留问题
* 检查项目,修复group_id的遗留问题
* 解决冲突
* 解决冲突
* end_user_id清理干净
* end_user_id清理干净
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 感知meta_data字段BUG修复
* user_id->现实为config_id_old
* user_id->显示为config_id_old传输
* user_id->显示为config_id_old传输
* user_id->显示为config_id_old传输
* 检查需要更改的格式问题
---------
Co-authored-by: lanceyq <1982376970@qq.com>
* fix(web): remove URI decode and encode
* [add] plugin system and base sso module
* 修复宿主列表获取memory_config_idBUG
* Fix/memory bug fix (#209)
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 读取的接口,去掉全局锁
* 输出数组
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化测试接口
* 反思优化测试接口
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 把group_id替换end_user_id
* 把group_id替换end_user_id_
* 把group_id替换end_user_id_
* config_config替换成memory_config
* config_config替换成memory_config
* [fix]Fix the memory interface to use end_user_id.
* config_config替换成memory_config
* config_config替换成memory_config
* config_config替换成memory_config
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID,与develop校对恢复
* 检查项目,修复group_id的遗留问题
* 检查项目,修复group_id的遗留问题
* 解决冲突
* 解决冲突
* end_user_id清理干净
* end_user_id清理干净
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 感知meta_data字段BUG修复
* user_id->现实为config_id_old
* user_id->显示为config_id_old传输
* user_id->显示为config_id_old传输
* user_id->显示为config_id_old传输
* 检查需要更改的格式问题
* 修复宿主列表获取memory_config_idBUG
---------
Co-authored-by: lanceyq <1982376970@qq.com>
* [modify] file local server url
* [add] migration script
* fix(workflow): fix activation and branch control issues in streaming output
* fix(workflow): fix function cache not taking effect and potential list index overflow
* style(workflow): enforce PEP8 style and remove redundant imports
* fix(workflow): fix streaming output error when variable is not a string
* [fix]remove aspose-slides
* perf(workflow): enhance streaming output node activation performance
* feat(workflow): store token usage in message table
* feat(web): add PageEmpty component
* feat(web): add PageTabs component
* perf(workflow): make memory configuration backward compatible
* feat(web): update model management
* config_id做映射
* config_id做映射
* Fix/memory bug fix (#211)
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 读取的接口,去掉全局锁
* 输出数组
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化测试接口
* 反思优化测试接口
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 把group_id替换end_user_id
* 把group_id替换end_user_id_
* 把group_id替换end_user_id_
* config_config替换成memory_config
* config_config替换成memory_config
* [fix]Fix the memory interface to use end_user_id.
* config_config替换成memory_config
* config_config替换成memory_config
* config_config替换成memory_config
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID,与develop校对恢复
* 检查项目,修复group_id的遗留问题
* 检查项目,修复group_id的遗留问题
* 解决冲突
* 解决冲突
* end_user_id清理干净
* end_user_id清理干净
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 感知meta_data字段BUG修复
* user_id->现实为config_id_old
* user_id->显示为config_id_old传输
* user_id->显示为config_id_old传输
* user_id->显示为config_id_old传输
* 检查需要更改的格式问题
* 修复宿主列表获取memory_config_idBUG
* config_id做映射
* config_id做映射
---------
Co-authored-by: lanceyq <1982376970@qq.com>
* feat(web): getModelListUrl add is_active param
* config_id做映射+1
* config_id做映射+1
* config_id做映射+1
* feat(web): remove file url replace
* Fix/memory bug fix (#212)
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 读取的接口,去掉全局锁
* 输出数组
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化测试接口
* 反思优化测试接口
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 把group_id替换end_user_id
* 把group_id替换end_user_id_
* 把group_id替换end_user_id_
* config_config替换成memory_config
* config_config替换成memory_config
* [fix]Fix the memory interface to use end_user_id.
* config_config替换成memory_config
* config_config替换成memory_config
* config_config替换成memory_config
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID,与develop校对恢复
* 检查项目,修复group_id的遗留问题
* 检查项目,修复group_id的遗留问题
* 解决冲突
* 解决冲突
* end_user_id清理干净
* end_user_id清理干净
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 感知meta_data字段BUG修复
* user_id->现实为config_id_old
* user_id->显示为config_id_old传输
* user_id->显示为config_id_old传输
* user_id->显示为config_id_old传输
* 检查需要更改的格式问题
* 修复宿主列表获取memory_config_idBUG
* config_id做映射
* config_id做映射
* config_id做映射+1
* config_id做映射+1
* config_id做映射+1
---------
Co-authored-by: lanceyq <1982376970@qq.com>
* feat(model and app statistic): 1. Optimize the model list; 2. Increase the model combination; 3. Add a model square; 4. Add application management statistics
* feat(web): model logo update
* 应用层memory_content->memory_config
* fix(web): correct spelling
* 应用层memory_content->memory_config
* 应用层memory_content->memory_config
* Fix/memory bug fix (#215)
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 读取的接口,去掉全局锁
* 输出数组
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化测试接口
* 反思优化测试接口
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 把group_id替换end_user_id
* 把group_id替换end_user_id_
* 把group_id替换end_user_id_
* config_config替换成memory_config
* config_config替换成memory_config
* [fix]Fix the memory interface to use end_user_id.
* config_config替换成memory_config
* config_config替换成memory_config
* config_config替换成memory_config
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID,与develop校对恢复
* 检查项目,修复group_id的遗留问题
* 检查项目,修复group_id的遗留问题
* 解决冲突
* 解决冲突
* end_user_id清理干净
* end_user_id清理干净
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 感知meta_data字段BUG修复
* user_id->现实为config_id_old
* user_id->显示为config_id_old传输
* user_id->显示为config_id_old传输
* user_id->显示为config_id_old传输
* 检查需要更改的格式问题
* 修复宿主列表获取memory_config_idBUG
* config_id做映射
* config_id做映射
* config_id做映射+1
* config_id做映射+1
* config_id做映射+1
* 应用层memory_content->memory_config
* 应用层memory_content->memory_config
* 应用层memory_content->memory_config
---------
Co-authored-by: lanceyq <1982376970@qq.com>
* feat(model and app statistic): 1. Optimize the model list; 2. Increase the model combination; 3. Add a model square; 4. Add application management statistics
* fix(web): model loading update
* 统一字段为config_id_old
* 统一字段为config_id_old
* feat(model and app statistic): 1. Optimize the model list; 2. Increase the model combination; 3. Add a model square; 4. Add application management statistics
* 统一字段为config_id_old
* 统一字段为config_id_old
* memory_content暂时不修改
* memory_content暂时不修改
* Fix/memory bug fix (#217)
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 图谱数据量限制数量去掉
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 用户详情优化
* 读取的接口,去掉全局锁
* 输出数组
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化1.0(优化隐私输出、时间检索)
* 反思优化测试接口
* 反思优化测试接口
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 读取接口内层嵌套BUG修复
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 新增中翻英功能(记忆时间线)(用户摘要)(兴趣分布接口)(查询核心档案)(记忆洞察)-接口添加翻译字段
* 把group_id替换end_user_id
* 把group_id替换end_user_id_
* 把group_id替换end_user_id_
* config_config替换成memory_config
* config_config替换成memory_config
* [fix]Fix the memory interface to use end_user_id.
* config_config替换成memory_config
* config_config替换成memory_config
* config_config替换成memory_config
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID
* config_id字段改成UUID,与develop校对恢复
* 检查项目,修复group_id的遗留问题
* 检查项目,修复group_id的遗留问题
* 解决冲突
* 解决冲突
* end_user_id清理干净
* end_user_id清理干净
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 修复遗留合并BUG
* 感知meta_data字段BUG修复
* user_id->现实为config_id_old
* user_id->显示为config_id_old传输
* user_id->显示为config_id_old传输
* user_id->显示为config_id_old传输
* 检查需要更改的格式问题
* 修复宿主列表获取memory_config_idBUG
* config_id做映射
* config_id做映射
* config_id做映射+1
* config_id做映射+1
* config_id做映射+1
* 应用层memory_content->memory_config
* 应用层memory_content->memory_config
* 应用层memory_content->memory_config
* 统一字段为config_id_old
* 统一字段为config_id_old
* 统一字段为config_id_old
* 统一字段为config_id_old
* memory_content暂时不修改
* memory_content暂时不修改
---------
Co-authored-by: lanceyq <1982376970@qq.com>
* feat(web): add app statistics
* fix(workflow): fix streaming output issues with multi-output End nodes
End nodes with multiple output segments could cause cursor errors or leave some
segments inactive, resulting in incorrect final outputs.
Unified _emit_active_chunks and _update_scope_activate to ensure all segments
are activated in order and streamed correctly.
* feat(web): add apps statistics api
* fix(web): agent's knowledge_bases bugfix
* Revert "feat(web): update read_all_config select valueKey"
This reverts commit 46f0f3cee9.
* [add] migrations script
* perf(workflow): make memory write node backward-compatible and defer config validation
* 旧数据兼容
* 旧数据兼容
* 旧数据兼容
* 旧数据兼容
* fix(web): model bugfix
* fix(web): model bugfix
* 提交遗漏 (#228)
* [fix] chat api for workflow
* [fix] web search set for v1 api
* fix(web): model bugfix
* fix(web): model list remove is_active
* fix(model): bug fix
* [add]migration script
* [fix] api
* [fix] api
* fix(web): model bugfix
* fix(model): the model type does not allow modification, delete tts and speech2text type
* fix(model): bug fix
* 遗漏的历史映射
* 遗漏的历史映射
* 遗漏的历史映射
* Add/develop memory (#239)
* 遗漏的历史映射
* 遗漏的历史映射
* 遗漏的历史映射
* 遗漏的历史映射
* 遗漏的历史映射
* feat(web): model ui update
* feat(web): model ui update
* Add/develop memory (#243)
* 遗漏的历史映射
* 遗漏的历史映射
* fix(model): bug fix
* feat(web): model ui update
* Add/develop memory (#247)
* 遗漏的历史映射
* 遗漏的历史映射
* 遗漏的历史映射
* 遗漏的历史映射
* 遗漏的历史映射
* 遗漏的历史映射
* 遗漏的历史映射
* 遗漏的历史映射
* 遗漏的历史映射
* [modify] migration script
* [add] migration script
* fix(web): change form message
* fix(web): the memoryContent field is compatible with numbers and strings
* feat(web): code node hidden
* fix(model):
1. create a basic model to check if the name and provider are duplicated.
2. The result shows error models because the provider created API Keys for all matching models.
---------
Co-authored-by: lixinyue <2569494688@qq.com>
Co-authored-by: lanceyq <1982376970@qq.com>
Co-authored-by: yujiangping <yujiangping@taofen8.com>
Co-authored-by: 乐力齐 <162269739+lanceyq@users.noreply.github.com>
Co-authored-by: lixinyue11 <94037597+lixinyue11@users.noreply.github.com>
Co-authored-by: yingzhao <zhaoyingyz@126.com>
Co-authored-by: Timebomb2018 <18868801967@163.com>
Co-authored-by: Mark <zhuwenhui5566@163.com>
Co-authored-by: zhaoying <yzhao96@best-inc.com>
Co-authored-by: Eternity <1533512157@qq.com>
Co-authored-by: lixiangcheng1 <lixiangcheng1@wanda.cn>
620 lines
21 KiB
Python
620 lines
21 KiB
Python
"""多 Agent 配置管理服务"""
|
||
import uuid
|
||
from typing import Optional, List, Tuple, Any, Annotated
|
||
|
||
from fastapi import Depends
|
||
from sqlalchemy.orm import Session
|
||
from sqlalchemy import select, desc
|
||
|
||
from app.db import get_db
|
||
from app.models import MultiAgentConfig, App, AgentConfig
|
||
from app.schemas.multi_agent_schema import (
|
||
MultiAgentConfigCreate,
|
||
MultiAgentConfigUpdate,
|
||
MultiAgentRunRequest
|
||
)
|
||
from app.services.model_service import ModelApiKeyService
|
||
from app.services.multi_agent_orchestrator import MultiAgentOrchestrator
|
||
from app.core.exceptions import ResourceNotFoundException, BusinessException
|
||
from app.core.error_codes import BizCode
|
||
from app.core.logging_config import get_business_logger
|
||
from app.models import AppRelease
|
||
|
||
logger = get_business_logger()
|
||
|
||
|
||
def convert_uuids_to_str(obj: Any) -> Any:
|
||
"""递归转换对象中的所有 UUID 为字符串
|
||
|
||
Args:
|
||
obj: 要转换的对象(dict, list, UUID 等)
|
||
|
||
Returns:
|
||
转换后的对象
|
||
"""
|
||
if isinstance(obj, uuid.UUID):
|
||
return str(obj)
|
||
elif isinstance(obj, dict):
|
||
return {k: convert_uuids_to_str(v) for k, v in obj.items()}
|
||
elif isinstance(obj, list):
|
||
return [convert_uuids_to_str(item) for item in obj]
|
||
else:
|
||
return obj
|
||
|
||
|
||
class MultiAgentService:
|
||
"""多 Agent 配置管理服务"""
|
||
|
||
def __init__(self, db: Session):
|
||
self.db = db
|
||
|
||
def create_config(
|
||
self,
|
||
app_id: uuid.UUID,
|
||
data: MultiAgentConfigCreate,
|
||
created_by: uuid.UUID
|
||
) -> MultiAgentConfig:
|
||
"""创建多 Agent 配置
|
||
|
||
Args:
|
||
app_id: 应用 ID
|
||
data: 配置数据
|
||
created_by: 创建者 ID
|
||
|
||
Returns:
|
||
多 Agent 配置
|
||
"""
|
||
# 1. 验证应用存在
|
||
app = self.db.get(App, app_id)
|
||
if not app:
|
||
raise ResourceNotFoundException("应用", str(app_id))
|
||
|
||
# 2. 检查是否已有有效配置
|
||
existing = self.db.scalars(
|
||
select(MultiAgentConfig)
|
||
.where(
|
||
MultiAgentConfig.app_id == app_id,
|
||
MultiAgentConfig.is_active.is_(True)
|
||
)
|
||
.order_by(MultiAgentConfig.updated_at.desc())
|
||
).first()
|
||
if existing:
|
||
raise BusinessException("应用已有多 Agent 配置", BizCode.DUPLICATE_RESOURCE)
|
||
|
||
# 3. 验证主 Agent 存在
|
||
master_agent = self.db.get(AgentConfig, data.master_agent_id)
|
||
if not master_agent:
|
||
raise ResourceNotFoundException("主 Agent", str(data.master_agent_id))
|
||
|
||
# 4. 验证子 Agent 存在
|
||
for sub_agent in data.sub_agents:
|
||
agent = self.db.get(AgentConfig, sub_agent.agent_id)
|
||
if not agent:
|
||
raise ResourceNotFoundException("子 Agent", str(sub_agent.agent_id))
|
||
|
||
# 5. 创建配置(转换 UUID 为字符串以支持 JSON 序列化)
|
||
sub_agents_data = [convert_uuids_to_str(sub_agent.model_dump()) for sub_agent in data.sub_agents]
|
||
routing_rules_data = [convert_uuids_to_str(rule.model_dump()) for rule in data.routing_rules] if data.routing_rules else None
|
||
|
||
# 处理 execution_config(可能是 None、字典或 Pydantic 模型)
|
||
if data.execution_config is None:
|
||
execution_config_data = {}
|
||
elif isinstance(data.execution_config, dict):
|
||
execution_config_data = convert_uuids_to_str(data.execution_config)
|
||
else:
|
||
execution_config_data = convert_uuids_to_str(data.execution_config.model_dump())
|
||
|
||
config = MultiAgentConfig(
|
||
app_id=app_id,
|
||
master_agent_id=data.master_agent_id,
|
||
master_agent_name=data.master_agent_name,
|
||
orchestration_mode=data.orchestration_mode,
|
||
sub_agents=sub_agents_data,
|
||
routing_rules=routing_rules_data,
|
||
execution_config=execution_config_data,
|
||
aggregation_strategy=data.aggregation_strategy
|
||
)
|
||
|
||
self.db.add(config)
|
||
self.db.commit()
|
||
self.db.refresh(config)
|
||
|
||
logger.info(
|
||
"创建多 Agent 配置成功",
|
||
extra={
|
||
"config_id": str(config.id),
|
||
"app_id": str(app_id),
|
||
"mode": data.orchestration_mode,
|
||
"sub_agent_count": len(data.sub_agents)
|
||
}
|
||
)
|
||
|
||
return config
|
||
|
||
def get_config(self, app_id: uuid.UUID) -> Optional[MultiAgentConfig]:
|
||
"""获取多 Agent 配置
|
||
|
||
Args:
|
||
app_id: 应用 ID
|
||
|
||
Returns:
|
||
多 Agent 配置,如果不存在返回 None
|
||
"""
|
||
return self.db.scalars(
|
||
select(MultiAgentConfig)
|
||
.where(
|
||
MultiAgentConfig.app_id == app_id,
|
||
MultiAgentConfig.is_active.is_(True)
|
||
)
|
||
.order_by(MultiAgentConfig.updated_at.desc())
|
||
).first()
|
||
|
||
def get_multi_agent_configs(self, app_id: uuid.UUID) -> Optional[dict]:
|
||
"""通过 app_id 获取最新有效的多智能体配置,并将 agent_id 转换为 app_id
|
||
|
||
Args:
|
||
app_id: 应用 ID
|
||
|
||
Returns:
|
||
转换后的配置字典,如果不存在返回 None
|
||
"""
|
||
config = self.get_config(app_id)
|
||
if not config:
|
||
return None
|
||
|
||
#兼容代码
|
||
if not config.default_model_config_id:
|
||
master_release = self.db.get(AppRelease, config.master_agent_id)
|
||
config.default_model_config_id = master_release.default_model_config_id if master_release else None
|
||
|
||
# 转换 sub_agents 中的 agent_id (release_id) 为 app_id
|
||
converted_sub_agents = []
|
||
for sub_agent in config.sub_agents:
|
||
sub_agent_copy = sub_agent.copy()
|
||
release_id = sub_agent.get("agent_id")
|
||
if release_id:
|
||
try:
|
||
release_id_uuid = uuid.UUID(release_id) if isinstance(release_id, str) else release_id
|
||
sub_release = self.db.get(AppRelease, release_id_uuid)
|
||
if sub_release:
|
||
sub_agent_copy["agent_id"] = str(sub_release.app_id)
|
||
except Exception as e:
|
||
logger.warning(f"转换 sub_agent agent_id 失败: {release_id}, 错误: {str(e)}")
|
||
converted_sub_agents.append(sub_agent_copy)
|
||
|
||
# 构建返回的配置字典
|
||
return {
|
||
"id": config.id,
|
||
"app_id": config.app_id,
|
||
"default_model_config_id": config.default_model_config_id,
|
||
"model_parameters": config.model_parameters,
|
||
"orchestration_mode": config.orchestration_mode,
|
||
"sub_agents": converted_sub_agents,
|
||
"routing_rules": config.routing_rules,
|
||
"execution_config": config.execution_config,
|
||
"aggregation_strategy": config.aggregation_strategy,
|
||
"is_active": config.is_active,
|
||
"created_at": config.created_at,
|
||
"updated_at": config.updated_at
|
||
}
|
||
|
||
def get_published_config_by_agent_id(self, agent_id: uuid.UUID) -> Optional[dict]:
|
||
"""通过 agent_id 获取当前发布版本的完整配置
|
||
|
||
Args:
|
||
agent_id: Agent 配置 ID
|
||
|
||
Returns:
|
||
当前发布版本的配置字典,如果没有发布版本则返回 None
|
||
"""
|
||
from app.models import AppRelease
|
||
|
||
# 查询 Agent 配置
|
||
agent_config = self.db.get(AgentConfig, agent_id)
|
||
if not agent_config:
|
||
logger.warning(f"Agent 配置不存在: {agent_id}")
|
||
return None
|
||
|
||
# 获取关联的应用
|
||
app = self.db.get(App, agent_config.app_id)
|
||
if not app or not app.current_release_id:
|
||
logger.warning(f"应用未发布或不存在: app_id={agent_config.app_id}")
|
||
return None
|
||
|
||
# 获取当前发布版本
|
||
release = self.db.get(AppRelease, app.current_release_id)
|
||
if not release:
|
||
logger.warning(f"发布版本不存在: release_id={app.current_release_id}")
|
||
return None
|
||
|
||
# 从发布版本的 config 中获取完整配置
|
||
# config 是一个 JSON 对象,包含了发布时的配置快照
|
||
config_data = release.config
|
||
if config_data and isinstance(config_data, dict):
|
||
return config_data
|
||
|
||
return None
|
||
|
||
def get_published_by_agent_id(self, agent_id: uuid.UUID) -> Optional[AppRelease]:
|
||
"""通过 agent_id 获取当前发布版本的完整配置
|
||
|
||
Args:
|
||
agent_id: Agent 配置 ID
|
||
|
||
Returns:
|
||
当前发布版本的配置字典,如果没有发布版本则返回 None
|
||
"""
|
||
|
||
# 获取关联的应用
|
||
app = self.db.get(App, agent_id)
|
||
if not app or not app.current_release_id:
|
||
logger.warning(f"应用未发布或不存在: app_id={agent_id}")
|
||
return None
|
||
|
||
# 获取当前发布版本
|
||
release = self.db.get(AppRelease, app.current_release_id)
|
||
if not release:
|
||
logger.warning(f"发布版本不存在: release_id={app.current_release_id}")
|
||
return None
|
||
return release
|
||
|
||
def check_config_data(self,app_id: uuid.UUID, data: MultiAgentConfigUpdate) -> MultiAgentConfig:
|
||
# 1. 验证应用存在
|
||
app = self.db.get(App, app_id)
|
||
if not app:
|
||
raise ResourceNotFoundException("应用", str(app_id))
|
||
|
||
# 2. 验证模型配置(如果提供了)
|
||
if data.default_model_config_id:
|
||
model_api_key = ModelApiKeyService.get_a_api_key(self.db, data.default_model_config_id)
|
||
if not model_api_key:
|
||
raise ResourceNotFoundException("模型配置", str(data.default_model_config_id))
|
||
|
||
# 3. 验证子 Agent 存在并获取发布版本 ID
|
||
for sub_agent in data.sub_agents:
|
||
agent_app_release = self.get_published_by_agent_id(sub_agent.agent_id)
|
||
if not agent_app_release:
|
||
raise ResourceNotFoundException("子 Agent 未发布或不存在", str(sub_agent.agent_id))
|
||
|
||
# 使用发布版本 ID
|
||
sub_agent.agent_id = agent_app_release.id
|
||
|
||
# 5. 创建配置(转换 UUID 为字符串以支持 JSON 序列化)
|
||
sub_agents_data = [convert_uuids_to_str(sub_agent.model_dump()) for sub_agent in data.sub_agents]
|
||
# routing_rules_data = [convert_uuids_to_str(rule.model_dump()) for rule in data.routing_rules] if data.routing_rules else None
|
||
|
||
# 处理 execution_config(可能是 None、字典或 Pydantic 模型)
|
||
if data.execution_config is None:
|
||
execution_config_data = {}
|
||
elif isinstance(data.execution_config, dict):
|
||
execution_config_data = convert_uuids_to_str(data.execution_config)
|
||
else:
|
||
execution_config_data = convert_uuids_to_str(data.execution_config.model_dump())
|
||
|
||
# 处理 model_parameters(可能是 None、字典或 Pydantic 模型)
|
||
if data.model_parameters is None:
|
||
model_parameters_data = None
|
||
# elif isinstance(data.model_parameters, dict):
|
||
# # 过滤掉值为 None 的字段
|
||
# model_parameters_data = {k: v for k, v in data.model_parameters.items() if v is not None}
|
||
else:
|
||
# 过滤掉值为 None 的字段
|
||
# model_parameters_data = {k: v for k, v in data.model_parameters.model_dump().items() if v is not None}
|
||
model_parameters_data = data.model_parameters
|
||
|
||
config = MultiAgentConfig(
|
||
app_id=app_id,
|
||
master_agent_id=data.master_agent_id,
|
||
master_agent_name=data.master_agent_name,
|
||
default_model_config_id=data.default_model_config_id,
|
||
model_parameters=model_parameters_data,
|
||
orchestration_mode=data.orchestration_mode,
|
||
sub_agents=sub_agents_data,
|
||
# routing_rules=routing_rules_data,
|
||
execution_config=execution_config_data,
|
||
aggregation_strategy=data.aggregation_strategy
|
||
)
|
||
return config
|
||
|
||
def update_config(
|
||
self,
|
||
app_id: uuid.UUID,
|
||
data: MultiAgentConfigUpdate
|
||
) -> MultiAgentConfig:
|
||
"""更新多 Agent 配置
|
||
|
||
Args:
|
||
app_id: 应用 ID
|
||
data: 更新数据
|
||
|
||
Returns:
|
||
更新后的配置
|
||
"""
|
||
config = self.get_config(app_id)
|
||
newConfig = self.check_config_data(app_id, data)
|
||
if not config:
|
||
config = newConfig
|
||
self.db.add(config)
|
||
self.db.commit()
|
||
self.db.refresh(config)
|
||
logger.info(
|
||
"创建多 Agent 配置成功",
|
||
extra={
|
||
"config_id": str(config.id),
|
||
"app_id": str(app_id),
|
||
"mode": data.orchestration_mode,
|
||
"sub_agent_count": len(data.sub_agents)
|
||
}
|
||
)
|
||
return config
|
||
|
||
# 完全替换配置,但对于数据库 NOT NULL 字段,如果新值是 None 则保留原值
|
||
config.default_model_config_id = newConfig.default_model_config_id
|
||
config.model_parameters = newConfig.model_parameters
|
||
config.orchestration_mode = newConfig.orchestration_mode or config.orchestration_mode
|
||
config.sub_agents = newConfig.sub_agents if newConfig.sub_agents is not None else config.sub_agents
|
||
config.routing_rules = newConfig.routing_rules
|
||
config.execution_config = newConfig.execution_config if newConfig.execution_config else config.execution_config
|
||
config.aggregation_strategy = newConfig.aggregation_strategy or config.aggregation_strategy
|
||
self.db.commit()
|
||
self.db.refresh(config)
|
||
|
||
logger.info(
|
||
"更新多 Agent 配置成功",
|
||
extra={
|
||
"config_id": str(config.id),
|
||
"app_id": str(app_id)
|
||
}
|
||
)
|
||
|
||
return config
|
||
|
||
def delete_config(self, app_id: uuid.UUID) -> None:
|
||
"""删除多 Agent 配置
|
||
|
||
Args:
|
||
app_id: 应用 ID
|
||
"""
|
||
config = self.get_config(app_id)
|
||
if not config:
|
||
raise ResourceNotFoundException("多 Agent 配置", str(app_id))
|
||
|
||
# 逻辑删除多 Agent 配置
|
||
config.is_active = False
|
||
self.db.commit()
|
||
|
||
logger.info(
|
||
"删除多 Agent 配置成功",
|
||
extra={
|
||
"config_id": str(config.id),
|
||
"app_id": str(app_id)
|
||
}
|
||
)
|
||
|
||
async def run(
|
||
self,
|
||
app_id: uuid.UUID,
|
||
request: MultiAgentRunRequest
|
||
) -> dict:
|
||
"""运行多 Agent 任务
|
||
|
||
Args:
|
||
app_id: 应用 ID
|
||
request: 运行请求
|
||
|
||
Returns:
|
||
执行结果
|
||
"""
|
||
# 1. 获取配置
|
||
config = self.get_config(app_id)
|
||
if not config:
|
||
raise ResourceNotFoundException("多 Agent 配置", str(app_id))
|
||
|
||
if not config.is_active:
|
||
raise BusinessException("多 Agent 配置已禁用", BizCode.RESOURCE_DISABLED)
|
||
|
||
# 2. 创建编排器
|
||
orchestrator = MultiAgentOrchestrator(self.db, config)
|
||
|
||
# 3. 执行任务
|
||
result = await orchestrator.execute(
|
||
message=request.message,
|
||
conversation_id=request.conversation_id,
|
||
user_id=request.user_id,
|
||
variables=request.variables,
|
||
use_llm_routing=getattr(request, 'use_llm_routing', True), # 默认启用 LLM 路由
|
||
web_search=getattr(request, 'web_search', False), # 网络搜索参数
|
||
memory=getattr(request, 'memory', True) # 记忆功能参数
|
||
)
|
||
|
||
return result
|
||
|
||
async def run_stream(
|
||
self,
|
||
app_id: uuid.UUID,
|
||
request: MultiAgentRunRequest,
|
||
storage_type :str,
|
||
user_rag_memory_id :str
|
||
):
|
||
"""运行多 Agent 任务(流式返回)
|
||
|
||
Args:
|
||
app_id: 应用 ID
|
||
request: 运行请求
|
||
|
||
Yields:
|
||
SSE 格式的事件流
|
||
"""
|
||
# 1. 获取配置
|
||
config = self.get_config(app_id)
|
||
if not config:
|
||
raise ResourceNotFoundException("多 Agent 配置", str(app_id))
|
||
|
||
if not config.is_active:
|
||
raise BusinessException("多 Agent 配置已禁用", BizCode.RESOURCE_DISABLED)
|
||
|
||
# 2. 创建编排器
|
||
orchestrator = MultiAgentOrchestrator(self.db, config)
|
||
|
||
# 3. 流式执行任务
|
||
async for event in orchestrator.execute_stream(
|
||
message=request.message,
|
||
conversation_id=request.conversation_id,
|
||
user_id=request.user_id,
|
||
variables=request.variables,
|
||
use_llm_routing=getattr(request, 'use_llm_routing', True),
|
||
web_search=getattr(request, 'web_search', False), # 网络搜索参数
|
||
memory=getattr(request, 'memory', True) , # 记忆功能参数
|
||
storage_type=storage_type,
|
||
user_rag_memory_id=user_rag_memory_id
|
||
):
|
||
yield event
|
||
|
||
# def add_sub_agent(
|
||
# self,
|
||
# app_id: uuid.UUID,
|
||
# agent_id: uuid.UUID,
|
||
# name: str,
|
||
# role: Optional[str] = None,
|
||
# priority: int = 1,
|
||
# capabilities: Optional[List[str]] = None
|
||
# ) -> MultiAgentConfig:
|
||
# """添加子 Agent
|
||
|
||
# Args:
|
||
# app_id: 应用 ID
|
||
# agent_id: Agent ID
|
||
# name: Agent 名称
|
||
# role: 角色描述
|
||
# priority: 优先级
|
||
# capabilities: 能力列表
|
||
|
||
# Returns:
|
||
# 更新后的配置
|
||
# """
|
||
# config = self.get_config(app_id)
|
||
# if not config:
|
||
# raise ResourceNotFoundException("多 Agent 配置", str(app_id))
|
||
|
||
# # 验证 Agent 存在
|
||
# agent = self.db.get(AgentConfig, agent_id)
|
||
# if not agent:
|
||
# raise ResourceNotFoundException("Agent", str(agent_id))
|
||
|
||
# # 检查是否已存在
|
||
# for sub_agent in config.sub_agents:
|
||
# if sub_agent["agent_id"] == str(agent_id):
|
||
# raise BusinessException("Agent 已存在于配置中", BizCode.DUPLICATE_RESOURCE)
|
||
|
||
# # 添加子 Agent
|
||
# new_sub_agent = {
|
||
# "agent_id": str(agent_id),
|
||
# "name": name,
|
||
# "role": role,
|
||
# "priority": priority,
|
||
# "capabilities": capabilities or []
|
||
# }
|
||
|
||
# config.sub_agents.append(new_sub_agent)
|
||
|
||
# # 标记为已修改
|
||
# self.db.add(config)
|
||
# self.db.commit()
|
||
# self.db.refresh(config)
|
||
|
||
# logger.info(
|
||
# "添加子 Agent 成功",
|
||
# extra={
|
||
# "config_id": str(config.id),
|
||
# "agent_id": str(agent_id),
|
||
# "agent_name": name
|
||
# }
|
||
# )
|
||
|
||
# return config
|
||
|
||
# def remove_sub_agent(
|
||
# self,
|
||
# app_id: uuid.UUID,
|
||
# agent_id: uuid.UUID
|
||
# ) -> MultiAgentConfig:
|
||
# """移除子 Agent
|
||
|
||
# Args:
|
||
# app_id: 应用 ID
|
||
# agent_id: Agent ID
|
||
|
||
# Returns:
|
||
# 更新后的配置
|
||
# """
|
||
# config = self.get_config(app_id)
|
||
# if not config:
|
||
# raise ResourceNotFoundException("多 Agent 配置", str(app_id))
|
||
|
||
# # 查找并移除
|
||
# original_count = len(config.sub_agents)
|
||
# config.sub_agents = [
|
||
# sub_agent for sub_agent in config.sub_agents
|
||
# if sub_agent["agent_id"] != str(agent_id)
|
||
# ]
|
||
|
||
# if len(config.sub_agents) == original_count:
|
||
# raise ResourceNotFoundException("子 Agent", str(agent_id))
|
||
|
||
# # 标记为已修改
|
||
# self.db.add(config)
|
||
# self.db.commit()
|
||
# self.db.refresh(config)
|
||
|
||
# logger.info(
|
||
# "移除子 Agent 成功",
|
||
# extra={
|
||
# "config_id": str(config.id),
|
||
# "agent_id": str(agent_id)
|
||
# }
|
||
# )
|
||
|
||
# return config
|
||
|
||
def list_configs(
|
||
self,
|
||
workspace_id: uuid.UUID,
|
||
page: int = 1,
|
||
pagesize: int = 20
|
||
) -> Tuple[List[MultiAgentConfig], int]:
|
||
"""列出多 Agent 配置
|
||
|
||
Args:
|
||
workspace_id: 工作空间 ID
|
||
page: 页码
|
||
pagesize: 每页数量
|
||
|
||
Returns:
|
||
配置列表和总数
|
||
"""
|
||
# 构建查询
|
||
stmt = (
|
||
select(MultiAgentConfig)
|
||
.join(App)
|
||
.where(App.workspace_id == workspace_id)
|
||
.order_by(desc(MultiAgentConfig.created_at))
|
||
)
|
||
|
||
# 总数
|
||
count_stmt = stmt.with_only_columns(MultiAgentConfig.id)
|
||
total = len(self.db.execute(count_stmt).all())
|
||
|
||
# 分页
|
||
stmt = stmt.offset((page - 1) * pagesize).limit(pagesize)
|
||
configs = list(self.db.scalars(stmt).all())
|
||
|
||
return configs, total
|
||
|
||
# ==================== 依赖注入函数 ====================
|
||
|
||
def get_multi_agent_service(
|
||
db: Annotated[Session, Depends(get_db)]
|
||
) -> MultiAgentService:
|
||
"""获取工作流服务(依赖注入)"""
|
||
return MultiAgentService(db)
|