Skip to content

Commit ae27f55

Browse files
committed
Share more logic for system prompt templating
1 parent 704e66e commit ae27f55

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

holmes/core/prompt.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from rich.console import Console
2-
from typing import Optional, List, Dict
2+
from typing import Optional, List, Dict, Any, Union
33
from pathlib import Path
4+
from holmes.plugins.prompts import load_and_render_prompt
5+
from holmes.plugins.runbooks import RunbookCatalog
46

57

68
def append_file_to_user_prompt(user_prompt: str, file_path: Path) -> str:
@@ -25,11 +27,31 @@ def append_all_files_to_user_prompt(
2527

2628
def build_initial_ask_messages(
2729
console: Console,
28-
system_prompt_rendered: str,
2930
initial_user_prompt: str,
3031
file_paths: Optional[List[Path]],
32+
tool_executor: Any, # ToolExecutor type
33+
runbooks: Union[RunbookCatalog, Dict, None] = None,
3134
) -> List[Dict]:
32-
"""Build the initial messages for the AI call."""
35+
"""Build the initial messages for the AI call.
36+
37+
Args:
38+
console: Rich console for output
39+
initial_user_prompt: The user's prompt
40+
file_paths: Optional list of files to include
41+
tool_executor: The tool executor with available toolsets
42+
runbooks: Optional runbook catalog
43+
"""
44+
# Load and render system prompt internally
45+
system_prompt_template = "builtin://generic_ask.jinja2"
46+
template_context = {
47+
"toolsets": tool_executor.toolsets,
48+
"runbooks": runbooks or {},
49+
}
50+
system_prompt_rendered = load_and_render_prompt(
51+
system_prompt_template, template_context
52+
)
53+
54+
# Append files to user prompt
3355
user_prompt_with_files = append_all_files_to_user_prompt(
3456
console, initial_user_prompt, file_paths
3557
)

holmes/interactive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,12 +756,12 @@ def display_recent_tool_outputs(
756756
def run_interactive_loop(
757757
ai: ToolCallingLLM,
758758
console: Console,
759-
system_prompt_rendered: str,
760759
initial_user_input: Optional[str],
761760
include_files: Optional[List[Path]],
762761
post_processing_prompt: Optional[str],
763762
show_tool_output: bool,
764763
tracer=None,
764+
runbooks=None,
765765
) -> None:
766766
# Initialize tracer - use DummyTracer if no tracer provided
767767
if tracer is None:
@@ -960,7 +960,7 @@ def get_bottom_toolbar():
960960

961961
if messages is None:
962962
messages = build_initial_ask_messages(
963-
console, system_prompt_rendered, user_input, include_files
963+
console, user_input, include_files, ai.tool_executor, runbooks
964964
)
965965
else:
966966
messages.append({"role": "user", "content": user_input})

holmes/main.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,6 @@ def ask(
180180
destination: Optional[DestinationType] = opt_destination,
181181
slack_token: Optional[str] = opt_slack_token,
182182
slack_channel: Optional[str] = opt_slack_channel,
183-
# advanced options for this command
184-
system_prompt: Optional[str] = typer.Option(
185-
"builtin://generic_ask.jinja2", help=system_prompt_help
186-
),
187183
show_tool_output: bool = typer.Option(
188184
False,
189185
"--show-tool-output",
@@ -255,12 +251,6 @@ def ask(
255251
refresh_toolsets=refresh_toolsets, # flag to refresh the toolset status
256252
tracer=tracer,
257253
)
258-
template_context = {
259-
"toolsets": ai.tool_executor.toolsets,
260-
"runbooks": config.get_runbook_catalog(),
261-
}
262-
263-
system_prompt_rendered = load_and_render_prompt(system_prompt, template_context) # type: ignore
264254

265255
if prompt_file and prompt:
266256
raise typer.BadParameter(
@@ -295,20 +285,21 @@ def ask(
295285
run_interactive_loop(
296286
ai,
297287
console,
298-
system_prompt_rendered,
299288
prompt,
300289
include_file,
301290
post_processing_prompt,
302291
show_tool_output,
303292
tracer,
293+
config.get_runbook_catalog(),
304294
)
305295
return
306296

307297
messages = build_initial_ask_messages(
308298
console,
309-
system_prompt_rendered,
310299
prompt, # type: ignore
311300
include_file,
301+
ai.tool_executor,
302+
config.get_runbook_catalog(),
312303
)
313304

314305
with tracer.start_trace(

0 commit comments

Comments
 (0)