<@U084APK40NS> I want to change the used LLM for t...
# ask-ai
d
@millions-hair-24956 I want to change the used LLM for the voiceagentpiple after a function from functioncontext. I used agent.llm = llm_configuration but there is the error AttributeError property 'llm' of 'VoicePipelineAgent' object has no setter how can i handle this ?
g
To change the LLM used by a
VoicePipelineAgent
, you cannot directly set the
llm
property because it does not have a setter. Instead, you can modify the LLM instance by using the
before_llm_cb
callback to dynamically adjust the LLM configuration before each call. This allows you to inject a new LLM instance or modify the existing one as needed. Here's a basic example of how you might implement this:
Copy code
from livekit.agents import VoicePipelineAgent, llm

async def before_llm_cb(agent: VoicePipelineAgent, chat_ctx: llm.ChatContext):
    # Create a new LLM instance or modify the existing one
    new_llm = llm.LLM()  # Replace with your LLM configuration
    agent._llm = new_llm  # Directly modify the internal attribute

agent = VoicePipelineAgent(
    vad=your_vad_instance,
    stt=your_stt_instance,
    llm=initial_llm_instance,
    tts=your_tts_instance,
    before_llm_cb=before_llm_cb
)
Would you like more details on this approach? Sources: - https://livekit-users.slack.com/archives/C07FY8WHGPM/p1729785664.481519 - https://docs.livekit.io/agents-js/classes/agents.pipeline.VoicePipelineAgent.html 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.