This message was deleted.
# ask-ai
s
This message was deleted.
t
Thanks for reaching out, Scott. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! Just to make sure I understand correctly, are you hoping to fully remove the data from the Instructions field, or would you rather find a way to compress it so some of the history stays intact? Also, are you using any particular tools or setups that might affect how this data is handled? I’m here to help!
p
i want to use the generateReply, but everytime i dont, it adds its to the session, and that context keeps growing and growing everytime, which is not good.
t
To keep the Instructions field from growing too much and to avoid any performance hiccups, here are some handy tips you can try out: • Use the
before_llm_cb
Callback:
This lets you trim down the chat context before sending it to the LLM. For instance, you might want to keep just the last 15 messages to save on tokens:
Copy code
async def truncate_context(assistant: VoicePipelineAgent, chat_ctx: llm.ChatContext):
    if len(chat_ctx.messages) > 15:
        chat_ctx.messages = chat_ctx.messages[-15:]
• Manage Instructions Explicitly: When you use
generateReply
, the
instructions
parameter is great for temporary instructions that don’t get saved in the chat history. Try not to add to instructions unnecessarily to keep things lean. • Update Instructions Only When Needed: Use
update_instructions()
to change agent instructions during runtime, but make sure you replace old instructions instead of piling them up. • Leverage Automatic Context Truncation: Some models automatically cut down the context once it goes beyond a certain number of messages, like 40. You can also add similar trimming in your app. • Avoid Redundant Context Updates: Use
user_input
for ongoing conversation bits and keep
instructions
for one-off directions to avoid repeating yourself. Following these tips will help you keep token use efficient and boost performance during longer sessions. If you want to chat more about this or need a hand, just let me know! Sources: plugins/google/src/beta/realtime/realtime_api.ts | Agent speech and audio | LiveKit Docs | VoicePipelineAgent | LiveKit Docs | VoicePipelineAgent | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_session.py