You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lagent/actions/tmux_action.py
+55-15Lines changed: 55 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,32 @@
37
37
_TIMEOUT_TEMPLATE="Command '{command}' timed out after {timeout_sec}s.\n\n{terminal_state}"
38
38
39
39
40
+
TOOLSCHEMA= {
41
+
"name": "bash_command",
42
+
"description": """Send keystrokes to the persistent tmux pane and return pane output.The pane is a real bash shell running in a pty: it only executes a command once the keystrokes include a line terminator. Each call's keystrokes are sent verbatim; bash accumulates input across calls until it sees '\n' or 'Enter' — if you forget the terminator the command will sit unexecuted in the prompt and get concatenated with whatever you send next. Tmux-style key names are also accepted as tokens: 'C-c' (Ctrl+C), 'C-d' (Ctrl+D), 'Enter', 'Tab'.""",
43
+
"parameters": [
44
+
{
45
+
"name": "keystrokes",
46
+
"type": "string",
47
+
"description": """exact characters to send. MUST end with '\n' (or 'Enter') for the command to actually execute — without it bash stays in "typing" state and you will only see the prompt echo back your input, not the command's output.""",
48
+
},
49
+
{
50
+
"name": "duration",
51
+
"type": "number",
52
+
"description": """seconds to wait after sending before reading pane output (default 1.0, max 60.0). A too-short duration is the other way this tool appears to "do nothing": the command is still running when we capture the pane, so you see the prompt without output and assume it failed.
53
+
Guidance:
54
+
- 1.0 for typical commands (ls, cat, cd, pip install,
55
+
python scripts that finish quickly)
56
+
- 3-10 for builds / installers / downloads
57
+
- up to 60 for very slow commands
58
+
If output is incomplete, re-call with ``keystrokes=""`` and a longer ``duration`` to poll further — do NOT resend the command.""",
59
+
"default": 1.0,
60
+
},
61
+
],
62
+
"required": ["keystrokes", "duration"],
63
+
}
64
+
65
+
40
66
classTmuxSession:
41
67
"""Persistent tmux pane driven by local subprocess calls."""
42
68
@@ -320,7 +346,7 @@ def __init__(
320
346
pane_height: int=40,
321
347
working_dir: str|None=None,
322
348
extra_env: dict[str, str] |None=None,
323
-
description: dict|None=None,
349
+
description: dict=TOOLSCHEMA,
324
350
):
325
351
"""Create the tool and start the tmux session immediately.
"""Send keystrokes to the persistent tmux pane and return pane output.
351
377
352
-
Each call's keystrokes are sent verbatim to the terminal. Write them
353
-
exactly as you want them typed:
354
-
- End every command with '\\n' or it will not execute.
355
-
- Tmux-style escape sequences are accepted: 'C-c' (Ctrl+C),
356
-
'C-d' (Ctrl+D), 'Enter', 'Tab'.
378
+
The pane is a real bash shell running in a pty: it only executes a command once the keystrokes include a line terminator. Each call's keystrokes are sent verbatim; bash accumulates input across calls until it sees '\n' or 'Enter' — if you forget the terminator the command will sit unexecuted in the prompt and get concatenated with whatever you send next. Tmux-style key names are also accepted as tokens: 'C-c' (Ctrl+C), 'C-d' (Ctrl+D), 'Enter', 'Tab'.
357
379
358
380
Args:
359
-
keystrokes (str): exact characters to send to the terminal.
360
-
duration (float): seconds to wait after sending before returning
361
-
output (default 1.0, max 60.0). Use 0.1 for immediate
362
-
commands (cd, ls, echo, cat), 1.0 for typical commands
363
-
(gcc, find, rustc), longer for slow commands (make, wget,
364
-
long-running scripts). Prefer polling with an empty
365
-
keystrokes string over long single waits — call again with
366
-
``keystrokes=""`` and a longer duration if output is not
367
-
yet complete. Never wait longer than 60 seconds.
381
+
keystrokes (str): exact characters to send. MUST end with '\n' (or 'Enter') for the command to actually execute — without it bash stays in "typing" state and you will only see the prompt echo back your input, not the command's output.
382
+
duration (float): seconds to wait after sending before reading pane output (default 1.0, max 60.0). A too-short duration is the other way this tool appears to "do nothing": the command is still running when we capture the pane, so you see the prompt without output and assume it failed.
383
+
Guidance:
384
+
- 1.0 for typical commands (ls, cat, cd, pip install,
385
+
python scripts that finish quickly)
386
+
- 3-10 for builds / installers / downloads
387
+
- up to 60 for very slow commands
388
+
If output is incomplete, re-call with ``keystrokes=""`` and a longer ``duration`` to poll further — do NOT resend the command.
368
389
369
390
Returns:
370
391
str: terminal output (new pane content since the last call, or
0 commit comments