Skip to content

Commit ab88eea

Browse files
committed
fix: anchor recency to current date in chat prompt
1 parent 2091c98 commit ab88eea

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/kg_agent_loop.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
import time
66
import uuid
7+
from datetime import datetime
78
from dataclasses import dataclass
89
from typing import Any
910

@@ -572,9 +573,14 @@ def __init__(
572573
self.client = genai.Client(api_key=api_key)
573574

574575
def _system_prompt(self) -> str:
576+
today = datetime.now().date().isoformat()
575577
return (
576578
"You are YuhHearDem, a friendly AI guide to Barbados Parliament debates. "
577579
"Keep a lightly Caribbean (Bajan) tone - warm and plainspoken, not cheesy.\n\n"
580+
f"Today's date is {today}.\n"
581+
"When the user asks for recent, latest, current, or new information, interpret it relative "
582+
"to today's date and prioritize the newest evidence (video_date/upload_date) from results. "
583+
"If the user asks about a time period without a year, assume the current year.\n\n"
578584
"You MUST ground everything in retrieved evidence from knowledge graph and transcript utterances.\n\n"
579585
"Rules:\n"
580586
"- Before answering, call the tool `kg_hybrid_graph_rag` to retrieve a compact subgraph + citations, including bill excerpts for legislation questions.\n"

tests/test_kg_agent_loop_unit.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
import json
5+
from datetime import datetime
56
from dataclasses import dataclass
67
from typing import Any
78

@@ -67,6 +68,24 @@ def generate_query_embedding(self, _query: str) -> list[float]:
6768
return [0.0] * 768
6869

6970

71+
def test_system_prompt_includes_current_date_and_recency_guidance() -> None:
72+
from lib.kg_agent_loop import KGAgentLoop
73+
74+
client = _FakeGeminiClient([])
75+
loop = KGAgentLoop(
76+
postgres=_FakePostgres(),
77+
embedding_client=_FakeEmbedding(),
78+
client=client,
79+
model="gemini-3-flash-preview",
80+
)
81+
82+
prompt = loop._system_prompt()
83+
today = datetime.now().date().isoformat()
84+
85+
assert f"Today's date is {today}." in prompt
86+
assert "When the user asks for recent" in prompt
87+
88+
7089
def test_agent_loop_runs_tool_then_answers():
7190
from lib.kg_agent_loop import KGAgentLoop
7291

0 commit comments

Comments
 (0)