diff --git a/agent/deep_assistant.py b/agent/deep_assistant.py index a68f7aa..75ca1bd 100644 --- a/agent/deep_assistant.py +++ b/agent/deep_assistant.py @@ -215,6 +215,38 @@ async def init_agent(config: AgentConfig): logger.info(f"create {config.robot_type} elapsed: {time.time() - create_start:.3f}s") return agent, checkpointer +class CustomSkillsMiddleware(SkillsMiddleware): + def __init__( + self, + *, + skills_dir: str | Path, + assistant_id: str, + project_skills_dir: str | Path | None = None, + ) -> None: + super().__init__( + skills_dir=skills_dir, + assistant_id=assistant_id, + project_skills_dir=project_skills_dir + ) + self.user_skills_display = f"./skills" + + def before_agent(self, state, runtime): + """Load skills metadata before agent execution. + + This runs once at session start to discover available skills from both + user-level and project-level directories. + + Args: + state: Current agent state. + runtime: Runtime context. + + Returns: + Updated state with skills_metadata populated. + """ + state = super().before_agent(state, runtime) + for item in state["skills_metadata"]: + item["path"] = self.user_skills_display + item["path"].replace(str(self.skills_dir), "") + return state def create_custom_cli_agent( model: str | BaseChatModel, @@ -280,7 +312,7 @@ def create_custom_cli_agent( if sandbox is None: # ========== LOCAL MODE ========== composite_backend = CompositeBackend( - default=FilesystemBackend(root_dir=workspace_root), # Current working directory + default=FilesystemBackend(root_dir=workspace_root, virtual_mode=True), # Current working directory routes={}, # No virtualization - use real paths ) @@ -293,7 +325,7 @@ def create_custom_cli_agent( # Add skills middleware if enable_skills: agent_middleware.append( - SkillsMiddleware( + CustomSkillsMiddleware( skills_dir=skills_dir, assistant_id=assistant_id ) @@ -304,9 +336,6 @@ def create_custom_cli_agent( # Create environment for shell commands # Restore user's original LANGSMITH_PROJECT so their code traces separately shell_env = os.environ.copy() - if settings.user_langchain_project: - shell_env["LANGSMITH_PROJECT"] = settings.user_langchain_project - # Use custom workspace_root if provided, otherwise use current directory shell_workspace = workspace_root if workspace_root is not None else str(Path.cwd()) @@ -332,10 +361,9 @@ def create_custom_cli_agent( # Add skills middleware if enable_skills: agent_middleware.append( - SkillsMiddleware( + CustomSkillsMiddleware( skills_dir=skills_dir, - assistant_id=assistant_id, - project_skills_dir=project_skills_dir, + assistant_id=assistant_id ) ) diff --git a/agent/prompt_loader.py b/agent/prompt_loader.py index bbb76f2..59f7a82 100644 --- a/agent/prompt_loader.py +++ b/agent/prompt_loader.py @@ -120,14 +120,14 @@ async def load_system_prompt_async(project_dir: str, language: str = None, syste readme_path = os.path.join(project_dir, "README.md") readme = await config_cache.get_text_file(readme_path) or "" - agent_dir_path = f"~/.deepagents/{bot_id}" #agent_dir_path 其实映射的就是 project_dir目录,只是给ai看的目录路径 + # agent_dir_path = f"~/.deepagents/{bot_id}" #agent_dir_path 其实映射的就是 project_dir目录,只是给ai看的目录路径 prompt = system_prompt_default.format( readme=str(readme), extra_prompt=system_prompt or "", language=language_display, user_identifier=user_identifier, datetime=datetime_str, - agent_dir_path=agent_dir_path + agent_dir_path="." ) elif system_prompt: prompt = system_prompt.format(language=language_display, user_identifier=user_identifier, datetime=datetime_str) diff --git a/utils/multi_project_manager.py b/utils/multi_project_manager.py index 748d68d..4beee22 100644 --- a/utils/multi_project_manager.py +++ b/utils/multi_project_manager.py @@ -451,10 +451,6 @@ def create_robot_project(dataset_ids: List[str], bot_id: str, force_rebuild: boo config_data = { "dataset_ids": dataset_ids, "bot_id": bot_id, - "env": { - "backend_host": settings.BACKEND_HOST, - "masterkey": settings.MASTERKEY - }, "created_at": datetime.now().isoformat(), "total_folders": len(copy_results), "successful_copies": sum(1 for r in copy_results if r["success"])