Browse Source

Refactor code by commenting out unused imports and decorators in various modules to improve clarity and maintainability. Update the default system prompt with strict rules for brevity and confidence in responses, enhancing user interaction guidelines.

master
Mohsen Taba 5 days ago
parent
commit
c2d0d5bf54
  1. 6
      out.md
  2. 2
      src/agents/base_agent.py
  3. 4
      src/main.py
  4. 4
      src/utils/hooks.py
  5. 6
      src/utils/load_settings.py

6
out.md

@ -30,3 +30,9 @@ Here is the context from the database:\n---------------------\n[Source: Unknown
--------------------------------------------------- ---------------------------------------------------
بسم الله الرحمن الرحیم \n\nبر اساس روایات نقل‌شده از امام رضا (علیه‌السلام)، صدقه دادن در ماه شعبان دارای ثواب‌های بزرگ الهی است: \n\n۱. **حرام‌شدن بدن بر آتش دوزخ**: \nامام رضا (علیه‌السلام) فرمودند: \n> **«وَمَن تَصَدَّقَ فِي شَعبَانَ بِصَدَقَةٍ وَلَو بِشِقِّ تَمرَةٍ حَرَّمَ اللَّهُ جَسَدَهُ عَلَى النَّارِ»** \n*(هرکس در ماه شعبان صدقه‌ای بدهد؛ حتی به اندازه نصف خرما، خداوند بدنش را بر آتش دوزخ حرام می‌کند.)* \n(منبع: کتاب «خصال» و روایات منقول در منابع پایگاه) \n\n۲. **تکمیل‌کننده ایمان**: \nصدقه در این ماه، نشانه‌ای از ایمان عملی است و زمینۀ بخشش گناهان گذشته را فراهم می‌آورد، چنانکه امام (ع) فرمودند: هفتاد بار استغفار در هر روز شعبان گناهان را می‌پوشاند. \n\n۳. **معنویت هم‌سو با ماه رمضان**: \nصدقه‌های شعبان، مؤمنان را برای ورود به ماه رمضان آماده می‌کند و این هماهنگی، پاداش را مضاعف می‌نماید. \n\n۴. **نماد نزدیکی به خدا**: \nامام (ع) تصریح فرمودند که اعمال نیک در این ماه ــ از جمله صدقه ــ موجب می‌شود خداوند متعال بندگانش را قبل از رمضان ببخشاید. \n\n### نکتهٔ عملی \nحتی کم‌ترین صدقه (مانند نصف خرما) نیز این پاداش را دارد، زیرا پذیرش اعمال به *نیت خالص* و *رهنمود اهل‌بیت (ع)* بستگی دارد، نه مقدار مال. \n\n**والسّلام علیکم ورحمة الله وبرکاته** \nوَ اللهُ أعلَمُ بِالصَّواب. \n\n--- \n**منبع است duringداد:** \n- فضیلت ماه شعبان در پایگاه داده، با استناد به حدیث امام رضا (علیه‌السلام)." بسم الله الرحمن الرحیم \n\nبر اساس روایات نقل‌شده از امام رضا (علیه‌السلام)، صدقه دادن در ماه شعبان دارای ثواب‌های بزرگ الهی است: \n\n۱. **حرام‌شدن بدن بر آتش دوزخ**: \nامام رضا (علیه‌السلام) فرمودند: \n> **«وَمَن تَصَدَّقَ فِي شَعبَانَ بِصَدَقَةٍ وَلَو بِشِقِّ تَمرَةٍ حَرَّمَ اللَّهُ جَسَدَهُ عَلَى النَّارِ»** \n*(هرکس در ماه شعبان صدقه‌ای بدهد؛ حتی به اندازه نصف خرما، خداوند بدنش را بر آتش دوزخ حرام می‌کند.)* \n(منبع: کتاب «خصال» و روایات منقول در منابع پایگاه) \n\n۲. **تکمیل‌کننده ایمان**: \nصدقه در این ماه، نشانه‌ای از ایمان عملی است و زمینۀ بخشش گناهان گذشته را فراهم می‌آورد، چنانکه امام (ع) فرمودند: هفتاد بار استغفار در هر روز شعبان گناهان را می‌پوشاند. \n\n۳. **معنویت هم‌سو با ماه رمضان**: \nصدقه‌های شعبان، مؤمنان را برای ورود به ماه رمضان آماده می‌کند و این هماهنگی، پاداش را مضاعف می‌نماید. \n\n۴. **نماد نزدیکی به خدا**: \nامام (ع) تصریح فرمودند که اعمال نیک در این ماه ــ از جمله صدقه ــ موجب می‌شود خداوند متعال بندگانش را قبل از رمضان ببخشاید. \n\n### نکتهٔ عملی \nحتی کم‌ترین صدقه (مانند نصف خرما) نیز این پاداش را دارد، زیرا پذیرش اعمال به *نیت خالص* و *رهنمود اهل‌بیت (ع)* بستگی دارد، نه مقدار مال. \n\n**والسّلام علیکم ورحمة الله وبرکاته** \nوَ اللهُ أعلَمُ بِالصَّواب. \n\n--- \n**منبع است duringداد:** \n- فضیلت ماه شعبان در پایگاه داده، با استناد به حدیث امام رضا (علیه‌السلام)."
------------------------
۱. **پیش‌بینی و وصیت خود امام:**
بر اساس روایات متعدد، امام رضا علیه‌السلام از پیش محل دفن خود را預言 کرده بودند. ایشان فرمودند:
*«یُدْفَنِي فِي بِلَادِ غُرْبَةٍ»* (مرا در سرزمین غربت به خاک می‌سپارند).

2
src/agents/base_agent.py

@ -10,7 +10,7 @@ from agno.guardrails import PromptInjectionGuardrail
from src.guardrails.limit import InputLimitGuardrail from src.guardrails.limit import InputLimitGuardrail
from src.utils.hooks import sync_config_hook, rag_injection_hook from src.utils.hooks import sync_config_hook, rag_injection_hook
from src.utils.load_settings import default_system_prompt from src.utils.load_settings import default_system_prompt
from src.agents.tracing_agent import TracingAgent
# from src.agents.tracing_agent import TracingAgent

4
src/main.py

@ -16,8 +16,8 @@ from src.models.factory import ModelFactory
from src.knowledge.rag_pipeline import create_knowledge_base from src.knowledge.rag_pipeline import create_knowledge_base
from src.core.logging import logger from src.core.logging import logger
from src.knowledge.embedding_factory import EmbeddingFactory from src.knowledge.embedding_factory import EmbeddingFactory
from langfuse.openai import openai as langfuse_openai
from langfuse import Langfuse
# from langfuse.openai import openai as langfuse_openai
# from langfuse import Langfuse
from src.utils.load_settings import get_active_agent_config from src.utils.load_settings import get_active_agent_config
from dotenv import load_dotenv from dotenv import load_dotenv
load_dotenv() load_dotenv()

4
src/utils/hooks.py

@ -1,7 +1,7 @@
from agno.run.agent import RunInput from agno.run.agent import RunInput
from src.utils.load_settings import get_active_agent_config from src.utils.load_settings import get_active_agent_config
from src.utils.search_knowledge import build_rag_prompt from src.utils.search_knowledge import build_rag_prompt
from langfuse.decorators import observe
# from langfuse.decorators import observe
@ -32,7 +32,7 @@ def sync_config_hook(run_input: RunInput, **kwargs):
return run_input return run_input
@observe(name="rag_injection_hook")
# @observe(name="rag_injection_hook")
def rag_injection_hook(run_input: RunInput, **kwargs): def rag_injection_hook(run_input: RunInput, **kwargs):
""" """
Intercepts the user input and injects RAG context. Intercepts the user input and injects RAG context.

6
src/utils/load_settings.py

@ -58,11 +58,15 @@ def default_system_prompt():
"You are a humble, polite, and knowledgeable Khadem (Servant) of the Holy Shrine of Ali ibn Musa al-Reza (peace be upon him) in Mashhad. Your purpose is to welcome, guide, and serve the pilgrims (Zaer) and visitors who seek knowledge about the Shrine, its history, its categories, and its authors.", "You are a humble, polite, and knowledgeable Khadem (Servant) of the Holy Shrine of Ali ibn Musa al-Reza (peace be upon him) in Mashhad. Your purpose is to welcome, guide, and serve the pilgrims (Zaer) and visitors who seek knowledge about the Shrine, its history, its categories, and its authors.",
"You do not possess personal ego. You consider serving the pilgrims of Imam Reza (A.S.) to be your greatest honor. You embody the egalitarian spirit of the Shrine, treating every visitor—regardless of their background—with equal dignity, warmth, and respect.", "You do not possess personal ego. You consider serving the pilgrims of Imam Reza (A.S.) to be your greatest honor. You embody the egalitarian spirit of the Shrine, treating every visitor—regardless of their background—with equal dignity, warmth, and respect.",
"STRICT RULE: Keep all answers very brief and concise. Never write more than 3 short paragraphs.",
""
# TONE AND DEMEANOR # TONE AND DEMEANOR
'''- **Greeting:** Always greet the user respectfully. Use traditional Islamic and Persian expressions of courtesy where appropriate, such as "Salaam" (Peace be upon you), "Dear Pilgrim", "Brother/Sister", or "May your pilgrimage be accepted" (Ziyarat Qabul). '''- **Greeting:** Always greet the user respectfully. Use traditional Islamic and Persian expressions of courtesy where appropriate, such as "Salaam" (Peace be upon you), "Dear Pilgrim", "Brother/Sister", or "May your pilgrimage be accepted" (Ziyarat Qabul).
- **Humility:** Speak softly, calmly, and with profound respect. Use phrases like "I am at your service," "It is my honor to assist you," or "Please allow me to share what is written." - **Humility:** Speak softly, calmly, and with profound respect. Use phrases like "I am at your service," "It is my honor to assist you," or "Please allow me to share what is written."
- **Empathy:** If a user expresses distress or seeks spiritual comfort, respond with deep empathy and gentle reassurance, reflecting the peaceful atmosphere of the Holy Shrine. - **Empathy:** If a user expresses distress or seeks spiritual comfort, respond with deep empathy and gentle reassurance, reflecting the peaceful atmosphere of the Holy Shrine.
''', ''',
"STRICT RULE FOR GREETINGS: Keep greetings extremely brief (e.g., a simple 'Salaam' or 'سلام بر شما'). Do NOT write long welcoming prayers, introductions, or phrases like 'It is my honor to serve you'. Dive straight into the answer immediately to respect the user's time.",
# KNOWLEDGE AND RAG CONSTRAINTS (CRITICAL) # KNOWLEDGE AND RAG CONSTRAINTS (CRITICAL)
'''Your knowledge is STRICTLY limited to the context provided to you through your Knowledge Base (the Wiki database). '''Your knowledge is STRICTLY limited to the context provided to you through your Knowledge Base (the Wiki database).
@ -72,6 +76,8 @@ def default_system_prompt():
3. **Use Metadata:** When answering questions about a Wiki entry, naturally weave in the Author or Category information if it adds value to the pilgrim's understanding (e.g., "According to the writings of [Author] in the [Category] section..."). 3. **Use Metadata:** When answering questions about a Wiki entry, naturally weave in the Author or Category information if it adds value to the pilgrim's understanding (e.g., "According to the writings of [Author] in the [Category] section...").
''', ''',
"STRICT RULE FOR CONFIDENCE: Speak with quiet, scholarly confidence. NEVER use self-deprecating phrases like 'based on the texts entrusted to me', 'available to me', 'as a humble servant', or 'my knowledge is limited'. Do not draw attention to the fact that you are reading from a database. State the facts directly. If you need to cite a source, use simple, authoritative phrases like 'According to the texts' or 'بر اساس منابع موجود'.",
# INTERACTION GUIDELINES # INTERACTION GUIDELINES
'''- **Clarity and Brevity:** While being polite, ensure your answers are clear, structured, and easy to read. Use bullet points if explaining a list of locations, historical facts, or etiquette rules. '''- **Clarity and Brevity:** While being polite, ensure your answers are clear, structured, and easy to read. Use bullet points if explaining a list of locations, historical facts, or etiquette rules.
- **Multilingual Grace:** If a user speaks to you in a different language (like Persian, Arabic, or English), seamlessly reply in that same language while maintaining the exact same respectful Khadem persona. - **Multilingual Grace:** If a user speaks to you in a different language (like Persian, Arabic, or English), seamlessly reply in that same language while maintaining the exact same respectful Khadem persona.

Loading…
Cancel
Save