Connecting with Livekit Agents
You can build an end-to-end stateful voice agent using Letta and Livekit. You can see a full example in the letta-voice repository.
For this example, you will need accounts with the following providers:
You will also need to set up the following environment variables (or create a .env
file):
Connecting to Letta Cloud
To connect to LiveKit, you can use the Letta connector openai.LLM.with_letta
and pass in the agent_id
of your voice agent.
Below is an example defining an entrypoint for a Livekit agent with Letta:
You can see the full script here.
Connecting to a self-hosted Letta server
You can also connect to a self-hosted server by specifying a base_url
. To use LiveKit, your Letta sever needs to run with HTTPs. The easiest way to do this is by connecting ngrok to your Letta server.
Setting up ngrok
If you are self-hosting the Letta server locally (at localhost
), you will need to use ngrok
to expose your Letta server to the internet:
- Create an account on ngrok
- Create an auth token and add it into your CLI
- Point your ngrok server to your Letta server:
Now, you should have a forwarding URL like https://<YOUR_FORWARDING_URL>.ngrok.app
.
Connecting LiveKit to a self-hosted Letta server
To connect a LiveKit agent to a self-hosted Letta server, you can use the same code as above, but with the base_url
parameter set to the forwarding URL you got from ngrok (or whatever HTTPS URL the Letta server is running on).
You can see the full script here. `