Skip to content

Support switching LLM models in the middle of conversation #416

Description

@xingyaoww

Maybe we can re-use some pattern in LLM Router to support this #152

We can probably add a new method "/conversation/update_llm" endpoint to the server.

One way we could implement this

Similar to this example

https://github.com/All-Hands-AI/agent-sdk/blob/a5f7e71269b32fd36b9ad7d3843d281288b24f7b/examples/10_persistence.py#L83-L92

agent = Agent(llm=llm, tools=tools)
conversation = Conversation(
    agent=agent,
    callbacks=[conversation_callback],
    persist_filestore=file_store,
    conversation_id=conversation_id,
)
# we do stuff ...
del conversation

# <--- HERE WE DECIDE TO SWITCH
agent2 = Agent(llm=llm2, tools=tools)
conversation = Conversation(
    agent=agent,
    callbacks=[conversation_callback],
    persist_filestore=file_store,
    conversation_id=conversation_id,
)

This will currently throw an error due to resolve_diff_from_deserialized:

https://github.com/All-Hands-AI/agent-sdk/blob/a5f7e71269b32fd36b9ad7d3843d281288b24f7b/openhands/sdk/llm/llm.py#L841-L875

We can implement resolve_diff_from_deserialized differently in LLMRouter -- it should allow us to set a different LLM on the fly:

  1. We start a conversation with LLMRouter with ONE model instead of LLM
  2. User sets new LLM config
  3. LLMRouter save the LLMConfig, set it to the current LLM service (LLMRouter should be the serializable class that contains all information about the history of LLM switch actions)

Activity

  1. jpelletier1 commented on Nov 12, 2025

    @jpelletier1
    Contributor

    @xingyaoww Is this already implemented in V1, such that once we have the GUI using V1, we should be able to support switching models mid-conversation?

    We currently have designs for this so wanted to check on whether there's additional Agent SDK features that are needed.

  2. enyst commented on Nov 12, 2025

    @enyst
    Member

    @jpelletier1 Not yet. Switching models mid-conversation is currently blocked, because I have concerns about one way of doing it, and I need to finalize and propose another way of doing it. Sorry. I’ll open that discussion by tonight!

    What designs are we talking about?

  3. jpelletier1 commented on Nov 13, 2025

    @jpelletier1
    Contributor

    @enyst Thanks for the update.

    The designs are fairly minimal at this stage, but were included with the Planning Agent design. In this design screenshot, there is a small dropdown in the Input Textarea (labeled GPT5) where a user can switch models within the context of a conversation: OpenHands/OpenHands#8964 (comment)

  4. deleted a comment from all-hands-bot on Jan 1, 2026
  5. all-hands-bot commented on Feb 11, 2026

    @all-hands-bot
    Collaborator

    This issue is stale because it has been open for 40 days with no activity. Remove the stale label or leave a comment, otherwise it will be closed in 10 days.

  6. VascoSch92 commented on Feb 12, 2026

    @VascoSch92
    Member

    This is related to #2018.

    Question: Do we want to switch LLM or Agent?

    They are two totally different problems :-) and from the first example in the issue it seems that we want to switch LLM but than in the example we have two different agents.

  7. added
    behavior-initiative
    and removed
    behavior-initiative
    on Feb 14, 2026
  8. maveilo commented on Mar 21, 2026

    @maveilo

    Great question @VascoSch92!

    For LLM switching specifically (not agent), ClawRouter handles this at the request level:

    * Each API call gets routed to the optimal model based on prompt complexity
    
    * No agent-level changes needed - just swap the endpoint
    
    * Works transparently with any agent framework
    

    The distinction matters because:

    * **Agent switching** = changing behavior/tools/prompts mid-conversation
    
    * **LLM switching** = same agent, different backend model per request
    

    ClawRouter focuses purely on the LLM layer - it's invisible to your agent logic.

    https://github.com/BlockRunAI/ClawRouter

    llama.cpp provides an alternative way for local LLMs - just a single REST request to load the model to start chatting with it (sending a REST request with different model name switches it):

    curl http://localhost:8080/v1/chat/completions \
      -H "Content-Type: application/json" \
      -d '{
        "model": "ggml-org/gemma-3-4b-it-GGUF:Q4_K_M",
        "messages": [{"role": "user", "content": "Hello!"}]
      }'
    
  9. VascoSch92 commented on Apr 6, 2026

    @VascoSch92
    Member

    I think this issue can be closed because of: #2192

    We could open another issue to port the switching logic in the agent-server if needed.

    @xingyaoww WDYT?

  10. enyst commented on Apr 6, 2026

    @enyst
    Member

    I think we do need it in the agent-server. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions