import os
from dotenv import load_dotenv
from livekit import agents
from livekit.agents import AgentSession, Agent, RoomInputOptions
from livekit.plugins import (
openai,
cartesia,
deepgram,
silero,
)
load_dotenv()
class TrueFoundryAssistant(Agent):
def __init__(self) -> None:
super().__init__(
instructions="You are a helpful AI assistant powered by TrueFoundry. "
"You can help with questions, provide information, and have natural conversations. "
"Keep your responses conversational and helpful."
)
async def entrypoint(ctx: agents.JobContext):
# Create session with TrueFoundry Gateway integration
session = AgentSession(
stt=deepgram.STT(
model="nova-2",
language="en"
),
llm=openai.LLM(
model=os.getenv("TRUEFOUNDRY_MODEL_ID", "openai-main/gpt-4o"),
api_key=os.getenv("OPENAI_API_KEY"), # Your TrueFoundry API Key
base_url=os.getenv("TRUEFOUNDRY_BASE_URL"), # Your TrueFoundry Gateway URL
temperature=0.7,
),
tts=cartesia.TTS(
model="sonic-english",
voice="79a125e8-cd45-4c13-8a67-188112f4dd22" # Pleasant voice
),
vad=silero.VAD.load(
min_speaking_duration=0.3,
min_silence_duration=0.8,
),
)
await ctx.connect()
# Start the session with the assistant
await session.start(
room=ctx.room,
agent=TrueFoundryAssistant(),
)
# Send initial greeting
await session.generate_reply(
instructions="Welcome the user warmly and let them know you're powered by TrueFoundry. "
"Ask how you can help them today."
)
if __name__ == "__main__":
agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))