Skip to content

Commit

Permalink
Enable memory condensation from the frontend (All-Hands-AI#6333)
Browse files Browse the repository at this point in the history
Co-authored-by: Calvin Smith <[email protected]>
  • Loading branch information
2 people authored and Kevin Chen committed Feb 4, 2025
1 parent 4cdac77 commit f81e01a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ModelSelector } from "./model-selector";
import { RuntimeSizeSelector } from "./runtime-size-selector";
import { useConfig } from "#/hooks/query/use-config";
import { useCurrentSettings } from "#/context/settings-context";
import { MEMORY_CONDENSER } from "#/utils/feature-flags";

interface SettingsFormProps {
disabled?: boolean;
Expand Down Expand Up @@ -64,12 +65,14 @@ export function SettingsForm({
const isUsingConfirmationMode = !!settings.CONFIRMATION_MODE;
const isUsingBaseUrl = !!settings.LLM_BASE_URL;
const isUsingCustomModel = !!settings.LLM_MODEL && !isKnownModel;
const isUsingDefaultCondenser = !!settings.ENABLE_DEFAULT_CONDENSER;

return (
isUsingSecurityAnalyzer ||
isUsingConfirmationMode ||
isUsingBaseUrl ||
isUsingCustomModel
isUsingCustomModel ||
isUsingDefaultCondenser
);
}

Expand All @@ -94,6 +97,9 @@ export function SettingsForm({
const isUsingAdvancedOptions = keys.includes("use-advanced-options");
const newSettings = extractSettings(formData);

// Inject the condenser config from the current feature flag value
newSettings.ENABLE_DEFAULT_CONDENSER = MEMORY_CONDENSER;

saveSettingsView(isUsingAdvancedOptions ? "advanced" : "basic");
await saveUserSettings(newSettings);
onClose();
Expand Down
1 change: 1 addition & 0 deletions frontend/src/hooks/mutation/use-save-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const saveSettingsMutationFn = async (settings: Partial<Settings>) => {
confirmation_mode: settings.CONFIRMATION_MODE,
security_analyzer: settings.SECURITY_ANALYZER,
llm_api_key: settings.LLM_API_KEY?.trim() || undefined,
enable_default_condenser: settings.ENABLE_DEFAULT_CONDENSER,
};

await OpenHands.saveSettings(apiSettings);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/hooks/query/use-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const getSettingsQueryFn = async () => {
LLM_API_KEY: apiSettings.llm_api_key,
REMOTE_RUNTIME_RESOURCE_FACTOR:
apiSettings.remote_runtime_resource_factor,
ENABLE_DEFAULT_CONDENSER: apiSettings.enable_default_condenser,
};
}

Expand Down
3 changes: 3 additions & 0 deletions frontend/src/i18n/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4506,5 +4506,8 @@
"fr": "Que voulez-vous construire ?",
"tr": "Ne inşa etmek istiyorsun?",
"de": "Was möchten Sie erstellen?"
},
"SETTINGS_FORM$ENABLE_DEFAULT_CONDENSER_SWITCH_LABEL": {
"en": "Enable Memory Condenser"
}
}
7 changes: 7 additions & 0 deletions frontend/src/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type Settings = {
CONFIRMATION_MODE: boolean;
SECURITY_ANALYZER: string;
REMOTE_RUNTIME_RESOURCE_FACTOR: number;
ENABLE_DEFAULT_CONDENSER: boolean;
};

export type ApiSettings = {
Expand All @@ -20,6 +21,7 @@ export type ApiSettings = {
confirmation_mode: boolean;
security_analyzer: string;
remote_runtime_resource_factor: number;
enable_default_condenser: boolean;
};

export const DEFAULT_SETTINGS: Settings = {
Expand All @@ -31,6 +33,7 @@ export const DEFAULT_SETTINGS: Settings = {
CONFIRMATION_MODE: false,
SECURITY_ANALYZER: "",
REMOTE_RUNTIME_RESOURCE_FACTOR: 1,
ENABLE_DEFAULT_CONDENSER: false,
};

export const getCurrentSettingsVersion = () => {
Expand Down Expand Up @@ -60,6 +63,8 @@ export const getLocalStorageSettings = (): Settings => {
const llmApiKey = localStorage.getItem("LLM_API_KEY");
const confirmationMode = localStorage.getItem("CONFIRMATION_MODE") === "true";
const securityAnalyzer = localStorage.getItem("SECURITY_ANALYZER");
const enableDefaultCondenser =
localStorage.getItem("ENABLE_DEFAULT_CONDENSER") === "true";

return {
LLM_MODEL: llmModel || DEFAULT_SETTINGS.LLM_MODEL,
Expand All @@ -71,6 +76,8 @@ export const getLocalStorageSettings = (): Settings => {
SECURITY_ANALYZER: securityAnalyzer || DEFAULT_SETTINGS.SECURITY_ANALYZER,
REMOTE_RUNTIME_RESOURCE_FACTOR:
DEFAULT_SETTINGS.REMOTE_RUNTIME_RESOURCE_FACTOR,
ENABLE_DEFAULT_CONDENSER:
enableDefaultCondenser || DEFAULT_SETTINGS.ENABLE_DEFAULT_CONDENSER,
};
};

Expand Down
1 change: 1 addition & 0 deletions frontend/src/utils/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ function loadFeatureFlag(
}

export const MULTI_CONVERSATION_UI = loadFeatureFlag("MULTI_CONVERSATION_UI");
export const MEMORY_CONDENSER = loadFeatureFlag("MEMORY_CONDENSER");
9 changes: 9 additions & 0 deletions openhands/server/session/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from openhands.controller.agent import Agent
from openhands.core.config import AppConfig
from openhands.core.config.condenser_config import AmortizedForgettingCondenserConfig
from openhands.core.const.guide_url import TROUBLESHOOTING_URL
from openhands.core.logger import openhands_logger as logger
from openhands.core.schema import AgentState
Expand Down Expand Up @@ -105,6 +106,14 @@ async def initialize_agent(

llm = LLM(config=self.config.get_llm_config_from_agent(agent_cls))
agent_config = self.config.get_agent_config(agent_cls)

if settings.enable_default_condenser:
default_condenser_config = AmortizedForgettingCondenserConfig(
keep_first=3, max_size=20
)
logger.info(f'Enabling default condenser: {default_condenser_config}')
agent_config.condenser = default_condenser_config

agent = Agent.get_cls(agent_cls)(llm, agent_config)

github_token = None
Expand Down
1 change: 1 addition & 0 deletions openhands/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Settings(BaseModel):
llm_api_key: SecretStr | None = None
llm_base_url: str | None = None
remote_runtime_resource_factor: int | None = None
enable_default_condenser: bool = False

@field_serializer('llm_api_key')
def llm_api_key_serializer(self, llm_api_key: SecretStr, info: SerializationInfo):
Expand Down

0 comments on commit f81e01a

Please sign in to comment.