Implement browser session inactivity timeout and cleanup
- Updated `.env.example` to include `BROWSER_INACTIVITY_TIMEOUT` for auto-cleanup of inactive sessions. - Enhanced `cli.py` to load the new inactivity timeout configuration into environment variables. - Added background thread functionality in `browser_tool.py` to periodically clean up inactive browser sessions based on the configured timeout. - Improved session management by tracking last activity timestamps and ensuring cleanup occurs when sessions exceed inactivity limits.
This commit is contained in:
parent
c360da4f35
commit
20f2875472
6 changed files with 336 additions and 4 deletions
13
cli.py
13
cli.py
|
|
@ -67,6 +67,9 @@ def load_cli_config() -> Dict[str, Any]:
|
|||
"singularity_image": "docker://python:3.11",
|
||||
"modal_image": "python:3.11",
|
||||
},
|
||||
"browser": {
|
||||
"inactivity_timeout": 120, # Auto-cleanup inactive browser sessions after 2 min
|
||||
},
|
||||
"agent": {
|
||||
"max_turns": 20,
|
||||
"verbose": False,
|
||||
|
|
@ -138,6 +141,16 @@ def load_cli_config() -> Dict[str, Any]:
|
|||
if config_key in terminal_config:
|
||||
os.environ[env_var] = str(terminal_config[config_key])
|
||||
|
||||
# Apply browser config to environment variables
|
||||
browser_config = defaults.get("browser", {})
|
||||
browser_env_mappings = {
|
||||
"inactivity_timeout": "BROWSER_INACTIVITY_TIMEOUT",
|
||||
}
|
||||
|
||||
for config_key, env_var in browser_env_mappings.items():
|
||||
if config_key in browser_config:
|
||||
os.environ[env_var] = str(browser_config[config_key])
|
||||
|
||||
return defaults
|
||||
|
||||
# Load configuration at module startup
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue