Skip to content

Commit 5b60cb0

Browse files
committed
Add optional persist parameter to workspace and retries configuration tools
1 parent 9243669 commit 5b60cb0

3 files changed

Lines changed: 50 additions & 40 deletions

File tree

MaxKernel/hitl_agent/prompts/interactive_prompt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@
4242
4343
* **If the request is to CHANGE/SET the workspace or working directory**:
4444
* **Action**: Call `set_working_directory` tool with the absolute path.
45+
* **Note**: Set `persist=True` ONLY if the user explicitly asks to persist, save, or make the change permanent. Otherwise, leave it as `False` (default).
4546
4647
* **If the request is to CHANGE/SET the maximum compilation retries**:
4748
* **Action**: Call `set_max_compilation_retries` tool with the integer value.
49+
* **Note**: Set `persist=True` ONLY if the user explicitly asks to persist, save, or make the change permanent. Otherwise, leave it as `False` (default).
4850
4951
* **If the request is simple explanation** (like "What is a TPU?"):
5052
* **Action**: Delegate to `ExplanationAgent`.

MaxKernel/hitl_agent/tools/retries_tool.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
from google.adk.tools import FunctionTool, ToolContext
66

77

8-
async def set_max_compilation_retries_fn(retries: int, tool_context: ToolContext) -> str:
8+
async def set_max_compilation_retries_fn(
9+
retries: int, tool_context: ToolContext, persist: bool = False
10+
) -> str:
911
"""Set the maximum number of compilation validation and auto-fixing attempts.
1012
1113
Args:
1214
retries: The maximum number of attempts (must be positive).
15+
persist: Whether to permanently save this change to the configuration file (default is False).
1316
1417
Returns:
1518
A string containing the operation result description:
16-
- If successful: "Successfully updated maximum compilation retries to: <retries>"
19+
- If successful: "Successfully updated maximum compilation retries to: <retries> (persisted: <persist>)"
1720
- If failed: "Error: The number of retries must be a positive integer."
1821
"""
1922
if retries <= 0:
@@ -24,24 +27,25 @@ async def set_max_compilation_retries_fn(retries: int, tool_context: ToolContext
2427
hitl_cfg.MAX_COMPILATION_RETRIES = retries
2528
os.environ["MAX_COMPILATION_RETRIES"] = str(retries)
2629

27-
# Update .env file
28-
try:
29-
env_path = ".env"
30-
if os.path.exists(env_path):
31-
with open(env_path, "r") as f:
32-
lines = f.readlines()
33-
with open(env_path, "w") as f:
34-
updated = False
35-
for line in lines:
36-
if line.strip().startswith("MAX_COMPILATION_RETRIES="):
30+
# Update .env file if persist is requested
31+
if persist:
32+
try:
33+
env_path = ".env"
34+
if os.path.exists(env_path):
35+
with open(env_path, "r") as f:
36+
lines = f.readlines()
37+
with open(env_path, "w") as f:
38+
updated = False
39+
for line in lines:
40+
if line.strip().startswith("MAX_COMPILATION_RETRIES="):
41+
f.write(f"MAX_COMPILATION_RETRIES={retries}\n")
42+
updated = True
43+
else:
44+
f.write(line)
45+
if not updated:
3746
f.write(f"MAX_COMPILATION_RETRIES={retries}\n")
38-
updated = True
39-
else:
40-
f.write(line)
41-
if not updated:
42-
f.write(f"MAX_COMPILATION_RETRIES={retries}\n")
43-
except Exception as e:
44-
logging.error(f"Failed to update .env: {e}")
47+
except Exception as e:
48+
logging.error(f"Failed to update .env: {e}")
4549

4650
# Update the active validation loops in-memory
4751
try:
@@ -50,7 +54,7 @@ async def set_max_compilation_retries_fn(retries: int, tool_context: ToolContext
5054
except Exception as e:
5155
logging.warning(f"Could not update hitl_loop max_retries: {e}")
5256

53-
return f"Successfully updated maximum compilation retries to: {retries}"
57+
return f"Successfully updated maximum compilation retries to: {retries} (persisted: {persist})"
5458

5559

5660
set_max_compilation_retries = FunctionTool(set_max_compilation_retries_fn)

MaxKernel/hitl_agent/tools/workspace_tool.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@
99
from hitl_agent.tools.filesystem_tools import filesystem_tool_r, filesystem_tool_rw
1010

1111

12-
async def set_working_directory_fn(path: str, tool_context: ToolContext) -> str:
12+
async def set_working_directory_fn(
13+
path: str, tool_context: ToolContext, persist: bool = False
14+
) -> str:
1315
"""Set the active workspace/working directory path for the session.
1416
1517
All filesystem tools (list_directory, read_file, write_file) will use
1618
the new path.
1719
1820
Args:
1921
path: The absolute path of the directory.
22+
persist: Whether to permanently save this change to the configuration file (default is False).
2023
2124
Returns:
2225
A string containing the operation result description:
23-
- If successful: "Successfully switched working directory to: <abs_path>"
26+
- If successful: "Successfully switched working directory to: <abs_path> (persisted: <persist>)"
2427
- If failed: "Error: Path '<path>' does not exist." or "Error: Path '<path>' is not a directory."
2528
"""
2629
if not os.path.exists(path):
@@ -34,24 +37,25 @@ async def set_working_directory_fn(path: str, tool_context: ToolContext) -> str:
3437
config.WORKDIR = abs_path
3538
os.environ["WORKDIR"] = abs_path
3639

37-
# Update .env file
38-
try:
39-
env_path = ".env"
40-
if os.path.exists(env_path):
41-
with open(env_path, "r") as f:
42-
lines = f.readlines()
43-
with open(env_path, "w") as f:
44-
updated = False
45-
for line in lines:
46-
if line.strip().startswith("WORKDIR="):
40+
# Update .env file if persist is requested
41+
if persist:
42+
try:
43+
env_path = ".env"
44+
if os.path.exists(env_path):
45+
with open(env_path, "r") as f:
46+
lines = f.readlines()
47+
with open(env_path, "w") as f:
48+
updated = False
49+
for line in lines:
50+
if line.strip().startswith("WORKDIR="):
51+
f.write(f'WORKDIR="{abs_path}"\n')
52+
updated = True
53+
else:
54+
f.write(line)
55+
if not updated:
4756
f.write(f'WORKDIR="{abs_path}"\n')
48-
updated = True
49-
else:
50-
f.write(line)
51-
if not updated:
52-
f.write(f'WORKDIR="{abs_path}"\n')
53-
except Exception as e:
54-
logging.error(f"Failed to update .env: {e}")
57+
except Exception as e:
58+
logging.error(f"Failed to update .env: {e}")
5559

5660
# Update active filesystem tools
5761
# Update read-only filesystem tool
@@ -80,7 +84,7 @@ async def set_working_directory_fn(path: str, tool_context: ToolContext) -> str:
8084
sampling_capabilities=filesystem_tool_rw._sampling_capabilities,
8185
)
8286

83-
return f"Successfully switched working directory to: {abs_path}"
87+
return f"Successfully switched working directory to: {abs_path} (persisted: {persist})"
8488

8589

8690
set_working_directory = FunctionTool(set_working_directory_fn)

0 commit comments

Comments
 (0)