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>
This commit is contained in:
朱潮 2025-12-31 20:30:44 +08:00
parent 7c9e270a66
commit a6f166d51e
3 changed files with 38 additions and 14 deletions

View File

@ -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
)
)

View File

@ -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)

View File

@ -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"])