diff options
| author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2026-10-11 14:24:45 +0300 |
|---|---|---|
| committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2026-10-11 14:24:45 +0300 |
| commit | 0e3d7053c4d1a774d43e241ff04571d57b9a6673 (patch) | |
| tree | b6ed1aecf2b3abc7a1b90bc3f80ca377d1cd21fb /llm.py | |
| parent | 0d5c378beb81d436e4ae0226e6f952d196b15ab1 (diff) | |
| download | agent-0e3d7053c4d1a774d43e241ff04571d57b9a6673.tar.gz agent-0e3d7053c4d1a774d43e241ff04571d57b9a6673.zip | |
feat: trust system
Diffstat (limited to 'llm.py')
| -rwxr-xr-x | llm.py | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -27,6 +27,8 @@ class AgentConfig: workdir: Path actions: List["Action"] + trustlevels: Dict[str, int] + trustlevel: int client = OpenAI( @@ -105,9 +107,16 @@ def query_agent(query: str, config: AgentConfig, state=()): f = first(config.actions, lambda f: f.name == action_name) if f is not None: - result_json = f(action, config) + desc = f.formatter(action) + if ( + config.trustlevels[action_name] > config.trustlevel + and not input(f"Perform {desc}? [y/N] ") == "y" + ): + result_json = {"status": "error", "reason": "Permission denied by user"} + else: + result_json = f(action, config) result_jsons.append(result_json) - replacements.append((m.start(), m.end(), action_name)) + replacements.append((m.start(), m.end(), desc)) replaced_res = "" i = 0 @@ -133,7 +142,18 @@ def main(): ) args = parser.parse_args() - config = AgentConfig(workdir=args.workdir, actions=[ls, read, write, tldr, shell]) + config = AgentConfig( + workdir=args.workdir, + actions=[ls, read, write, tldr, shell], + trustlevels={ + "ls": 0, + "read": 0, + "tldr": 0, + "write": 1, + "shell": 2, + }, + trustlevel=0, + ) state = ( { |
