Spaces:
Running
Running
Download extensions/python/system_prompt/_11_tools_prompt.py from Leon4gr45/openoperator: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/spaces/Leon4gr45/openoperator/resolve/main/extensions/python/system_prompt/_11_tools_prompt.py
- Command line
-
hf download hf://spaces/Leon4gr45/openoperator/extensions/python/system_prompt/_11_tools_prompt.py
-
curl -L -o _11_tools_prompt.py https://huggingface.co/spaces/Leon4gr45/openoperator/resolve/main/extensions/python/system_prompt/_11_tools_prompt.py
1.96 kB
| import os | |
| from typing import Any | |
| from helpers.extension import Extension, extensible | |
| from helpers import files, subagents, tool_policy | |
| from helpers.print_style import PrintStyle | |
| from agent import Agent, LoopData | |
| TOOL_KWARGS_KEY = "_tool_prompt_kwargs" | |
| class ToolsPrompt(Extension): | |
| async def execute( | |
| self, | |
| system_prompt: list[str] = [], | |
| loop_data: LoopData = LoopData(), | |
| **kwargs: Any, | |
| ): | |
| if not self.agent: | |
| return | |
| prompt = await build_prompt(self.agent) | |
| system_prompt.append(prompt) | |
| async def build_prompt(agent: Agent) -> str: | |
| # collect tool files from all prompt directories | |
| prompt_dirs = subagents.get_paths(agent, "prompts") | |
| tool_files = files.get_unique_filenames_in_dirs( | |
| prompt_dirs, "agent.system.tool.*.md" | |
| ) | |
| # per-file kwargs registered by plugin config extensions (e.g. _09_text_editor_config) | |
| all_tool_kwargs: dict[str, dict[str, Any]] = agent.get_data(TOOL_KWARGS_KEY) or {} | |
| tools: list[str] = [] | |
| for tool_file in tool_files: | |
| try: | |
| basename = os.path.basename(tool_file) | |
| extra = all_tool_kwargs.get(basename, {}) | |
| tool = agent.read_prompt(basename, **extra) | |
| tool = tool_policy.filter_tool_prompt(agent, basename, tool) | |
| if tool: | |
| tools.append(tool) | |
| except Exception as e: | |
| PrintStyle().error(f"Error loading tool '{tool_file}': {e}") | |
| tools_str = "\n\n".join(tools) | |
| prompt = agent.read_prompt("agent.system.tools.md", tools=tools_str) | |
| # vision support | |
| from plugins._model_config.helpers.model_config import ( | |
| get_chat_model_config, | |
| get_vision_model_config, | |
| ) | |
| chat_cfg = get_chat_model_config(agent) | |
| if get_vision_model_config(agent) or chat_cfg.get("vision", False): | |
| prompt += "\n\n" + agent.read_prompt("agent.system.tools_vision.md") | |
| return prompt | |