is it possible to send the initial prompt before t...
# ask-ai
b
is it possible to send the initial prompt before the first request is sent
t
Thanks for reaching out, timothe. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely, you can send an initial prompt before the very first request in LiveKit! How you do this depends a bit on the type of agent and model you're working with: • Sarvam STT Models: You’ll want to use the
prompt
parameter during initialization. This gets sent as part of the initial configuration message over the WebSocket connection. • AWS Bedrock's Sonic Realtime Model: Here, you can use the
system_content
parameter in the
create_prompt_start_block
method to set the system prompt right at the start of your session. • VoicePipelineAgent: A great approach is to append to the
llm.ChatContext()
to set an initial conversation context. Plus, you can use
session.say()
if you want the agent to speak a predefined message or
generate_reply()
if you’d like more control over the response. These options give you the flexibility to guide your agent’s behavior and set the context right from the beginning, making your sessions smoother and more tailored to your needs. Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | delay-handling/agent.py | Agent speech and audio | LiveKit docs
b
using openai ?
t
When you're using OpenAI in LiveKit, you can start by sending an initial prompt before the very first request like this: • For Speech-to-Text (STT): You’ll want to use the
prompt
parameter in the
openai.STT
class. Here’s a quick example:
Copy code
from livekit.plugins import openai

stt = openai.STT(
    model="whisper-1",
    prompt="Transcribe technical terms accurately, such as 'API', 'LLM', and 'real-time'.",
    language="en",
    detect_language=False,
)
This helps guide the transcription right from the start. • For Large Language Models (LLM): You can use
llm.ChatContext
to add a system message, or the
instructions
parameter if you’re working with Azure OpenAI. For example:
Copy code
from livekit.agents import llm

initial_ctx = llm.ChatContext().append(
    role="system",
    text="You are a voice assistant created by LiveKit. Keep responses short and concise, suitable for voice playback.",
)

agent = VoicePipelineAgent(
    llm=openai.LLM(),
    chat_ctx=initial_ctx,
)
These approaches gently set the stage for the AI, making sure it understands the context before handling the very first user request. If you have any questions or want me to walk you through it further, just let me know—I’m here to help! Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/llm.py | meditation_assistant/README.mdoc | Azure OpenAI Realtime API and LiveKit | LiveKit Docs
b
but what about the instructions in th Agent?
t
I'm glad you're exploring how to set initial instructions in an Agent using OpenAI in LiveKit! You can easily do this by using the
instructions
parameter when creating your agent. Think of this as the system prompt that gently guides your agent's behavior. Here's a simple example to get you started:
Copy code
const agent = new voice.Agent({
  instructions: 'You are a helpful assistant. Speak clearly and concisely.',
});
These instructions help define your agent’s personality and how it interacts during conversations. What’s even better is that you can update these instructions on the fly during a session with the
updateInstructions
method. Here’s a little snippet to illustrate that:
Copy code
class ChangeInstructionsAgent(Agent):
    def __init__(self):
        super().__init__(
            instructions="You are a helpful agent. When the user speaks, you listen and respond.",
        )

    async def on_enter(self):
        if self.session.participant.name.startswith("sip"):
            self.update_instructions("You are a helpful agent speaking on the phone.")
        self.session.generate_reply()
This flexibility lets your agent adapt its behavior based on who it's talking to or what's happening in the session. If you'd like, I’m here to walk you through more examples or answer any questions you might have—just let me know! Sources: plugins/openai/src/realtime/realtime_model.ts | docs/index.yaml | examples/voice_agents/raw_function_description.py | agent/main.py | src/agent.ts
b
bu does the instruction in the agent () send the prompt before frst request?
t
Absolutely! The
instructions
parameter in the agent does send the prompt right before the very first request. It’s included as part of a
session.update
event during the session initialization, which means the instructions are taken into account before any user interaction begins. This works the same way across OpenAI, Azure OpenAI, and other supported realtime models in LiveKit. Think of the instructions as a helpful guide that sets the tone for the agent’s behavior right from the start of your session. Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/llm.py | plugins/openai/src/realtime/realtime_model.ts | Azure OpenAI Realtime API and LiveKit | LiveKit Docs | OpenAI TTS plugin guide | LiveKit Docs | Agent speech and audio | LiveKit docs
b
are you sure it seems like it sends it a the first request
t
The
instructions
parameter is there to help set the system prompt right at the start of your session. So, it’s sent either just before or at the very beginning of your first request, making sure those instructions are included in the initial context for the agent’s responses. If you’re noticing something different or unexpected, please don’t hesitate to let me know. I’m here to help you troubleshoot or clarify any details to make sure everything works smoothly for you. Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | Azure OpenAI Realtime API and LiveKit | LiveKit Docs