-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
116 lines (97 loc) · 3.64 KB
/
Copy pathagent.py
File metadata and controls
116 lines (97 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""Interactive coding agent.
A REPL interface to a Flow coding agent. Talk to it, give it tasks, it writes
and edits files in your working directory using delegation.
Usage:
python examples/coding/agent.py --workdir ./myproject
python examples/coding/agent.py --workdir ./myproject --no-viz
python examples/coding/agent.py --workdir ./myproject --docker-image rlmflow:local
"""
from __future__ import annotations
import argparse
from pathlib import Path
import rflow
from rflow.tools import FILE_TOOLS
def build_llm(model: str):
return (
rflow.AnthropicClient(model)
if model.startswith("claude")
else rflow.OpenAIClient(model)
)
def main():
examples_root = Path(__file__).resolve().parents[1]
parser = argparse.ArgumentParser(description="Interactive coding agent")
parser.add_argument(
"--workdir",
type=str,
default=str(examples_root / "_runs" / "coding"),
help="working directory the agent edits (default: examples/_runs/coding/)",
)
parser.add_argument("--model", default="gpt-5")
parser.add_argument("--fast-model", default="gpt-5-mini")
parser.add_argument(
"--docker-image",
default=None,
help="If set, run agent code inside this Docker image (e.g. rlmflow:local).",
)
parser.add_argument("--max-depth", type=int, default=3)
parser.add_argument("--max-iters", type=int, default=30)
parser.add_argument("--no-viz", action="store_true")
parser.add_argument(
"--max-concurrency",
type=int,
default=8,
help="Maximum number of concurrent tasks to run.",
)
args = parser.parse_args()
if args.docker_image:
print(f">>> DOCKER RUNTIME image={args.docker_image}")
else:
print(">>> LOCAL RUNTIME")
workdir = Path(args.workdir).resolve()
workdir.mkdir(parents=True, exist_ok=True)
print(f"Working directory: {workdir}")
# The runtime decides where code runs and carries the file tools. Local runs
# in-process with the cwd switched into `workdir`; Docker runs each agent in a
# container with `workdir` bind-mounted to /workspace. Same interface.
if args.docker_image:
runtime = rflow.DockerRuntime(args.docker_image, working_directory=workdir)
else:
runtime = rflow.LocalRuntime(working_directory=workdir)
runtime.register_tools(FILE_TOOLS)
flow = rflow.Flow(
build_llm(args.model),
llm_clients={"fast": build_llm(args.fast_model)},
runtime=runtime,
max_depth=args.max_depth,
max_iters=args.max_iters,
max_concurrency=args.max_concurrency,
)
print("Agent ready. Type a query, or 'quit' to exit.\n")
try:
while True:
try:
query = input("> ").strip()
except (EOFError, KeyboardInterrupt):
print()
break
if not query or query.lower() in ("quit", "exit", "q"):
break
graph = flow.start(query)
if args.no_viz:
while not graph.finished:
graph = flow.step(graph)
else:
from rflow.utils.viz import live_view
with live_view() as view:
view(graph)
while not graph.finished:
graph = flow.step(graph)
view(graph)
print(f"\n{graph.result() or '(no result)'}\n")
path = graph.save(workdir / "graph")
print(f"Graph saved to {path}")
print(f"Files written under {workdir}")
finally:
flow.close()
if __name__ == "__main__":
main()