|
| 1 | +# External command calls to allow LLMs to experiment and learn |
| 2 | + |
| 3 | +## Summary |
| 4 | +I propose a language extension to `CEDARScript` to allow arbitrary command execution. |
| 5 | +It would work as an escape hatch that connects the LLM to the external environment. |
| 6 | + |
| 7 | +Security implications aside, it holds a lot of potential. |
| 8 | + |
| 9 | +The firs application could be a benchmark to see if the LLM would be able to perform better than the baseline |
| 10 | +when solving complex mathematical challenges, e. g. https://epoch.ai/frontiermath |
| 11 | + |
| 12 | +## Examples |
| 13 | + |
| 14 | +```sql |
| 15 | +-- Capturing script output |
| 16 | + |
| 17 | +CALL LANGUAGE "python" |
| 18 | +WITH CONTENT r''' |
| 19 | +import os |
| 20 | +print(os.environ) |
| 21 | +'''; |
| 22 | + |
| 23 | +CALL COMMAND |
| 24 | +WITH CONTENT r''' |
| 25 | +#!/usr/bin/python3 -B -O |
| 26 | +import sys |
| 27 | +print(sys.version) |
| 28 | +'''; |
| 29 | + |
| 30 | +CALL COMMAND |
| 31 | +-- ENV MODE (ISOLATED* | INHERIT ONLY | INHERIT ALL) |
| 32 | +ENV MODE INHERIT ONLY 'PATH, HOME, API_KEY' |
| 33 | +-- ENV (r'''<env-spec>''' | FILE "<path>") |
| 34 | +ENV r''' |
| 35 | +OUTPUT_FORMAT=xml |
| 36 | +MAX_RESULTS=20 |
| 37 | +''' |
| 38 | +CAPTURE STDOUT -- CAPTURE (*ALL | STDOUT | STDERR) |
| 39 | +-- WITH (CONTENT r'''<string>''' | FILE "<path>") |
| 40 | +WITH CONTENT r''' |
| 41 | +#!/bin/bash |
| 42 | +
|
| 43 | +echo $PATH |
| 44 | +echo $HOME |
| 45 | +echo $API_KEY $MAX_RESULTS |
| 46 | +curl http://something.com/ |
| 47 | +'''; |
| 48 | + |
| 49 | +``` |
| 50 | + |
| 51 | +## Syntax in EBNF |
| 52 | + |
| 53 | +``` |
| 54 | +call_command ::= |
| 55 | + | 'CALL' 'COMMAND' [env_spec] with_clause |
| 56 | + | 'CALL' 'LANGUAGE' string_literal [env_spec] with_clause |
| 57 | +
|
| 58 | +env_spec ::= [env_mode_clause] [env_clause] [capture_clause] |
| 59 | +
|
| 60 | +env_mode_clause ::= 'ENV' 'MODE' ( |
| 61 | + | 'ISOLATED' (* Default *) |
| 62 | + | 'INHERIT' 'ALL' |
| 63 | + | 'INHERIT' 'ONLY' string_literal (* Comma-separated list *) |
| 64 | +) |
| 65 | +
|
| 66 | +env_clause ::= 'ENV' ( |
| 67 | + | raw_string_literal (* Multiline env vars *) |
| 68 | + | 'FILE' string_literal (* Load from file *) |
| 69 | +) |
| 70 | +
|
| 71 | +capture_clause ::= 'CAPTURE' ('ALL' | 'STDOUT' | 'STDERR') |
| 72 | +
|
| 73 | +with_clause ::= 'WITH' ( |
| 74 | + | 'CONTENT' raw_string_literal (* Inline script with optional shebang *) |
| 75 | + | 'FILE' string_literal (* Script file with optional shebang *) |
| 76 | +) |
| 77 | +``` |
0 commit comments