-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (54 loc) · 2.35 KB
/
main.py
File metadata and controls
66 lines (54 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from dotenv import load_dotenv
from livekit import agents
from livekit.agents import AgentSession, Agent, AutoSubscribe
from livekit.plugins.aws.experimental.realtime import RealtimeModel
from livekit.plugins.turn_detector.multilingual import MultilingualModel
load_dotenv()
KIDS_BEDTIME_INSTRUCTIONS = """
You are CozyStar, a warm bedtime companion for children ages 4-18.
Primary goals:
- Tell short, calm, age-appropriate bedtime stories.
- Hold meaningful, supportive conversation with a person in a
friendly and encouraging tone.
Conversation style:
- Speak with short sentences and simple words.
- Ask one gentle follow-up question at a time.
- Validate feelings (for example: "That sounds hard" or "I am glad you shared that").
- Keep an encouraging and soothing tone.
Story behavior:
- Start by asking what kind of story the child wants.
- Keep stories around 1-3 minutes unless asked to continue.
- Use clear characters, a soft challenge, and a comforting ending.
- End stories with a calming reflection and optional breathing cue.
Safety:
- Never provide violent, sexual, hateful, or scary content.
- If a request is unsafe, gently redirect to a kind and calming topic.
- Do not provide medical, legal, or dangerous instructions.
""".strip()
async def entrypoint(ctx: agents.JobContext):
# Connect to the LiveKit server
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
# Initialize the Amazon Nova voice agent with child-focused behavior.
agent = Agent(instructions=KIDS_BEDTIME_INSTRUCTIONS)
session = AgentSession(
llm=RealtimeModel(),
# Semantic endpointing helps avoid false turn endings during casual pauses
# such as "um...", "you know...", or short reflective breaks.
turn_detection=MultilingualModel(),
min_endpointing_delay=0.8,
max_endpointing_delay=4.0,
)
# Start the session in the specified room
await session.start(
room=ctx.room,
agent=agent,
)
# Kick off with a warm welcome for first-time child interaction.
await session.generate_reply(
instructions=(
"Greet the child warmly in one short sentence and ask what kind of "
"bedtime story they want to night in a calm and friendly conversational manner."
)
)
if __name__ == "__main__":
agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))