Commit Graph

358 Commits

Author SHA1 Message Date
朱潮
44b4295a87 update parse_skill_frontmatter 2026-01-23 08:52:27 +08:00
朱潮
3dc119bca8 refactor(mem0): optimize connection pool and async memory handling
- Fix mem0 connection pool exhausted error with proper pooling
- Convert memory operations to async tasks
- Optimize docker-compose configuration
- Add skill upload functionality
- Reduce cache size for better performance
- Update dependencies

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 19:39:12 +08:00
朱潮
f29fd1fb54 📝 docs(prompt): add skill execution workflow with read_file pattern
- Add 3-step workflow: read_file → extract command → bash execute
- Include complete example showing read_file + bash execution pattern
- Clarify that SKILL.md must be read with read_file tool before execution
- Add key rules with checkmarks (always read_file, always absolute paths)

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-01-21 17:50:58 +08:00
朱潮
d3f60e129b 📝 docs(prompt): enhance skill script path handling instructions
- Add CRITICAL path handling section with skill-specific conversion rules
- Include path conversion table showing SKILL.md relative paths to absolute paths
- Add 4-step execution guide for skill script path resolution
- Clarify skill directory structure (scripts/ can be at root or in scripts/ subfolder)

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-01-21 17:21:53 +08:00
朱潮
0922ad084a patch 2026-01-21 13:23:11 +08:00
朱潮
60bd1e4042 feat(prompt): add fact retrieval prompt with contact tracking
Add comprehensive prompt for extracting and storing user facts from
conversations, with special focus on relationship/contact tracking:
- Full name and nickname association (e.g., "Mike" → "Michael Johnson")
- Relationship context recording (family, friend, colleague, etc.)
- Multi-language name support
- Few-shot examples for various fact extraction scenarios

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-01-21 13:22:17 +08:00
朱潮
99755ceab5 remove settingsetting 2026-01-21 10:38:29 +08:00
朱潮
40bd50c439 update claude.md 2026-01-21 09:03:12 +08:00
朱潮
3aa223d71d update requirements.txt 2026-01-21 08:47:55 +08:00
朱潮
b53174ae9f 需要 openai_api_key的环境变量 2026-01-21 08:38:06 +08:00
朱潮
223c63047d fix(mem0): use asyncio.run() for async call in sync embed method
在 CustomMem0Embedding.embed() 同步方法中使用 asyncio.run()
调用异步的 manager.get_model(),解决同步/异步混合调用问题。

