refactor: use @extensible decorator on build_prompt functions

linuztx committed Mar 20, 2026 at 12:48 UTC 8847af089ace74790d8e6aec6d16f84708a32935
6 files changed +18 -30
extensions/python/system_prompt/_10_main_prompt.py
+3 -4
@@ -1,6 +1,6 @@
1 from typing import Any
2
3 -from helpers.extension import Extension, call_extensions_async
3 +from helpers.extension import Extension, extensible
4 from agent import Agent, LoopData
5
6
@@ -18,7 +18,6 @@ class MainPrompt(Extension):
18 system_prompt.append(prompt)
19
20
21 +@extensible
22 async def build_prompt(agent: Agent) -> str:
22 - data: dict[str, Any] = {"prompt": agent.read_prompt("agent.system.main.md")}
23 - await call_extensions_async("system_prompt_main", agent=agent, data=data)
24 - return data["prompt"]
23 + return agent.read_prompt("agent.system.main.md")
extensions/python/system_prompt/_11_tools_prompt.py
+3 -4
@@ -1,7 +1,7 @@
1 import os
2 from typing import Any
3
4 -from helpers.extension import Extension, call_extensions_async
4 +from helpers.extension import Extension, extensible
5 from helpers import files, subagents
6 from helpers.print_style import PrintStyle
7 from agent import Agent, LoopData
@@ -24,6 +24,7 @@ class ToolsPrompt(Extension):
24 system_prompt.append(prompt)
25
26
27 +@extensible
28 async def build_prompt(agent: Agent) -> str:
29 # collect tool files from all prompt directories
30 prompt_dirs = subagents.get_paths(agent, "prompts")
@@ -54,6 +55,4 @@ async def build_prompt(agent: Agent) -> str:
55 if chat_cfg.get("vision", False):
56 prompt += "\n\n" + agent.read_prompt("agent.system.tools_vision.md")
57
57 - data: dict[str, Any] = {"prompt": prompt}
58 - await call_extensions_async("system_prompt_tools", agent=agent, data=data)
59 - return data["prompt"]
58 + return prompt
extensions/python/system_prompt/_12_mcp_prompt.py
+3 -5
@@ -1,6 +1,6 @@
1 from typing import Any
2
3 -from helpers.extension import Extension, call_extensions_async
3 +from helpers.extension import Extension, extensible
4 from helpers.mcp_handler import MCPConfig
5 from agent import Agent, LoopData
6
@@ -20,6 +20,7 @@ class MCPToolsPrompt(Extension):
20 system_prompt.append(prompt)
21
22
23 +@extensible
24 async def build_prompt(agent: Agent) -> str:
25 mcp_config = MCPConfig.get_instance()
26 if not mcp_config.servers:
@@ -29,7 +30,4 @@ async def build_prompt(agent: Agent) -> str:
30 agent.context.log.set_progress("Collecting MCP tools")
31 tools = mcp_config.get_tools_prompt()
32 agent.context.log.set_progress(pre_progress)
32 -
33 - data: dict[str, Any] = {"prompt": tools}
34 - await call_extensions_async("system_prompt_mcp", agent=agent, data=data)
35 - return data["prompt"]
33 + return tools
extensions/python/system_prompt/_13_secrets_prompt.py
+3 -6
@@ -1,6 +1,6 @@
1 from typing import Any
2
3 -from helpers.extension import Extension, call_extensions_async
3 +from helpers.extension import Extension, extensible
4 from agent import Agent, LoopData
5
6
@@ -19,6 +19,7 @@ class SecretsPrompt(Extension):
19 system_prompt.append(prompt)
20
21
22 +@extensible
23 async def build_prompt(agent: Agent) -> str:
24 try:
25 from helpers.secrets import get_secrets_manager
@@ -27,12 +28,8 @@ async def build_prompt(agent: Agent) -> str:
28 secrets_manager = get_secrets_manager(agent.context)
29 secrets = secrets_manager.get_secrets_for_prompt()
30 variables = get_settings()["variables"]
30 - prompt = agent.read_prompt(
31 + return agent.read_prompt(
32 "agent.system.secrets.md", secrets=secrets, vars=variables
33 )
33 -
34 - data: dict[str, Any] = {"prompt": prompt}
35 - await call_extensions_async("system_prompt_secrets", agent=agent, data=data)
36 - return data["prompt"]
34 except Exception:
35 return ""
extensions/python/system_prompt/_13_skills_prompt.py
+3 -6
@@ -1,6 +1,6 @@
1 from typing import Any
2
3 -from helpers.extension import Extension, call_extensions_async
3 +from helpers.extension import Extension, extensible
4 from helpers import skills as skills_helper
5 from agent import Agent, LoopData
6
@@ -20,6 +20,7 @@ class SkillsPrompt(Extension):
20 system_prompt.append(prompt)
21
22
23 +@extensible
24 async def build_prompt(agent: Agent) -> str:
25 available = skills_helper.list_skills(agent=agent)
26 result: list[str] = []
@@ -31,8 +32,4 @@ async def build_prompt(agent: Agent) -> str:
32 if not result:
33 return ""
34
34 - prompt = agent.read_prompt("agent.system.skills.md", skills="\n".join(result))
35 -
36 - data: dict[str, Any] = {"prompt": prompt}
37 - await call_extensions_async("system_prompt_skills", agent=agent, data=data)
38 - return data["prompt"]
35 + return agent.read_prompt("agent.system.skills.md", skills="\n".join(result))
extensions/python/system_prompt/_14_project_prompt.py
+3 -5
@@ -1,6 +1,6 @@
1 from typing import Any
2
3 -from helpers.extension import Extension, call_extensions_async
3 +from helpers.extension import Extension, extensible
4 from helpers import projects
5 from agent import Agent, LoopData
6
@@ -20,6 +20,7 @@ class ProjectPrompt(Extension):
20 system_prompt.append(prompt)
21
22
23 +@extensible
24 async def build_prompt(agent: Agent) -> str:
25 result = agent.read_prompt("agent.system.projects.main.md")
26 project_name = agent.context.get_data(projects.CONTEXT_DATA_KEY_PROJECT)
@@ -30,7 +31,4 @@ async def build_prompt(agent: Agent) -> str:
31 )
32 else:
33 result += "\n\n" + agent.read_prompt("agent.system.projects.inactive.md")
33 -
34 - data: dict[str, Any] = {"prompt": result}
35 - await call_extensions_async("system_prompt_project", agent=agent, data=data)
36 - return data["prompt"]
34 + return result