Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

docs: fix documentation and update SDK for cc (#5689)

Sarah Wooders2270d2f05008
diff --git a/fern/openapi-overrides.yml b/fern/openapi-overrides.yml
index ba32c53a1..e57972091 100644
--- a/fern/openapi-overrides.yml
+++ b/fern/openapi-overrides.yml
@@ -1124,6 +1124,12 @@ paths:
- batches
- messages
x-fern-sdk-method-name: list
+ /v1/chat/completions:
+ post:
+ x-fern-sdk-group-name:
+ - chat
+ - completions
+ x-fern-sdk-method-name: create
/v1/embeddings/total_storage_size:
get:
x-fern-ignore: true
diff --git a/fern/pages/voice/voice.mdx b/fern/pages/voice/voice.mdx
new file mode 100644
index 000000000..b936fb2f1
--- /dev/null
+++ b/fern/pages/voice/voice.mdx
@@ -0,0 +1,35 @@
+---
+title: Voice Agents
+slug: guides/voice/overview
+---
+
+<Warning>
+Voice agents support is experimental and may be unstable. For more information, visit our [Discord](https://discord.gg/letta).
+</Warning>
+
+All Letta agents can be connected to a voice provider by using the OpenAI-compatible streaming chat completions endpoint at `http://localhost:8283/v1/chat/completions`. Any standard Letta agent can be used for voice applications.
+
+<Note>
+The legacy `/v1/voice-beta/<AGENT_ID>` endpoint has been deprecated. Please use the OpenAI-compatible `/v1/chat/completions` endpoint with `stream=true` for voice applications.
+</Note>
+
+## Creating a voice agent
+You can create a voice agent using the standard Letta agent creation flow:
+
+```python
+from letta_client import Letta
+
+client = Letta(token=os.getenv('LETTA_API_KEY'))
+
+# create the Letta agent
+agent = client.agents.create(
+ memory_blocks=[
+ {"value": "Name: ?", "label": "human"},
+ {"value": "You are a helpful assistant.", "label": "persona"},
+ ],
+ model="openai/gpt-4o-mini", # Use 4o-mini for speed
+ embedding="openai/text-embedding-3-small",
+)
+```
+
+You can attach additional tools and blocks to this agent just as you would any other Letta agent.
diff --git a/fern/pages/voice/voice_livekit.mdx b/fern/pages/voice/voice_livekit.mdx
new file mode 100644
index 000000000..80641123e
--- /dev/null
+++ b/fern/pages/voice/voice_livekit.mdx
@@ -0,0 +1,118 @@
+---
+title: Connecting with Livekit Agents
+slug: guides/voice/livekit
+---
+
+<Warning>
+Voice agents support is experimental and may be unstable. For more information, visit our [Discord](https://discord.gg/letta).
+</Warning>
+
+You can build an end-to-end stateful voice agent using Letta and Livekit. You can see a full example in the [letta-voice](https://github.com/letta-ai/letta-voice) repository.
+
+For this example, you will need accounts with the following providers:
+* [Livekit](https://livekit.io/) for handling the voice connection
+* [Deepgram](https://deepgram.com/) for speech-to-text
+* [Cartesia](https://cartesia.io/) for text-to-speech
+
+You will also need to set up the following environment variables (or create a `.env` file):
+```sh
+LETTA_API_KEY=... # Letta Cloud API key (if using cloud)
+
+LIVEKIT_URL=wss://<YOUR-ROOM>.livekit.cloud # Livekit URL
+LIVEKIT_API_KEY=... # Livekit API key
+LIVEKIT_API_SECRET=... # Livekit API secret
+
+DEEPGRAM_API_KEY=... # Deepgram API key
+CARTESIA_API_KEY=... # Cartesia API key
+```
+
+## 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. The connector uses Letta's OpenAI-compatible streaming chat completions endpoint (`/v1/chat/completions`) under the hood.
+
+Below is an example defining an entrypoint for a Livekit agent with Letta:
+```python
+import os
+from dotenv import load_dotenv
+from livekit import agents
+from livekit.agents import AgentSession, Agent, AutoSubscribe
+from livekit.plugins import (
+ openai,
+ cartesia,
+ deepgram,
+)
+load_dotenv()
+
+async def entrypoint(ctx: agents.JobContext):
+ agent_id = os.environ.get('LETTA_AGENT_ID')
+ print(f"Agent id: {agent_id}")
+ session = AgentSession(
+ llm=openai.LLM.with_letta(
+ agent_id=agent_id,
+ ),
+ stt=deepgram.STT(),
+ tts=cartesia.TTS(),
+ )
+
+ await session.start(
+ room=ctx.room,
+ agent=Agent(instructions=""), # instructions should be set in the Letta agent
+ )
+
+ session.say("Hi, what's your name?")
+ await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
+```
+You can see the full script [here](https://github.com/letta-ai/letta-voice/blob/main/main.py).
+
+## 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:
+1. Create an account on [ngrok](https://ngrok.com/)
+2. Create an auth token and add it into your CLI
+```
+ngrok config add-authtoken <YOUR_AUTH_TOKEN>
+```
+3. Point your ngrok server to your Letta server:
+```
+ngrok http http://localhost:8283
+```
+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).
+
+```python
+import os
+from dotenv import load_dotenv
+from livekit import agents
+from livekit.agents import AgentSession, Agent, AutoSubscribe
+from livekit.plugins import (
+ openai,
+ cartesia,
+ deepgram,
+)
+load_dotenv()
+
+async def entrypoint(ctx: agents.JobContext):
+ agent_id = os.environ.get('LETTA_AGENT_ID')
+ print(f"Agent id: {agent_id}")
+ session = AgentSession(
+ llm=openai.LLM.with_letta(
+ agent_id=agent_id,
+ base_url="https://<YOUR_FORWARDING_URL>.ngrok.app", # point to your Letta server
+ ),
+ stt=deepgram.STT(),
+ tts=cartesia.TTS(),
+ )
+
+ await session.start(
+ room=ctx.room,
+ agent=Agent(instructions=""), # instructions should be set in the Letta agent
+ )
+
+ session.say("Hi, what's your name?")
+ await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
+```
+You can see the full script [here](https://github.com/letta-ai/letta-voice/blob/main/main.py).
+`
diff --git a/fern/pages/voice/voice_vapi.mdx b/fern/pages/voice/voice_vapi.mdx
new file mode 100644
index 000000000..6a635d575
--- /dev/null
+++ b/fern/pages/voice/voice_vapi.mdx
@@ -0,0 +1,66 @@
+---
+title: Connecting with Vapi
+slug: guides/voice/vapi
+---
+
+<Warning>
+Voice agents support is experimental and may be unstable. For more information, visit our [Discord](https://discord.gg/letta).
+</Warning>
+
+## Connecting to Letta Cloud
+<Steps>
+ <Step title="Add your `LETTA_API_KEY`">
+ Add Letta Cloud as an integration by entering your `LETTA_API_KEY` into the "Custom LLM" field at https://dashboard.vapi.ai/settings/integrations.
+ <img src="../../images/vapi_custom_model.png" />
+ </Step>
+ <Step title="Create an assistant">
+ Create a Vapi assistant at https://dashboard.vapi.ai/assistants/ and use the "Blank Template".
+ <img src="../../images/vapi_create_assistant.png" />
+ </Step>
+ <Step title="Connect your Letta agent">
+ Select "Custom LLM" for the model, and enter in the chat completions endpoint: https://api.letta.com/v1/chat/completions
+
+ In the request body, set the "model" field to your agent ID in the format `agent-{AGENT-ID}`.
+
+ <img src="../../images/vapi_model_letta.png" />
+
+ <Note>The legacy `/v1/voice-beta/{AGENT-ID}` endpoint has been deprecated. Use `/v1/chat/completions` with the agent ID specified in the "model" field instead.</Note>
+ </Step>
+ <Step title="Talk to your agent">
+ You can now interact with your agent through Vapi, including calling and texting your agent!
+ </Step>
+
+</Steps>
+
+## Connecting to a self-hosted Letta server
+To connect to a self-hosted server, you will need to have a internal accessible endpoint for your Letta server and add any authentication tokens (if they exist) instead of `LETTA_API_KEY`. We recommend using ngrok to expose your Letta server to the internet.
+
+<Steps>
+<Step title="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:
+1. Create an account on [ngrok](https://ngrok.com/)
+2. Create an auth token and add it into your CLI
+```
+ngrok config add-authtoken <YOUR_AUTH_TOKEN>
+```
+3. Point your ngrok server to your Letta server:
+```
+ngrok http http://localhost:8283
+```
+Now, you should have a forwarding URL like `https://{YOUR_FORWARDING_URL}.ngrok.app`.
+</Step>
+ <Step title="Create an assistant">
+ Create a Vapi assistant at https://dashboard.vapi.ai/assistants/ and use the "Blank Template".
+ <img src="../../images/vapi_create_assistant.png" />
+ </Step>
+ <Step title="Connect your Letta agent">
+ Select "Custom LLM" for the model, and enter in the chat completions endpoint: `https://{YOUR_FORWARDING_URL}.ngrok.app/v1/chat/completions`
+
+ In the request body, set the "model" field to your agent ID in the format `agent-{AGENT_ID}`.
+
+ <Note>The legacy `/v1/voice-beta/{AGENT_ID}` endpoint has been deprecated. Use `/v1/chat/completions` with the agent ID specified in the "model" field instead.</Note>
+ </Step>
+ <Step title="Talk to your agent">
+ You can now interact with your agent through Vapi, including calling and texting your agent!
+ </Step>
+</Steps>