From a8f1589b1086746b0d4677006d68c54de8764feb Mon Sep 17 00:00:00 2001 From: Roi Glinik Date: Sun, 22 Jun 2025 12:09:13 +0300 Subject: [PATCH 1/4] add global date context --- holmes/plugins/prompts/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/holmes/plugins/prompts/__init__.py b/holmes/plugins/prompts/__init__.py index 6a818a4cf2..77915fb2c2 100644 --- a/holmes/plugins/prompts/__init__.py +++ b/holmes/plugins/prompts/__init__.py @@ -2,6 +2,7 @@ import os.path from typing import Optional from jinja2 import Environment, FileSystemLoader +from datetime import datetime, timezone THIS_DIR = os.path.abspath(os.path.dirname(__file__)) @@ -35,9 +36,12 @@ def load_and_render_prompt(prompt: str, context: Optional[dict] = None) -> str: env = Environment( loader=FileSystemLoader(THIS_DIR), ) + template = env.from_string(prompt_as_str) if context is None: - context = {} + context = {"now": datetime.now(timezone.utc)} + else: + context.update({"now": datetime.now(timezone.utc)}) return template.render(**context) From 771c33acdcf7d6f2fca8b88c55b806a9e990b8f9 Mon Sep 17 00:00:00 2001 From: Roi Glinik Date: Sun, 22 Jun 2025 12:28:24 +0300 Subject: [PATCH 2/4] add current date to system prompts --- holmes/plugins/prompts/generic_ask_conversation.jinja2 | 1 + .../plugins/prompts/generic_ask_for_issue_conversation.jinja2 | 1 + holmes/plugins/prompts/generic_investigation.jinja2 | 2 +- holmes/plugins/prompts/kubernetes_workload_ask.jinja2 | 2 +- holmes/plugins/prompts/kubernetes_workload_chat.jinja2 | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/holmes/plugins/prompts/generic_ask_conversation.jinja2 b/holmes/plugins/prompts/generic_ask_conversation.jinja2 index 6753fb6fb2..9eec1c5ea2 100644 --- a/holmes/plugins/prompts/generic_ask_conversation.jinja2 +++ b/holmes/plugins/prompts/generic_ask_conversation.jinja2 @@ -3,6 +3,7 @@ Whenever possible you MUST first use tools to investigate then answer the questi Do not say 'based on the tool output' or explicitly refer to tools at all. If you output an answer and then realize you need to call more tools or there are possible next steps, you may do so by calling tools at that point in time. If you have a good and concrete suggestion for how the user can fix something, tell them even if not asked explicitly +When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now.timestamp() | int }}. Use conversation history to maintain continuity when appropriate, ensuring efficiency in your responses. diff --git a/holmes/plugins/prompts/generic_ask_for_issue_conversation.jinja2 b/holmes/plugins/prompts/generic_ask_for_issue_conversation.jinja2 index 8a67401d5b..f0fc25fda1 100644 --- a/holmes/plugins/prompts/generic_ask_for_issue_conversation.jinja2 +++ b/holmes/plugins/prompts/generic_ask_for_issue_conversation.jinja2 @@ -2,6 +2,7 @@ You are a tool-calling AI assist provided with common devops and IT tools that y Whenever possible you MUST first use tools to investigate then answer the question. Do not say 'based on the tool output' or explicitly refer to tools at all. If you output an answer and then realize you need to call more tools or there are possible next steps, you may do so by calling tools at that point in time. +When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now.timestamp() | int }}. ### Context Awareness: Be aware that this conversation is follow-up questions to a prior investigation conducted for the {{issue}}. diff --git a/holmes/plugins/prompts/generic_investigation.jinja2 b/holmes/plugins/prompts/generic_investigation.jinja2 index 052717095b..15c6c4e756 100644 --- a/holmes/plugins/prompts/generic_investigation.jinja2 +++ b/holmes/plugins/prompts/generic_investigation.jinja2 @@ -3,7 +3,7 @@ Whenever possible you MUST first use tools to investigate then answer the questi Do not say 'based on the tool output' Provide an terse analysis of the following {{ issue.source_type }} alert/issue and why it is firing. -* When querying tools, always query for the relevant time period +* When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now.timestamp() | int }}. * If the tool requires string format timestamps, query from 'start_timestamp' until 'end_timestamp' * If the tool requires timestamps in milliseconds, query from 'start_timestamp' until 'end_timestamp' * If you need timestamp in string format, query from 'start_timestamp_millis' until 'end_timestamp_millis' diff --git a/holmes/plugins/prompts/kubernetes_workload_ask.jinja2 b/holmes/plugins/prompts/kubernetes_workload_ask.jinja2 index 7cf3a31b89..1dc4687141 100644 --- a/holmes/plugins/prompts/kubernetes_workload_ask.jinja2 +++ b/holmes/plugins/prompts/kubernetes_workload_ask.jinja2 @@ -4,7 +4,7 @@ Do not say 'based on the tool output' or explicitly refer to tools at all. If you output an answer and then realize you need to call more tools or there are possible next steps, you may do so by calling tools at that point in time. If the user provides you with extra instructions in a triple single quotes section, ALWAYS perform their instructions and then perform your investigation. - +When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now.timestamp() | int }}. Global Instructions You may receive a set of “Global Instructions” that describe how to perform certain tasks, handle certain situations, or apply certain best practices. They are not mandatory for every request, but serve as a reference resource and must be used if the current scenario or user request aligns with one of the described methods or conditions. diff --git a/holmes/plugins/prompts/kubernetes_workload_chat.jinja2 b/holmes/plugins/prompts/kubernetes_workload_chat.jinja2 index cc63b18dbf..cff8bf9828 100644 --- a/holmes/plugins/prompts/kubernetes_workload_chat.jinja2 +++ b/holmes/plugins/prompts/kubernetes_workload_chat.jinja2 @@ -2,6 +2,7 @@ You are a tool-calling AI assist provided with common DevOps and IT tools that y Whenever possible, you MUST first use tools to investigate, then answer the question. Do not say 'based on the tool output' or explicitly refer to tools at all. If you output an answer and then realize you need to call more tools or there are possible next steps, you may do so by calling tools at that point in time. +When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now.timestamp() | int }}. ### Context Awareness: Be aware that this conversation is follow-up questions to a prior investigation conducted for the {{resource}}. From c231b69b8aa3b9ddacfafec9c35e578e2636b87a Mon Sep 17 00:00:00 2001 From: Roi Glinik Date: Sun, 22 Jun 2025 12:29:25 +0300 Subject: [PATCH 3/4] fix code --- holmes/plugins/prompts/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/holmes/plugins/prompts/__init__.py b/holmes/plugins/prompts/__init__.py index 77915fb2c2..b991a30fb4 100644 --- a/holmes/plugins/prompts/__init__.py +++ b/holmes/plugins/prompts/__init__.py @@ -40,8 +40,8 @@ def load_and_render_prompt(prompt: str, context: Optional[dict] = None) -> str: template = env.from_string(prompt_as_str) if context is None: - context = {"now": datetime.now(timezone.utc)} - else: - context.update({"now": datetime.now(timezone.utc)}) + context = {} + + context.update({"now": datetime.now(timezone.utc)}) return template.render(**context) From cbbcee02c9be11f5d4bf386748f2518b7768aecc Mon Sep 17 00:00:00 2001 From: Roi Glinik Date: Sun, 22 Jun 2025 13:41:14 +0300 Subject: [PATCH 4/4] parse dates before sending to context --- holmes/plugins/prompts/__init__.py | 3 ++- holmes/plugins/prompts/generic_ask_conversation.jinja2 | 2 +- .../plugins/prompts/generic_ask_for_issue_conversation.jinja2 | 2 +- holmes/plugins/prompts/generic_investigation.jinja2 | 2 +- holmes/plugins/prompts/kubernetes_workload_ask.jinja2 | 2 +- holmes/plugins/prompts/kubernetes_workload_chat.jinja2 | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/holmes/plugins/prompts/__init__.py b/holmes/plugins/prompts/__init__.py index b991a30fb4..24c683b9f1 100644 --- a/holmes/plugins/prompts/__init__.py +++ b/holmes/plugins/prompts/__init__.py @@ -42,6 +42,7 @@ def load_and_render_prompt(prompt: str, context: Optional[dict] = None) -> str: if context is None: context = {} - context.update({"now": datetime.now(timezone.utc)}) + now = datetime.now(timezone.utc) + context.update({"now": f"{now}", "now_timestamp_seconds": int(now.timestamp())}) return template.render(**context) diff --git a/holmes/plugins/prompts/generic_ask_conversation.jinja2 b/holmes/plugins/prompts/generic_ask_conversation.jinja2 index 9eec1c5ea2..ca5f17a6cb 100644 --- a/holmes/plugins/prompts/generic_ask_conversation.jinja2 +++ b/holmes/plugins/prompts/generic_ask_conversation.jinja2 @@ -3,7 +3,7 @@ Whenever possible you MUST first use tools to investigate then answer the questi Do not say 'based on the tool output' or explicitly refer to tools at all. If you output an answer and then realize you need to call more tools or there are possible next steps, you may do so by calling tools at that point in time. If you have a good and concrete suggestion for how the user can fix something, tell them even if not asked explicitly -When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now.timestamp() | int }}. +When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now_timestamp_seconds }}. Use conversation history to maintain continuity when appropriate, ensuring efficiency in your responses. diff --git a/holmes/plugins/prompts/generic_ask_for_issue_conversation.jinja2 b/holmes/plugins/prompts/generic_ask_for_issue_conversation.jinja2 index f0fc25fda1..42b0c19abb 100644 --- a/holmes/plugins/prompts/generic_ask_for_issue_conversation.jinja2 +++ b/holmes/plugins/prompts/generic_ask_for_issue_conversation.jinja2 @@ -2,7 +2,7 @@ You are a tool-calling AI assist provided with common devops and IT tools that y Whenever possible you MUST first use tools to investigate then answer the question. Do not say 'based on the tool output' or explicitly refer to tools at all. If you output an answer and then realize you need to call more tools or there are possible next steps, you may do so by calling tools at that point in time. -When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now.timestamp() | int }}. +When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now_timestamp_seconds }}. ### Context Awareness: Be aware that this conversation is follow-up questions to a prior investigation conducted for the {{issue}}. diff --git a/holmes/plugins/prompts/generic_investigation.jinja2 b/holmes/plugins/prompts/generic_investigation.jinja2 index 15c6c4e756..f64a741558 100644 --- a/holmes/plugins/prompts/generic_investigation.jinja2 +++ b/holmes/plugins/prompts/generic_investigation.jinja2 @@ -3,7 +3,7 @@ Whenever possible you MUST first use tools to investigate then answer the questi Do not say 'based on the tool output' Provide an terse analysis of the following {{ issue.source_type }} alert/issue and why it is firing. -* When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now.timestamp() | int }}. +* When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now_timestamp_seconds }}. * If the tool requires string format timestamps, query from 'start_timestamp' until 'end_timestamp' * If the tool requires timestamps in milliseconds, query from 'start_timestamp' until 'end_timestamp' * If you need timestamp in string format, query from 'start_timestamp_millis' until 'end_timestamp_millis' diff --git a/holmes/plugins/prompts/kubernetes_workload_ask.jinja2 b/holmes/plugins/prompts/kubernetes_workload_ask.jinja2 index 1dc4687141..3b9afaab71 100644 --- a/holmes/plugins/prompts/kubernetes_workload_ask.jinja2 +++ b/holmes/plugins/prompts/kubernetes_workload_ask.jinja2 @@ -4,7 +4,7 @@ Do not say 'based on the tool output' or explicitly refer to tools at all. If you output an answer and then realize you need to call more tools or there are possible next steps, you may do so by calling tools at that point in time. If the user provides you with extra instructions in a triple single quotes section, ALWAYS perform their instructions and then perform your investigation. -When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now.timestamp() | int }}. +When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now_timestamp_seconds }}. Global Instructions You may receive a set of “Global Instructions” that describe how to perform certain tasks, handle certain situations, or apply certain best practices. They are not mandatory for every request, but serve as a reference resource and must be used if the current scenario or user request aligns with one of the described methods or conditions. diff --git a/holmes/plugins/prompts/kubernetes_workload_chat.jinja2 b/holmes/plugins/prompts/kubernetes_workload_chat.jinja2 index cff8bf9828..daa3dc3ddb 100644 --- a/holmes/plugins/prompts/kubernetes_workload_chat.jinja2 +++ b/holmes/plugins/prompts/kubernetes_workload_chat.jinja2 @@ -2,7 +2,7 @@ You are a tool-calling AI assist provided with common DevOps and IT tools that y Whenever possible, you MUST first use tools to investigate, then answer the question. Do not say 'based on the tool output' or explicitly refer to tools at all. If you output an answer and then realize you need to call more tools or there are possible next steps, you may do so by calling tools at that point in time. -When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now.timestamp() | int }}. +When querying tools, always query for the relevant time period. The current UTC date and time are {{ now }}. The current UTC timestamp in seconds is {{ now_timestamp_seconds }}. ### Context Awareness: Be aware that this conversation is follow-up questions to a prior investigation conducted for the {{resource}}.