Skip to content

Commit 562178b

Browse files
Merge pull request #12 from heroku/remove_use_temp_dir_llm_arg
Turns tempdir LLM argument into a configvar
2 parents 0407827 + b64933d commit 562178b

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

app.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"STDIO_MODE_ONLY": {
1616
"description": "Only allow tool requests via STDIO mode?",
1717
"value": "false"
18+
},
19+
"USE_TEMP_DIR": {
20+
"description": "Run Python code in a temporary virtualenv (not a sandbox, but does isolate packages).",
21+
"value": "false"
1822
}
1923
},
2024
"formation": [

example_clients/test_sse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def mcp(method_name, args=None):
3232
3333
Examples:
3434
python example_clients/test_sse.py mcp list_tools
35-
python example_clients/test_sse.py mcp call_tool --args '{"name": "fetch_webpage_and_markdownify", "arguments": {"url": "https://example.com"}}'
35+
python example_clients/test_sse.py mcp call_tool --args '{"name": "code_exec_python", "arguments": {"code": "print(list(range(100)))"}}'
3636
"""
3737
result = asyncio.run(run(method_name, args))
3838
print(json.dumps(result.model_dump(), indent=2))

src/code_execution.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from pydantic import Field
66
from typing import Annotated
77
from typing import Optional, Dict, Any, List, Dict, Any
8+
# local:
9+
from src import config
810

911
def run_command(cmd: List[str]) -> Dict[str, Any]:
1012
"""Executes a command using subprocess and returns output and errors."""
@@ -83,11 +85,7 @@ def code_exec_python(
8385
packages: Annotated[
8486
Optional[List[str]],
8587
Field(description="Optional list of pip package names to install before execution.")
86-
] = None,
87-
use_temp_dir: Annotated[
88-
bool,
89-
Field(description="Use a temporary isolated virtual environment in a tempdir for this run.")
90-
] = False
88+
] = None
9189
) -> Dict[str, Any]:
9290
"""Executes a Python code snippet with optional pip dependencies.
9391
@@ -100,7 +98,7 @@ def code_exec_python(
10098
- 'stdout': Captured standard output.
10199
- 'stderr': Captured standard error or install failure messages.
102100
"""
103-
if use_temp_dir:
101+
if config.USE_TEMP_DIR:
104102
return run_in_tempdir(code, packages)
105103

106104
install_result = install_dependencies(packages)

src/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def get_env_variable(var_name, required=True):
1717
PORT = int(os.environ.get('PORT', 8000))
1818
WEB_CONCURRENCY = int(os.environ.get('WEB_CONCURRENCY', 1))
1919
STDIO_MODE_ONLY = os.getenv("STDIO_MODE_ONLY", "false").lower() == "true"
20+
USE_TEMP_DIR = os.getenv("USE_TEMP_DIR", "false").lower() == "true"
2021

2122
# Local or Not:
2223
is_one_off_dyno = os.getenv("DYNO") is not None

0 commit comments

Comments
 (0)