Skip to content

Agent Zero AI framework

refactor: use @extensible decorator on build_prompt functions

linuztx8847af089ace
diff --git a/extensions/python/system_prompt/_10_main_prompt.py b/extensions/python/system_prompt/_10_main_prompt.py
index ef479b5dd..88193540c 100644
--- a/extensions/python/system_prompt/_10_main_prompt.py
+++ b/extensions/python/system_prompt/_10_main_prompt.py
@@ -1,6 +1,6 @@
from typing import Any
-from helpers.extension import Extension, call_extensions_async
+from helpers.extension import Extension, extensible
from agent import Agent, LoopData
@@ -18,7 +18,6 @@ class MainPrompt(Extension):
system_prompt.append(prompt)
+@extensible
async def build_prompt(agent: Agent) -> str:
- data: dict[str, Any] = {"prompt": agent.read_prompt("agent.system.main.md")}
- await call_extensions_async("system_prompt_main", agent=agent, data=data)
- return data["prompt"]
+ return agent.read_prompt("agent.system.main.md")
diff --git a/extensions/python/system_prompt/_11_tools_prompt.py b/extensions/python/system_prompt/_11_tools_prompt.py
index 819eb4da6..15a1041d7 100644
--- a/extensions/python/system_prompt/_11_tools_prompt.py
+++ b/extensions/python/system_prompt/_11_tools_prompt.py
@@ -1,7 +1,7 @@
import os
from typing import Any
-from helpers.extension import Extension, call_extensions_async
+from helpers.extension import Extension, extensible
from helpers import files, subagents
from helpers.print_style import PrintStyle
from agent import Agent, LoopData
@@ -24,6 +24,7 @@ class ToolsPrompt(Extension):
system_prompt.append(prompt)
+@extensible
async def build_prompt(agent: Agent) -> str:
# collect tool files from all prompt directories
prompt_dirs = subagents.get_paths(agent, "prompts")
@@ -54,6 +55,4 @@ async def build_prompt(agent: Agent) -> str:
if chat_cfg.get("vision", False):
prompt += "\n\n" + agent.read_prompt("agent.system.tools_vision.md")
- data: dict[str, Any] = {"prompt": prompt}
- await call_extensions_async("system_prompt_tools", agent=agent, data=data)
- return data["prompt"]
+ return prompt
diff --git a/extensions/python/system_prompt/_12_mcp_prompt.py b/extensions/python/system_prompt/_12_mcp_prompt.py
index ecc41c10e..30ca34454 100644
--- a/extensions/python/system_prompt/_12_mcp_prompt.py
+++ b/extensions/python/system_prompt/_12_mcp_prompt.py
@@ -1,6 +1,6 @@
from typing import Any
-from helpers.extension import Extension, call_extensions_async
+from helpers.extension import Extension, extensible
from helpers.mcp_handler import MCPConfig
from agent import Agent, LoopData
@@ -20,6 +20,7 @@ class MCPToolsPrompt(Extension):
system_prompt.append(prompt)
+@extensible
async def build_prompt(agent: Agent) -> str:
mcp_config = MCPConfig.get_instance()
if not mcp_config.servers:
@@ -29,7 +30,4 @@ async def build_prompt(agent: Agent) -> str:
agent.context.log.set_progress("Collecting MCP tools")
tools = mcp_config.get_tools_prompt()
agent.context.log.set_progress(pre_progress)
-
- data: dict[str, Any] = {"prompt": tools}
- await call_extensions_async("system_prompt_mcp", agent=agent, data=data)
- return data["prompt"]
+ return tools
diff --git a/extensions/python/system_prompt/_13_secrets_prompt.py b/extensions/python/system_prompt/_13_secrets_prompt.py
index d73a9e5a3..7264c431d 100644
--- a/extensions/python/system_prompt/_13_secrets_prompt.py
+++ b/extensions/python/system_prompt/_13_secrets_prompt.py
@@ -1,6 +1,6 @@
from typing import Any
-from helpers.extension import Extension, call_extensions_async
+from helpers.extension import Extension, extensible
from agent import Agent, LoopData
@@ -19,6 +19,7 @@ class SecretsPrompt(Extension):
system_prompt.append(prompt)
+@extensible
async def build_prompt(agent: Agent) -> str:
try:
from helpers.secrets import get_secrets_manager
@@ -27,12 +28,8 @@ async def build_prompt(agent: Agent) -> str:
secrets_manager = get_secrets_manager(agent.context)
secrets = secrets_manager.get_secrets_for_prompt()
variables = get_settings()["variables"]
- prompt = agent.read_prompt(
+ return agent.read_prompt(
"agent.system.secrets.md", secrets=secrets, vars=variables
)
-
- data: dict[str, Any] = {"prompt": prompt}
- await call_extensions_async("system_prompt_secrets", agent=agent, data=data)
- return data["prompt"]
except Exception:
return ""
diff --git a/extensions/python/system_prompt/_13_skills_prompt.py b/extensions/python/system_prompt/_13_skills_prompt.py
index 8b54df028..6e7cd43b5 100644
--- a/extensions/python/system_prompt/_13_skills_prompt.py
+++ b/extensions/python/system_prompt/_13_skills_prompt.py
@@ -1,6 +1,6 @@
from typing import Any
-from helpers.extension import Extension, call_extensions_async
+from helpers.extension import Extension, extensible
from helpers import skills as skills_helper
from agent import Agent, LoopData
@@ -20,6 +20,7 @@ class SkillsPrompt(Extension):
system_prompt.append(prompt)
+@extensible
async def build_prompt(agent: Agent) -> str:
available = skills_helper.list_skills(agent=agent)
result: list[str] = []
@@ -31,8 +32,4 @@ async def build_prompt(agent: Agent) -> str:
if not result:
return ""
- prompt = agent.read_prompt("agent.system.skills.md", skills="\n".join(result))
-
- data: dict[str, Any] = {"prompt": prompt}
- await call_extensions_async("system_prompt_skills", agent=agent, data=data)
- return data["prompt"]
+ return agent.read_prompt("agent.system.skills.md", skills="\n".join(result))
diff --git a/extensions/python/system_prompt/_14_project_prompt.py b/extensions/python/system_prompt/_14_project_prompt.py
index 08d3b86b7..41948f5ed 100644
--- a/extensions/python/system_prompt/_14_project_prompt.py
+++ b/extensions/python/system_prompt/_14_project_prompt.py
@@ -1,6 +1,6 @@
from typing import Any
-from helpers.extension import Extension, call_extensions_async
+from helpers.extension import Extension, extensible
from helpers import projects
from agent import Agent, LoopData
@@ -20,6 +20,7 @@ class ProjectPrompt(Extension):
system_prompt.append(prompt)
+@extensible
async def build_prompt(agent: Agent) -> str:
result = agent.read_prompt("agent.system.projects.main.md")
project_name = agent.context.get_data(projects.CONTEXT_DATA_KEY_PROJECT)
@@ -30,7 +31,4 @@ async def build_prompt(agent: Agent) -> str:
)
else:
result += "\n\n" + agent.read_prompt("agent.system.projects.inactive.md")
-
- data: dict[str, Any] = {"prompt": result}
- await call_extensions_async("system_prompt_project", agent=agent, data=data)
- return data["prompt"]
+ return result