Spaces:
Build error
Build error
Commit
·
c61d9e2
1
Parent(s):
68a0b31
Realtime Flow
Browse files- src/agent_session/main.py +39 -34
src/agent_session/main.py
CHANGED
|
@@ -87,40 +87,45 @@ async def run_agent_session(room_name: str, agent_token: str):
|
|
| 87 |
await room.connect(livekit_url, agent_token)
|
| 88 |
print("DEBUG: 2. Connection successful.")
|
| 89 |
|
| 90 |
-
#
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
stt=stt,
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
except Exception as e:
|
| 126 |
print(f"FATAL ERROR in agent session: {e}")
|
|
|
|
| 87 |
await room.connect(livekit_url, agent_token)
|
| 88 |
print("DEBUG: 2. Connection successful.")
|
| 89 |
|
| 90 |
+
# Create HTTP session for TTS
|
| 91 |
+
async with aiohttp.ClientSession() as session:
|
| 92 |
+
# 1. Instantiate all plugins
|
| 93 |
+
vad = VAD.load(min_speech_duration=0.1, min_silence_duration=0.5)
|
| 94 |
+
tts = TTS(
|
| 95 |
+
voice=VoiceByName(
|
| 96 |
+
name="Tiktok Fashion Influencer",
|
| 97 |
+
provider=VoiceProvider.hume
|
| 98 |
+
),
|
| 99 |
+
instant_mode=True,
|
| 100 |
+
http_session=session, # Pass the session here
|
| 101 |
+
)
|
| 102 |
+
stt = StreamAdapter(stt=STT(model="whisper-large-v3-turbo"), vad=vad)
|
| 103 |
+
google_llm = GoogleLLM(model="gemini-2.5-flash")
|
| 104 |
+
llm_wrapper = LLMStateWrapper(llm=google_llm, room=room)
|
| 105 |
+
|
| 106 |
+
# 2. Create the AgentSession
|
| 107 |
+
session_agent = AgentSession(
|
| 108 |
+
stt=stt,
|
| 109 |
+
llm=llm_wrapper,
|
| 110 |
+
tts=tts,
|
| 111 |
+
vad=vad,
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
# 3. Create an instance of your agent
|
| 115 |
+
agent = VoiceAssistant()
|
| 116 |
+
|
| 117 |
+
# 4. Start the session
|
| 118 |
+
print("DEBUG: Starting AgentSession...")
|
| 119 |
+
task = asyncio.create_task(session_agent.start(agent=agent, room=room))
|
| 120 |
+
|
| 121 |
+
# 5. Generate the initial greeting
|
| 122 |
+
print("DEBUG: Generating initial greeting...")
|
| 123 |
+
await send_agent_state(room, "speaking")
|
| 124 |
+
await session_agent.generate_reply(instructions="hello")
|
| 125 |
+
print("DEBUG: Initial greeting complete. Agent is now fully operational.")
|
| 126 |
+
|
| 127 |
+
# Await the main session task
|
| 128 |
+
await task
|
| 129 |
|
| 130 |
except Exception as e:
|
| 131 |
print(f"FATAL ERROR in agent session: {e}")
|