Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,22 @@ Or one of the above command can be ran to run the agent with multiple instructio
steps:
- name: name of the step
original: original instruction
work_dir: optionally work directory
work_dir: optional work directory
command: bash command to run
- name: name of other step
original: original instruction
condition: bash command to run and check the return code
condition: optional bash command to run and check the return code
instruction: instruction to run the agent
- name: name of other step
original: original instruction
ignore: true
notes: notes
```

step can have `files` set to a list of files to include in the instruction for the agent to consult.

step can have `commit_if_change` set to either `true` or a string to commit the changes. If set to true, the step name is used as the commit message. If set to a string, the string is used instead.

```bash
--backend <agent name>
```
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "trobz-agent"
version = "1.0.0"
version = "1.0.1"
description = "Run an AI agent"
authors = [{name = "Hai Lang", email = "[email protected]"}]
requires-python = ">=3.10"
Expand Down
18 changes: 18 additions & 0 deletions trobz_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def run(cwd, *args, **kwargs):
return subprocess.run(args, **kwargs) # noqa: S603


def run_read(cwd, *args, **kwargs):
"""Shortcut to run a command in a given directory."""
return run(cwd, *args, **kwargs, stdout=subprocess.PIPE).stdout.decode("utf-8")


def run_agent(cwd, instructions, backend, mode, model):
if backend == "codex":
cmd_args = ["codex", "--full-auto"]
Expand Down Expand Up @@ -64,6 +69,17 @@ def inject_var(command):
return command.replace("{module_dir}", ".")


def commit_if_change(cwd, step):
changes = run_read(cwd, "git", "status", "--short")
if not changes.strip():
return
run(cwd, "git", "add", ".")
message = step["commit_if_change"]
if message == True: # noqa: E712
message = step["name"]
run(cwd, "git", "commit", "-m", message)


def run_workflow(workflow_dir, workflow, backend, mode, model): # noqa: C901
for step in workflow["steps"]:
if step.get("ignore", False):
Expand Down Expand Up @@ -98,6 +114,8 @@ def run_workflow(workflow_dir, workflow, backend, mode, model): # noqa: C901
instruction += "\n```\n"
if not error:
run_agent(cwd, instruction, backend, mode, model)
if step.get("commit_if_change"):
commit_if_change(cwd, step)


def main(
Expand Down
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading