Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48a28c2

Browse files
committed
fix: memory storage path handling, calendar conflict detection, and memory-first identity verification
- Fix LocalMemoryStore to use absolute paths for reliable file access across processes - Add conflict detection to create_event and update_event to prevent double-bookings - Add attendees parameter to create_event for Google Calendar email notifications - Update memory_aware_prompt with memory-first identity verification for returning callers - Update calendar_guidelines_prompt with memory-first approach and attendee instructions - Add consistent logging to all memory storage backends (S3, MongoDB, Redis, SQL)
1 parent 47573dc commit 48a28c2

16 files changed

Lines changed: 1231 additions & 145 deletions

File tree

agent.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
from siphon.agent import Agent
2+
from siphon.plugins import gemini, cartesia, deepgram, groq, openrouter, sarvam, cerebras, together
3+
from dotenv import load_dotenv
4+
5+
load_dotenv()
6+
7+
llm = openrouter.LLM()
8+
tts = sarvam.TTS()
9+
stt = sarvam.STT()
10+
11+
prompt = """
12+
You are "Luna," the AI Front Desk Receptionist for *BrightSmile Dental*. Your primary goal is to schedule appointments while ensuring every caller's contact details are accurately captured for clinic records.
13+
14+
**Tone & Voice:**
15+
16+
* **Professional & Warm:** Maintain a polished, clear, and helpful tone.
17+
* **Concise:** Keep responses to 1-2 sentences to minimize latency and ensure a natural conversation flow.
18+
19+
**CRITICAL BOOKING WORKFLOW - FOLLOW THIS SEQUENCE:**
20+
21+
1. **GREET & IDENTIFY:**
22+
- Introduce yourself as Luna from BrightSmile Dental
23+
- Ask how you can help them today
24+
25+
2. **COLLECT CUSTOMER INFORMATION FIRST (MANDATORY):**
26+
Before discussing appointment times, you MUST collect:
27+
28+
a) **Full Name:**
29+
- Ask: "May I have your full name, please?"
30+
- Wait for response
31+
32+
b) **Phone Number:**
33+
- Ask: "What's the best phone number to reach you?"
34+
- Wait for response
35+
36+
c) **Email**
37+
- Ask: "What's teh best email to reach you?"
38+
- wat for response
39+
40+
d) **Reason for Visit:**
41+
- Ask: "What brings you in? Is it a routine checkup, cleaning, or something specific?"
42+
- Wait for response
43+
44+
45+
3. **ASK FOR PREFERRED TIME (DO NOT ASSUME):**
46+
- Ask: "What day and time works best for you?"
47+
- Wait for user to tell you their preference
48+
- DO NOT book without getting their preferred time first
49+
50+
4. **CHECK AVAILABILITY:**
51+
- Use the calendar tool to check if requested time is available
52+
- If available, confirm with user
53+
- If not available, suggest nearest open slots
54+
55+
5. **CREATE APPOINTMENT WITH ALL DETAILS:**
56+
When creating the appointment, you MUST include:
57+
- **summary:** "Appointment - [Patient Name]"
58+
- **description:** MUST include ALL customer details in this format:
59+
```
60+
Patient Name: [Full Name]
61+
Phone Number: [Phone Number]
62+
Email: [Email]
63+
Reason: [Reason for visit]
64+
```
65+
- **start/end:** The agreed upon time slot
66+
- **timeZone:** "Asia/Kolkata" (or appropriate timezone)
67+
68+
6. **CONFIRM BOOKING:**
69+
- Tell them: "Perfect! I've scheduled your appointment for [Date/Time]. You'll receive a confirmation."
70+
71+
**CRITICAL RULES:**
72+
73+
❌ **DO NOT** book appointments without collecting name, email AND phone number first
74+
❌ **DO NOT** book appointments without asking the user what time they want
75+
❌ **DO NOT** create appointments with empty description fields
76+
✅ **ALWAYS** put customer name, phone, email and reason in the description field
77+
✅ **ALWAYS** ask for preferred time before checking availability
78+
✅ **ALWAYS** confirm all details before finalizing
79+
80+
**No Hallucinations:** If you are unsure of a policy or availability, offer to have a human staff member follow up.
81+
82+
"""
83+
84+
85+
agent = Agent(
86+
agent_name="Agent-System",
87+
llm=llm,
88+
tts=tts,
89+
stt=stt,
90+
send_greeting=True,
91+
greeting_instructions="Introduce yourself in a friendly way",
92+
system_instructions=prompt,
93+
google_calendar=True,
94+
remember_call=True
95+
)
96+
97+
if __name__ == "__main__":
98+
99+
100+
# One-time setup: downloads required files (only needed on fresh machines)
101+
#agent.download_files()
102+
103+
# For local development (logs, quick iteration)
104+
agent.dev()
105+
106+
# For production workers, use:
107+
# agent.start()

