diff options
| author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2026-10-12 19:54:29 +0300 |
|---|---|---|
| committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2026-10-12 19:54:29 +0300 |
| commit | 4d6f0330dd4648b2ae4385d08a58a8a78fb50b29 (patch) | |
| tree | 591efa0054e0859660a023fee7f9afbeab8bcdaa /actions.py | |
| parent | e42ae589c623dd1a5ae379899c94f93ed05bc848 (diff) | |
| download | agent-4d6f0330dd4648b2ae4385d08a58a8a78fb50b29.tar.gz agent-4d6f0330dd4648b2ae4385d08a58a8a78fb50b29.zip | |
fix: more robust action matching
Diffstat (limited to 'actions.py')
| -rw-r--r-- | actions.py | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -1,5 +1,5 @@ from pathlib import Path -from typing import Optional, Callable, Dict +from typing import Optional, Callable, Dict, List from dataclasses import dataclass import subprocess import re @@ -17,6 +17,7 @@ class Action: name: str description: str handler: Callable[[JSON, AgentConfig], JSON] + required_keys: List[str] formatter: Callable[[JSON], str] = lambda args: ( f"{args['action']} with " + ",".join([f"{arg} as {args[arg]}" for arg in args if arg != "action"]) @@ -148,30 +149,34 @@ def _webgrep(args: JSON, config: AgentConfig) -> JSON: return {"status": "success", "matches": list(matches)} -ls = Action("ls", _ls.__doc__ or "", _ls) -read = Action("read", _read.__doc__ or "", _read) +ls = Action("ls", _ls.__doc__ or "", _ls, ["path"]) +read = Action("read", _read.__doc__ or "", _read, ["path"]) write = Action( "write", _write.__doc__ or "", _write, + ["path", "content"], formatter=lambda args: f"write {args['path']}", ) -tldr = Action("tldr", _tldr.__doc__ or "", _tldr) +tldr = Action("tldr", _tldr.__doc__ or "", _tldr, ["program"]) shell = Action( "shell", _shell.__doc__ or "", _shell, + ["command"], formatter=lambda args: f"shell command `{args['command']}`", ) mypy = Action( "mypy", _mypy.__doc__ or "", _mypy, + ["path"], formatter=lambda args: f"type check {args['path']}", ) webgrep = Action( "webgrep", _webgrep.__doc__ or "", _webgrep, + ["url", "keywords"], formatter=lambda args: f"search {args['url']}", ) |
