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

Code before:
            api_key = prompt_api_key(
                step_counter,
                custom_model.split('/')[0] if len(custom_model.split('/')) > 1 else '',
                self.conversation.state.agent.llm.api_key if self.conversation else None,
                escapable=escapable,
            )
            memory_condensation = choose_memory_condensation(step_counter)

            # 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',
        )

        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:

Review comment (refactor):
🤔  @malhotra5 Did we need this for something in particular? We renamed it and made it a little more of a litellm auxiliary logging helper : `litellm_extra_body`. It was (and is) sent to litellm as extra_body if the litellm proxy is used, and nothing else, I think.

Please see https://github.com/OpenHands/software-agent-sdk/pull/837


Code after:
            api_key = prompt_api_key(
                step_counter,
                custom_model.split('/')[0] if len(custom_model.split('/')) > 1 else '',
                self.conversation.state.agent.llm.api_key if self.conversation else None,
                escapable=escapable,
            )
            memory_condensation = choose_memory_condensation(step_counter)

            # 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',
            litellm_extra_body={"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