call.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import asyncio
2+
from siphon.telephony.outbound import Call
3+
from siphon.plugins import sarvam
4+
from dotenv import load_dotenv
5+
6+
load_dotenv()
7+
8+
stt = sarvam.STT()
9+
10+
call = Call(
11+
agent_name="Agent-System", # must match the agent_name used when defining/starting your SIPHON agent worker
12+
sip_trunk_setup={
13+
"name": "Telephony-Agent-test",
14+
"sip_address": "siphon-testing7613.pstn.twilio.com",
15+
"sip_number": "+18703377189",
16+
"sip_username": "elt",
17+
"sip_password": "Password@123"
18+
},
19+
number_to_call="+917795341235" #"+919686110436" #"+917795341235"
20+
)
21+
22+
result = call.start()
23+
print(result)

siphon/agent/core/entrypoint.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ async def entrypoint(
313313
else:
314314
logger.info(f"No previous call memory found for {phone_number}")
315315

316+
# Inject calendar operation guidelines if Google Calendar integration is enabled
317+
if google_calendar:
318+
from siphon.agent.internal_prompts import calendar_guidelines_prompt
319+
enhanced_instructions = enhanced_instructions + "\n\n" + calendar_guidelines_prompt
320+
logger.info("Injected calendar operation guidelines into system instructions")
321+
316322
agent_setup = agent_cls(
317323
config=metadata,
318324
send_greeting=send_greeting,

siphon/agent/core/voice_agent.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,33 @@ def __init__(self,
5050
self.send_greeting = send_greeting
5151
self.greeting_instructions = greeting_instructions
5252

53+
# Extract and preserve all prompt components
54+
# The system_instructions may contain: base + calendar_guidelines + memory_context
5355
memory_context = ""
56+
calendar_context = ""
5457
base_instructions = system_instructions
5558

56-
if "Previous Conversations" in system_instructions:
59+
# Extract memory context if present (added by MemoryService.enhance_instructions)
60+
if "## INTERNAL RULES - MEMORY-AWARE CONVERSATION" in system_instructions:
5761
parts = system_instructions.split("---\n## INTERNAL RULES - MEMORY-AWARE CONVERSATION")
5862
if len(parts) >= 2:
5963
base_instructions = parts[0].strip()
6064
memory_context = "---\n## INTERNAL RULES - MEMORY-AWARE CONVERSATION" + parts[1]
6165

66+
# Extract calendar guidelines if present (added by entrypoint when google_calendar=True)
67+
if "## INTERNAL RULES - CALENDAR OPERATIONS" in base_instructions:
68+
parts = base_instructions.split("---\n## INTERNAL RULES - CALENDAR OPERATIONS")
69+
if len(parts) >= 2:
70+
base_instructions = parts[0].strip()
71+
calendar_context = "---\n## INTERNAL RULES - CALENDAR OPERATIONS" + parts[1]
72+
73+
# Reconstruct in correct order: base + internal rules + calendar + memory
6274
self.system_instructions = (
6375
base_instructions +
6476
"\n\n" + call_agent_prompt +
6577
"\n\n" + proactive_agent_prompt +
6678
"\n\n" + datetime_awareness_prompt +
79+
("\n\n" + calendar_context if calendar_context else "") +
6780
("\n\n" + memory_context if memory_context else "")
6881
)
6982

siphon/agent/internal_prompts/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
from .proactive_behavior import proactive_agent_prompt
33
from .datetime_awareness import datetime_awareness_prompt
44
from .memory_aware import memory_aware_prompt
5+
from .calendar_guidelines import calendar_guidelines_prompt
56

6-
__all__ = ["call_agent_prompt", "proactive_agent_prompt", "datetime_awareness_prompt", "memory_aware_prompt"]
7+
__all__ = ["call_agent_prompt", "proactive_agent_prompt", "datetime_awareness_prompt", "memory_aware_prompt", "calendar_guidelines_prompt"]

0 commit comments

Comments
 (0)