Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ data/
sdk/benchmark/.env
/docker/.env.bak

.venv
.venv

.pytest-tmp
doc/mermaid
74 changes: 73 additions & 1 deletion backend/agents/create_agent_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import threading
import json
import threading
import logging
from typing import List, Optional
from urllib.parse import urljoin
Expand Down Expand Up @@ -383,6 +384,77 @@ async def create_agent_config(
# Bubble up to streaming layer so it can emit <MEM_FAILED> and fall back
raise Exception(f"Failed to retrieve memory list: {e}")

# Append active memory tools if memory is enabled
if memory_context.user_config.memory_switch and memory_context.memory_config:
try:
memory_metadata = {
"memory_config": memory_context.memory_config,
"memory_user_config": memory_context.user_config,
"tenant_id": memory_context.tenant_id,
"user_id": memory_context.user_id,
"agent_id": memory_context.agent_id,
}

store_tool_config = ToolConfig(
class_name="StoreMemoryTool",
name="store_memory",
description=(
"Save important information to long-term memory for future recall. "
"Use this when the user shares personal preferences, facts about themselves, "
"project context, or instructions that should persist across conversations. "
"Do NOT store transient information like temporary calculations, information "
"already in the knowledge base, or data the user explicitly says to forget."
),
inputs=json.dumps({
"content": {
"type": "string",
"description": "The information to remember",
"description_zh": "需要记住的信息"
}
}, ensure_ascii=False),
output_type="string",
params={},
source="local",
usage=None,
metadata=memory_metadata,
)
tool_list.append(store_tool_config)

search_tool_config = ToolConfig(
class_name="SearchMemoryTool",
name="search_memory",
description=(
"Search long-term memory for relevant information from previous interactions. "
"Use this when you need context about the user's preferences, past decisions, "
"or previously discussed topics that aren't in the current conversation. "
"The system already provides some memory context automatically -- use this tool "
"when you need to search for specific information not already available."
),
inputs=json.dumps({
"query": {
"type": "string",
"description": "Natural language query describing what to search for",
"description_zh": "描述要搜索内容的自然语言查询"
},
"top_k": {
"type": "integer",
"description": "Maximum number of results to return",
"description_zh": "返回结果的最大数量",
"default": 5,
"nullable": True
}
}, ensure_ascii=False),
output_type="string",
params={},
source="local",
usage=None,
metadata=memory_metadata,
)
tool_list.append(search_tool_config)
logger.debug("Active memory tools appended to agent tool list")
except Exception as e:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[代码规范] except Exception: 过于宽泛,建议捕获更具体的异常类型,避免掩盖潜在错误。

logger.warning(f"Failed to append active memory tools: {e}")

# Build knowledge base summary
knowledge_base_summary = ""
try:
Expand Down
Loading
Loading