Repository: All-Hands-AI/OpenHands
File: openhands-cli/openhands_cli/tui/settings/settings_screen.py (Python)

Code before:

            # Confirm save
            save_settings_confirmation()
        except KeyboardInterrupt:
            print_formatted_text(HTML('\n<red>Cancelled settings change.</red>'))
            return

        # Store the collected settings for persistence
        self._save_advanced_settings(
            custom_model, base_url, api_key, memory_condensation
        )

    def _save_llm_settings(self, model, api_key, base_url: str | None = None) -> None:
        llm = LLM(
            model=model,
            api_key=api_key,
            base_url=base_url,
            usage_id='agent',
            metadata=get_llm_metadata(model_name=model, llm_type='agent'),
        )

        agent = self.agent_store.load()
        if not agent:
            agent = get_default_cli_agent(llm=llm)

        agent = agent.model_copy(update={'llm': llm})
        self.agent_store.save(agent)

    def _save_advanced_settings(
        self, custom_model: str, base_url: str, api_key: str, memory_condensation: bool
    ):
        self._save_llm_settings(custom_model, api_key, base_url=base_url)

        agent_spec = self.agent_store.load()
        if not agent_spec:
            return

        if not memory_condensation:
            agent_spec.model_copy(update={'condenser': None})

        self.agent_store.save(agent_spec)


Review comment (suggestion):
I think maybe this is the other way around... no, actually the user saves here "global" settings, so I tend to agree it should apply by default to all other LLMs 🤔 

I think sooner or later, we'll have the request to update them separately (we had it on V0). Not in scope here, I think maybe [LLM profiles](https://github.com/OpenHands/software-agent-sdk/pull/795) will give us a way to handle them separately...

Code after:

            # Confirm save
            save_settings_confirmation()
        except KeyboardInterrupt:
            print_formatted_text(HTML('\n<red>Cancelled settings change.</red>'))
            return

        # Store the collected settings for persistence
        self._save_advanced_settings(
            custom_model, base_url, api_key, memory_condensation
        )

    def _save_llm_settings(self, model, api_key, base_url: str | None = None) -> None:
        llm = LLM(
            model=model,
            api_key=api_key,
            base_url=base_url,
            usage_id='agent',
            metadata=get_llm_metadata(model_name=model, llm_type='agent'),
        )

        agent = self.agent_store.load()
        if not agent:
            agent = get_default_cli_agent(llm=llm)

        # Must update all LLMs
        agent = agent.model_copy(update={'llm': llm})
        condenser = LLMSummarizingCondenser(
            llm=llm.model_copy(
                update={"usage_id": "condenser"}
            )
        )
        agent = agent.model_copy(update={'condenser': condenser})
        self.agent_store.save(agent)

    def _save_advanced_settings(
        self, custom_model: str, base_url: str, api_key: str, memory_condensation: bool
    ):
        self._save_llm_settings(custom_model, api_key, base_url=base_url)

        agent_spec = self.agent_store.load()
        if not agent_spec:
            return

        if not memory_condensation:
            agent_spec.model_copy(update={'condenser': None})

        self.agent_store.save(agent_spec)