Generated with [Claude Code](https://claude.com/claude-code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-01-20 23:03:21 +08:00
朱潮
366a64283e Added memory log 2026-01-20 21:30:32 +08:00
朱潮
f694101747 refactor: migrate from Memori to Mem0 for long-term memory
Replace Memori with Mem0 for memory management:
- Delete memori_config.py, memori_manager.py, memori_middleware.py
- Add mem0_config.py, mem0_manager.py, mem0_middleware.py
- Update environment variables (MEMORI_* -> MEM0_*)
- Integrate Mem0 with LangGraph middleware
- Add sync connection pool for Mem0 in DBPoolManager
- Move checkpoint message prep to config creation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 21:15:30 +08:00
朱潮
5c041cdebe fix: add psycopg2-binary dependency for Memori
Memori requires synchronous database connection (psycopg2) to
create SQLAlchemy sessions. Added psycopg2-binary to dependencies.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-20 08:33:11 +08:00
朱潮
4d6ee6ae0c fix: pass db_url to init_global_memori
Add db_url property to MemoriManager that falls back to
CHECKPOINT_DB_URL setting, and pass it explicitly from
fastapi_app.py to ensure Memori can create sync connections.

This fixes the error "Either db_pool or db_url must be provided"
when recalling memories.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-20 08:27:34 +08:00
朱潮
456bcf50e6 refactor: move Memori initialization to fastapi_app.py
Move init_global_memori from deep_assistant.py to fastapi_app.py
lifespan function for proper application-level initialization.

This ensures Memori is initialized once at startup and closed at
shutdown, rather than checking and potentially initializing on every
agent creation.

Changes:
- fastapi_app.py: Add Memori init/close in lifespan
- deep_assistant.py: Simplify to only get memori_manager

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-20 00:15:21 +08:00
朱潮
455a48409d feat: integrate Memori long-term memory system
Add Memori (https://github.com/MemoriLabs/Memori) integration for
persistent cross-session memory capabilities in both create_agent
and create_deep_agent.

## New Files

- agent/memori_config.py: MemoriConfig dataclass for configuration
- agent/memori_manager.py: MemoriManager for connection and instance management
- agent/memori_middleware.py: MemoriMiddleware for memory recall/storage
- tests/: Unit tests for Memori components

## Modified Files

- agent/agent_config.py: Added enable_memori, memori_semantic_search_top_k, etc.
- agent/deep_assistant.py: Integrated MemoriMiddleware into init_agent()
- utils/settings.py: Added MEMORI_* environment variables
- pyproject.toml: Added memori>=3.1.0 dependency

## Features

- Semantic memory search with configurable top-k and threshold
- Multi-tenant isolation (entity_id=user, process_id=bot, session_id)
- Memory injection into system prompt
- Background asynchronous memory augmentation
- Graceful degradation when Memori is unavailable

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-20 00:12:43 +08:00
朱潮
af63c54778 db_pool 2026-01-19 23:39:04 +08:00
朱潮
05744cb9f4 批量保存聊天记录 2026-01-19 09:44:57 +08:00
朱潮
3b438d8ab7 优化输出 2026-01-18 22:04:36 +08:00
朱潮
f9ba3c8e51 添加聊天记录查询 2026-01-18 12:29:20 +08:00
朱潮
fa3e30cc07 docker file 2026-01-18 10:27:14 +08:00
朱潮
de3d5f6bf1 修改docker-compsoe 2026-01-18 10:10:34 +08:00
朱潮
20d5e96986 feat: 添加 PostgreSQL 支持用于 checkpoint 存储
- 添加 postgres:16-alpine 服务配置
- 配置 CHECKPOINT_DB_URL 环境变量
- 添加服务依赖和健康检查

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 00:32:23 +08:00
朱潮
723b249e42 增加2个系统级别的skill 2026-01-16 23:05:30 +08:00
朱潮
90117b41fe 修复符号链接的问题,和deep_agent提示词 2026-01-13 14:22:44 +08:00
朱潮
174a5e2059 deep_agent支持 checkpoint 2026-01-11 00:08:19 +08:00
朱潮
b93c40d5a5 merge 2026-01-08 23:10:09 +08:00
朱潮
d45079ca55 feat: 将system_prompt解析从markdown代码块改为XML标签格式
- agent_config.py: enable_thinking判断从 ```guideline 改为 <guidelines>
- fastapi_utils.py:
  - preamble解析从 ```preamble``` 改为 <preamble>
  - guidelines/tools/scenarios/terms 块解析从 markdown 格式改为 XML 标签格式
  - 移除不再使用的 parse_guidelines_text 函数

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-08 22:56:43 +08:00
朱潮
5a4aee91ab merge 2026-01-08 22:28:10 +08:00
朱潮
43ca06f591 修复system_prompt 2026-01-08 22:24:58 +08:00
朱潮
c1bf679166 enable_thinking 2026-01-08 18:03:21 +08:00
朱潮
37958291ae Merge branch 'rag_receive_top_k' 2026-01-08 17:28:59 +08:00
朱潮
fc5c1adaaa feat(mcp): add top_k optional parameter to RAG retrieve tool 2026-01-08 17:27:35 +08:00
朱潮
68a4578554 feat(skills): add skill deletion endpoint
- Add DELETE /api/v1/skill/remove endpoint
- Add validate_skill_name() for path traversal protection
- Include path normalization and security checks
- Prevent deletion of official skills (user skills only)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-07 21:34:16 +08:00
朱潮
ac8782e1a7 docs(solutions): add SSE error handling solution documentation
Add comprehensive documentation for the SSE stream termination fix:
- Problem analysis and root cause
- Step-by-step solution with code examples
- Security considerations (__debug__ vulnerability)
- Code simplification recommendations
- Prevention strategies and best practices
- Testing and monitoring guidelines

Location: docs/solutions/runtime-errors/sse-mcp-tool-error-handling.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-07 20:25:50 +08:00
朱潮
b8e57b2f51 feat(skills): add security hardening to skill upload endpoint
- Add ZipSlip path traversal protection (validate all file paths)
- Add file size limits (50MB upload, 500MB extracted)
- Add zip bomb protection (max 100:1 compression ratio, 1000 entries)
- Add async I/O using aiofiles to avoid blocking event loop
- Add bot_id validation to prevent path traversal attacks
- Add proper error cleanup on upload failures

Security improvements:
- P1-001: ZipSlip path traversal防护
- P1-004: File size limits (50MB)
- P1-005: Zip bomb防护 (compression ratio check)
- P1-008: Async I/O improvements

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-07 20:25:37 +08:00
朱潮
b3303ef8e6 refactor(sse): simplify error handling and remove __debug__ security issue
- Remove __debug__ conditional that exposed tracebacks in production
- Simplify error response structure to {"error": str(e)}
- Remove redundant exception handling in init_agent()
- Remove unnecessary traceback logging
- Reduce code from ~30 lines to ~10 lines

Fixes security vulnerability where __debug__ is always True
unless Python runs with -O flag, causing full tracebacks
to be sent to clients in production.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-07 20:24:30 +08:00
朱潮
342932030f feat(skills): add skill management API module
- Create new skill_manager.py with list and upload endpoints
- Add GET /api/v1/skill/list to retrieve official and user skills
- Add POST /api/v1/skill/upload for skill file upload
- Parse SKILL.md frontmatter to extract name and description
- Move skill upload endpoint from files.py to skill_manager.py
- Add SKILLS_DIR configuration to settings.py
- Register skill_manager router in fastapi_app.py

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-07 19:45:04 +08:00
朱潮
8a85e9025e fix(sse): properly handle MCP tool errors and send error responses to client
- Enhance exception handling in agent_task() to capture and send structured error messages via SSE stream
- Add [DONE] marker to outer exception handler to ensure proper stream termination
- Improve MCP tool loading error handling in init_agent() to prevent cascading failures
- Add detailed error logging with traceback for debugging

Fixes RemoteProtocolError that occurred when MCP tool calls failed,
which previously caused incomplete chunked read errors and connection drops.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-07 19:24:28 +08:00
朱潮
f74f09c191 fix(skills): improve skill extraction and handling logic
- Refactor _extract_skills_to_robot to accept bot_id instead of robot_dir
  - Add multi-directory skill search with priority order
  - Switch from zip extraction to direct directory copying
  - Add rag-retrieve skill directory
2026-01-07 14:56:10 +08:00
朱潮
92c82c24a4 feat(skills): add skill file upload API endpoint
Add new POST endpoint /api/v1/skills/upload for uploading skill zip files.
The endpoint:
- Accepts zip files with bot_id parameter
- Validates file format (must be .zip)
- Saves zip to projects/uploads/{bot_id}/skill_zip/
- Automatically extracts to projects/uploads/{bot_id}/skills/{skill_name}/
- Returns success response with file and extract paths

This enables programmatic skill deployment for specific bots.
2026-01-07 14:47:25 +08:00
朱潮
1233bdda0c ♻️ refactor(deep-agent): customize agent memory middleware path display
- Change workspace_root from ~/.deepagents/{bot_id} to projects/robot/{bot_id}
- Refactor CustomSkillsMiddleware to support user and project skills separately
- Update skill path formatting for better visibility in system prompts
- Remove unused symlink_utils module and related setup code
- Clean up imports in fastapi_app.py and utils/__init__.py
2026-01-07 12:05:40 +08:00
朱潮
8bb8c3fbc8 add scripts/ 2026-01-04 17:19:03 +08:00
朱潮
e7f6378f6b system_prompt_deep_agent 2026-01-04 16:45:24 +08:00
朱潮
96f5079bf9 📝 docs(deep-agent): remove directory access restriction from system prompt
Remove the CRITICAL section about directory access restrictions.
Path handling guidance is still maintained.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 21:02:34 +08:00
朱潮
8c67630bbd ♻️ refactor(deep-agent): customize agent memory middleware path display
Override AgentMemoryMiddleware to simplify agent directory display.
The CustomAgentMemoryMiddleware shows "." instead of full path.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 21:00:49 +08:00
朱潮
a6f166d51e refactor: simplify path displays and remove sensitive config data
- Add CustomSkillsMiddleware to show ./skills instead of full paths
- Enable virtual_mode for FilesystemBackend in local mode
- Display "." instead of ~/.deepagents/{bot_id} in system prompt
- Remove backend_host and masterkey from robot project config

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 20:30:44 +08:00
朱潮
7c9e270a66 feat(deep-agent): add custom workspace_root support for shell commands
- Add create_custom_cli_agent function to support custom workspace_root
- Set shell workspace to ~/.deepagents/{bot_id} for deep_agent type
- Pass system_prompt to create_custom_cli_agent for proper context
- Fix duplicate <env> tag in system_prompt_deep_agent.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 18:18:38 +08:00
朱潮
49a0447f9f 🔧 chore(deep-agent): disable shell feature by default
Set enable_shell=False to disable shell command execution capabilities
in the deep agent for security reasons.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 16:59:33 +08:00