Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
77 lines (62 loc) · 3.68 KB
/
Copy pathmain.py
File metadata and controls
77 lines (62 loc) · 3.68 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
"""
main.py — Entry point for Agentic Tool Synth.
Usage:
python main.py Run with the current toolkit (loads from disk)
python main.py --reset Wipe toolkit.json and start a fresh session
Each run is a SESSION. Tools synthesised in one session are saved to
toolkit.json and inherited automatically by the next session — this is
the persistence story.
"""
import sys
from dotenv import load_dotenv
load_dotenv() # must run before anthropic client is created
from agent.toolkit import ToolKit, TOOLKIT_PATH
from agent.agent import Agent
from agent.models import Task
from agent.retention import RetentionPolicy
from agent import console as con
# ── Reset flag ────────────────────────────────────────────────────────────────
if "--reset" in sys.argv or "--clear" in sys.argv:
if TOOLKIT_PATH.exists():
TOOLKIT_PATH.unlink()
con.console.print(
"[yellow] * --reset: toolkit.json deleted. Starting fresh.[/yellow]\n"
)
# ── Initialise ────────────────────────────────────────────────────────────────
policy = RetentionPolicy()
toolkit = ToolKit() # loads toolkit.json if it exists
agent = Agent(toolkit)
# Snapshot the tool names that existed BEFORE this session runs.
# Anything added after this point is "new" for the session summary.
_inherited_tools = list(toolkit.list_tools())
_initial_count = len(_inherited_tools)
# ── Session start banner ──────────────────────────────────────────────────────
con.session_start(_inherited_tools, policy, str(TOOLKIT_PATH))
# ── Tasks ─────────────────────────────────────────────────────────────────────
tasks = [
# Task 1: will synthesise parse_log on first run; reuse it on subsequent runs
Task(id="t1", description="parse a messy log file into structured JSON"),
# Task 2: reuses parse_log (keyword overlap)
Task(id="t2", description="parse messy server logs into JSON format"),
# Task 3: will synthesise compute_sha256 on first run; reuse on subsequent runs
Task(id="t3", description="compute the SHA256 hash of a string"),
]
for task in tasks:
agent.run(task)
# ── Retention report ─────────────────────────────────────────────────────────
tools_and_decisions = [
(tool, policy.evaluate(tool))
for tool in toolkit.list_tools()
]
con.retention_report(tools_and_decisions)
# ── Prune pass ────────────────────────────────────────────────────────────────
removed = toolkit.prune(policy)
con.prune_result(removed, len(toolkit.tools))
# ── Session end summary ───────────────────────────────────────────────────────
new_tools_count = len(toolkit.tools) - _initial_count + len(removed)
con.session_end(
tasks_run=len(tasks),
new_tools=max(0, new_tools_count),
total_tools=len(toolkit.tools),
path=str(TOOLKIT_PATH),
)