Compare commits
2 Commits
6f665b4117
...
6cb7392488
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6cb7392488 | ||
|
|
03078a2077 |
@ -241,15 +241,15 @@ async def init_agent(config: AgentConfig):
|
||||
token_counter=create_token_counter(config.model_name)
|
||||
)
|
||||
middleware.append(summarization_middleware)
|
||||
workspace_root = f"projects/robot/{config.bot_id}"
|
||||
workspace_root = str(Path.cwd() / "projects" /"robot"/ config.bot_id)
|
||||
# workspace_root = str(Path.home() / ".deepagents" / config.bot_id)
|
||||
|
||||
agent, composite_backend = create_custom_cli_agent(
|
||||
model=llm_instance,
|
||||
assistant_id=config.bot_id,
|
||||
system_prompt=system_prompt,
|
||||
tools=mcp_tools,
|
||||
auto_approve=True,
|
||||
enable_memory=False,
|
||||
workspace_root=workspace_root,
|
||||
middleware=middleware,
|
||||
checkpointer=checkpointer,
|
||||
@ -263,28 +263,6 @@ async def init_agent(config: AgentConfig):
|
||||
logger.info(f"create agent elapsed: {time.time() - create_start:.3f}s")
|
||||
return agent, checkpointer
|
||||
|
||||
class CustomAgentMemoryMiddleware(MemoryMiddleware):
|
||||
"""自定义的 AgentMemoryMiddleware,修改路径显示为当前目录"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
backend: FilesystemBackend,
|
||||
sources: list[str],
|
||||
) -> None:
|
||||
super().__init__(
|
||||
backend=backend,
|
||||
sources=sources,
|
||||
)
|
||||
self.agent_dir_display = f"."
|
||||
|
||||
def _format_memory_content(self, memories: list[dict]) -> str:
|
||||
"""Format memory content for display in system prompt.
|
||||
|
||||
Override to use relative path display.
|
||||
"""
|
||||
# 使用父类的默认实现,但路径显示已经是相对路径
|
||||
return super()._format_memory_content(memories) if hasattr(super(), '_format_memory_content') else ""
|
||||
|
||||
class CustomSkillsMiddleware(SkillsMiddleware):
|
||||
"""自定义的 SkillsMiddleware,使用新的签名格式"""
|
||||
@ -332,7 +310,6 @@ def create_custom_cli_agent(
|
||||
sandbox_type: str | None = None,
|
||||
system_prompt: str | None = None,
|
||||
auto_approve: bool = False,
|
||||
enable_memory: bool = True,
|
||||
enable_skills: bool = True,
|
||||
enable_shell: bool = True,
|
||||
middleware: list[AgentMiddleware] = [],
|
||||
@ -375,14 +352,6 @@ def create_custom_cli_agent(
|
||||
if tools is None:
|
||||
tools = []
|
||||
|
||||
# Setup agent directory for persistent memory (if enabled)
|
||||
if enable_memory or enable_skills:
|
||||
agent_dir = settings.ensure_agent_dir(assistant_id)
|
||||
agent_md = agent_dir / "AGENTS.md" # 新版本使用 AGENTS.md
|
||||
if not agent_md.exists():
|
||||
# Create empty file for user customizations
|
||||
agent_md.touch()
|
||||
|
||||
# Build middleware stack based on enabled features
|
||||
agent_middleware = middleware
|
||||
|
||||
@ -402,22 +371,19 @@ def create_custom_cli_agent(
|
||||
# Use LocalShellBackend for filesystem + shell execution
|
||||
backend = LocalShellBackend(
|
||||
root_dir=workspace_root,
|
||||
virtual_mode=True,
|
||||
inherit_env=True,
|
||||
env=final_shell_env,
|
||||
)
|
||||
else:
|
||||
# No shell access - use plain FilesystemBackend
|
||||
backend = FilesystemBackend(root_dir=workspace_root, virtual_mode=True)
|
||||
backend = FilesystemBackend(root_dir=workspace_root)
|
||||
|
||||
# Set up composite backend with routing (参考新版本实现)
|
||||
large_results_backend = FilesystemBackend(
|
||||
root_dir=tempfile.mkdtemp(prefix="deepagents_large_results_"),
|
||||
virtual_mode=True,
|
||||
)
|
||||
conversation_history_backend = FilesystemBackend(
|
||||
root_dir=tempfile.mkdtemp(prefix="deepagents_conversation_history_"),
|
||||
virtual_mode=True,
|
||||
)
|
||||
composite_backend = CompositeBackend(
|
||||
default=backend,
|
||||
@ -427,25 +393,13 @@ def create_custom_cli_agent(
|
||||
},
|
||||
)
|
||||
|
||||
# Add memory middleware (using new signature)
|
||||
if enable_memory:
|
||||
memory_sources = [str(settings.get_user_agent_md_path(assistant_id))]
|
||||
memory_sources.extend(str(p) for p in settings.get_project_agent_md_path())
|
||||
|
||||
agent_middleware.append(
|
||||
CustomAgentMemoryMiddleware(
|
||||
backend=FilesystemBackend(root_dir=workspace_root, virtual_mode=True),
|
||||
sources=memory_sources,
|
||||
)
|
||||
)
|
||||
|
||||
# Add skills middleware (using new signature)
|
||||
if enable_skills:
|
||||
skills_sources = ["./skills"]
|
||||
|
||||
agent_middleware.append(
|
||||
CustomSkillsMiddleware(
|
||||
backend=FilesystemBackend(root_dir=workspace_root, virtual_mode=True),
|
||||
backend=FilesystemBackend(root_dir=workspace_root),
|
||||
sources=skills_sources,
|
||||
)
|
||||
)
|
||||
@ -464,18 +418,6 @@ def create_custom_cli_agent(
|
||||
routes={}, # No virtualization
|
||||
)
|
||||
|
||||
# Add memory middleware
|
||||
if enable_memory:
|
||||
memory_sources = [str(settings.get_user_agent_md_path(assistant_id))]
|
||||
memory_sources.extend(str(p) for p in settings.get_project_agent_md_path())
|
||||
|
||||
agent_middleware.append(
|
||||
CustomAgentMemoryMiddleware(
|
||||
backend=sandbox,
|
||||
sources=memory_sources,
|
||||
)
|
||||
)
|
||||
|
||||
# Add skills middleware
|
||||
if enable_skills:
|
||||
skills_sources = ["/skills"]
|
||||
|
||||
@ -11,6 +11,7 @@ import logging
|
||||
from utils.settings import BACKEND_HOST, MASTERKEY
|
||||
logger = logging.getLogger('app')
|
||||
from .plugin_hook_loader import execute_hooks, merge_skill_mcp_configs
|
||||
from pathlib import Path
|
||||
|
||||
def format_datetime_by_language(language: str) -> str:
|
||||
"""
|
||||
@ -124,7 +125,7 @@ async def load_system_prompt_async(config) -> str:
|
||||
language=language_display,
|
||||
user_identifier=user_identifier,
|
||||
datetime=datetime_str,
|
||||
agent_dir_path=".",
|
||||
agent_dir_path=f"{Path.cwd()}/projects/robot/{config.bot_id}",
|
||||
trace_id=trace_id or ""
|
||||
)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user