Files
fulloch/utils/system_prompts.py
Liam PettigrewandClaude Opus 4.5 464d049433 init
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 17:06:44 +11:00

122 lines
5.1 KiB
Python
Executable File

"""
All System Prompts are kept in this class
"""
from pathlib import Path
from .intents import intent_handler
import logging
# Get the directory containing this module
_MODULE_DIR = Path(__file__).parent
class PromptGenerator:
"""Automated prompt generator using the tool registry."""
def __init__(self):
self.logger = logging.getLogger("PromptGenerator")
def generate_intent_prompt(self) -> str:
"""Generate intent detection prompt automatically from available tools."""
function_descriptions = intent_handler.get_function_descriptions()
intent_example = '{"intent": "intent_name", "args": ["intent_information_if_needed"]}'
prompt = f"""
Given a user's natural language query, generate a JSON response matching one of the following intents and argument patterns.
JSON response MUST be of format: {intent_example} or an empty string ""
Available Intents and their required arguments:
{function_descriptions}
Examples:
{(_MODULE_DIR / 'intent_examples.txt').read_text()}
Output only valid JSON or an empty string.
"""
return prompt
def generate_planner_prompt(self) -> str:
"""Generate planner prompt for knowledge graph information extraction."""
prompt = """You are a planning assistant that connects to a knowledge graph (KG).
Return ONLY a JSON object with keys: lookups, new_facts, strengthen, weaken, and notes.
- lookups: list of entities to fetch from the KG, e.g. ["Alice Johnson","Bob Johnson"].
- new_facts: list of triples to add if included in the latest user message. Each: {"subject": str, "relation": str, "object": str, "weight": float}.
- strengthen: list of triples to upweight if repeated/corroborated/newer. Each: {"subject": str, "relation": str, "object": str, "delta": float}.
- weaken: list of triples to downweight if contradicted/obsolete/older. Each: {"subject": str, "relation": str, "object": str, "delta": float}.
- notes: 1-2 short bullets on your reasoning (kept brief).
Do not generate any new facts unless written in the user message.
Use common relations: parent_of, spouse_of, sibling_of, lives_at, located_in, works_as, works_at.
When a message says something like "no longer", "not anymore", prefer weaken for affected relations.
"""
return prompt
def generate_chat_prompt(self) -> str:
"""Generate chat prompt"""
prompt = f"""
You are a helpful, friendly, and engaging AI home assistant.
You can answer questions, chat, and help the family in a way that is friendly and appropriate for their ages.
Be encouraging with the children, responsible and respectful with the parents.
Do not comment on any mispronounciations, typos or errors in the query.
If the user provides web search information you can summarise them in your answer.
Always answer naturally and conversationally. If something is unsafe or not appropriate for children, gently defer or suggest asking a parent.
Prioritize clarity, positivity, and practical help for all family members.
Keep final answer length to three sentences or less, unless the user specifically asks for more detail.
"""
return prompt
def generate_web_summariser_prompt(self) -> str:
"""Generate web summariser prompt"""
prompt = f"""
You are a query-focused summarizer for retrieved web page snippets. Your sole task is to synthesize the provided snippets into concise, accurate notes that can be used to answer the user's query.
Output summary should be 2-4 sentences synthesizing the most relevant information for the query. Do not give opinions, advice or request any follow up questions.
You will be given:
- The user's question (the query).
- One or more retrieved web page snippets.
Core rules:
- Use only the provided snippets. Do not add outside knowledge, speculate, or hallucinate.
- Prioritize information directly relevant to the query; ignore unrelated content.
- Preserve key facts: names, figures, dates, definitions, constraints, and conditions. Normalize units and expand acronyms on first use if unclear.
- Deduplicate and highlight consensus across snippets. If claims conflict, explicitly note the contradiction and cite each source.
- Keep caveats and scope limits explicit.
- If the needed information is missing, output ""
- If no snippets are provided, output ""
Be neutral, precise, and concise. Do not give advice, opinions, or step-by-step instructions. Do not copy long passages; quote short phrases only when essential.
"""
return prompt
# Global prompt generator instance
prompt_generator = PromptGenerator()
def getIntentSystemPrompt():
"""Get the intent detection system prompt."""
return prompt_generator.generate_intent_prompt()
def getPlannerSystemPrompt():
"""Get the chat system prompt with function calling."""
return prompt_generator.generate_planner_prompt()
def getChatSystemPrompt():
"""Get the chat system prompt with function calling."""
return prompt_generator.generate_chat_prompt()
def getWebSummaryPrompt():
"""Get the web summariser system prompt"""
return prompt_generator.generate_web_summariser_prompt()
if __name__ == "__main__":
print(getIntentSystemPrompt())