ameforge commited on
Commit
448beb7
·
verified ·
1 Parent(s): 0cbc7a2

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +163 -0
README.md ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ - fr
6
+ library_name: transformers
7
+ pipeline_tag: text-generation
8
+ tags:
9
+ - agentic
10
+ - function-calling
11
+ - tool-use
12
+ - structured-generation
13
+ - orchestration
14
+ - code-agent
15
+ - mcp
16
+ - edge
17
+ - small-language-model
18
+ base_model: AMFORGE/samg-reasoning
19
+ model-index:
20
+ - name: SAM-G-CobraTooling
21
+ results:
22
+ - task:
23
+ type: agentic-orchestration
24
+ name: Agentic IDE tool-call orchestration (13 families, held-out)
25
+ metrics:
26
+ - type: exact_match
27
+ value: 78.8
28
+ name: Exact plan match, aggregate (%)
29
+ - type: accuracy
30
+ value: 94.0
31
+ name: Risk-gate fidelity (%)
32
+ ---
33
+
34
+ # SAM-G-CobraTooling
35
+
36
+ **SAM-G-CobraTooling** is a 30.3M-parameter model fine-tuned from
37
+ [SAM-G-Reasoning](https://huggingface.co/AMFORGE/samg-reasoning) on 196k
38
+ agentic orchestration traces. It turns a natural-language instruction — or an
39
+ observation from a previous step — into an **ordered, risk-flagged JSON plan of
40
+ tool calls**. It is the local orchestration layer of an agentic IDE: it routes,
41
+ decomposes, tracks state, reacts to exit codes and HTTP status, and emits
42
+ structured tool calls entirely offline. It does **not** write code; code is
43
+ delegated to a larger model via an `ask_code_model` hand-off. Built by
44
+ **AMEFORGE** for the CobraBub IDE.
45
+
46
+ - **Parameters:** 30.3M · **Footprint:** 121 MB fp32 (~30 MB quantized) · **Base:** SAM-G-Reasoning
47
+ - **Fine-tuning:** prompt-masked SFT (loss on the plan span only), cosine 8e-5, 10k steps, best at 6k
48
+ - **Aggregate exact plan-match:** 78.8% (held-out, disjoint seed)
49
+ - **Lineage:** SAM-G → SAM-G-Reasoning → SAM-G-CobraTooling
50
+
51
+ ## Output format
52
+
53
+ ```
54
+ <instruction> [ACTION] {"plan":[{"op":...,"args":{...},"risk":"safe|critical"}, ...]}
55
+ <intent> | {"last_op":...,"...":...} [ACTION] {"plan":[ ... ]} # reactive (observation-driven)
56
+ ```
57
+
58
+ Every step carries a `risk` flag (`safe` or `critical`) that drives the IDE
59
+ confirmation gate: safe ops run autonomously, critical ops require explicit
60
+ user confirmation.
61
+
62
+ ## What it is good at — and what it is not
63
+
64
+ Stress-tested on thirteen families. The pattern mirrors the rest of the SAM-G
65
+ line: it excels at **routing and reaction** (short, procedural) and is limited
66
+ on **long ordered chains** that must match exactly at 30M parameters.
67
+
68
+ | Family | Exact % | Type |
69
+ |---|---|---|
70
+ | single_tool (routing) | 100 | routing |
71
+ | retry_loop (exit-code state machine) | 100 | reaction |
72
+ | feedback_react (stdout/stderr) | 100 | reaction |
73
+ | git_workflow (status→add→push, gated) | 100 | procedural |
74
+ | scrape_research (fetch→summarize→act) | 100 | procedural |
75
+ | db_query (SQL, SELECT vs mutation) | 100 | structured call |
76
+ | webhook_wait (async callback) | 92 | async reaction |
77
+ | **mcp_call (filesystem/github/postgres)** | **83** | **structured call** |
78
+ | api_call (REST/GraphQL + HTTP state machine) | 75 | structured call |
79
+ | plan_chain (multi-step plans) | 58 | planning |
80
+ | risk_gate (mixed safe/critical plans) | 58 | gated planning |
81
+ | fs_watch (file-change reaction) | 42 | async reaction |
82
+ | build_test_cycle (edit→test→react + hand-off) | 17 | long chain |
83
+
84
+ Routing, exit-code reaction, git, scraping and SQL routing are saturated.
85
+ `mcp_call` at 83% makes the model a viable local driver for MCP servers — the
86
+ core capability of a hosted code agent, here running offline. `plan_chain` rose
87
+ from the v1 plateau (0–42%) to 58% after broadening generator coverage.
88
+ `build_test_cycle` remains the hard family: four-to-five ordered ops ending in a
89
+ code-model hand-off, scored by strict exact match — the same long-chain ceiling
90
+ seen with arithmetic in SAM-G-Reasoning. For those, decompose app-side into
91
+ shorter sub-calls.
92
+
93
+ ## Security: the risk flag is advisory, not a boundary
94
+
95
+ The model flags critical ops with **94% fidelity** across all families — strong
96
+ for pre-flagging and good UX. **It must not be the sole security boundary.** A
97
+ 30M model will mis-flag a fraction of decisions, and the failure modes are
98
+ asymmetric: a false negative (a critical op flagged `safe`) would auto-run a
99
+ destructive command without confirmation. Integrators must add a
100
+ **deterministic backstop**: a hard whitelist/blacklist in the app that forces
101
+ `critical` on known-dangerous operations (`rm -rf`, `git push`, `DROP`/`DELETE`,
102
+ external mutating HTTP, MCP write tools, `delete_file`) regardless of the
103
+ model's flag. Treat the model's `risk` field as a fast hint that pre-fills the
104
+ confirmation gate, with the app's deterministic rules as the enforced boundary.
105
+
106
+ ## Op vocabulary
107
+
108
+ Routing/IO: `open_file`, `list_dir`, `run_command`, `scrape`, `summarize`,
109
+ `capture`, `open_app`. Hand-off: `ask_code_model`, `write_file`. Control:
110
+ `retry`, `escalate`, `backoff`, `reauth`, `continue`, `stop`. Integrations:
111
+ `api_call`, `mcp_call`, `db_query`, `webhook_wait`, `fs_watch`, `git_push`.
112
+
113
+ ## Intended use
114
+
115
+ The local planning/routing/reaction layer of an agentic IDE: decompose an
116
+ instruction into ordered tool calls, react to observations (exit codes, stderr,
117
+ HTTP status, DB row counts, webhook payloads, file-change events), and emit
118
+ structured, risk-flagged plans offline and for free. Roughly the procedural
119
+ majority of agentic turns; hard code generation and long exact chains are
120
+ escalated to a larger model via `ask_code_model`.
121
+
122
+ ## Usage
123
+
124
+ ```python
125
+ import sentencepiece as spm, torch
126
+ sp = spm.SentencePieceProcessor(); sp.Load("samg_tokenizer.model")
127
+
128
+ # routing
129
+ prompt = "open src/main.js and run the tests [ACTION]"
130
+ # -> {"plan":[{"op":"open_file","args":{"path":"src/main.js"},"risk":"safe"},
131
+ # {"op":"run_command","args":{"cmd":"pytest"},"risk":"safe"}]}
132
+
133
+ # reactive: HTTP 429 -> back off and retry
134
+ prompt = "rate limited, back off and retry | {\"last_op\":\"api_call\",\"status\":429} [ACTION]"
135
+ # -> {"plan":[{"op":"backoff","args":{"seconds":30},"risk":"safe"},
136
+ # {"op":"retry","args":{"attempt":2},"risk":"safe"}]}
137
+
138
+ ids = torch.tensor([sp.EncodeAsIds(prompt)])
139
+ # greedy-decode the [ACTION] span -> structured plan JSON
140
+ ```
141
+
142
+ ## Limitations
143
+
144
+ - `build_test_cycle` (17%) and the exact-match of `plan_chain`/`risk_gate`
145
+ (58%) plateau because long, strictly-ordered plans are hard at 30M; decompose
146
+ long plans app-side into shorter sub-calls.
147
+ - The `risk` flag is advisory (94% fidelity); enforce a deterministic backstop
148
+ in the app, as above.
149
+ - Traces are synthetic, drawn from the training family distribution with a
150
+ disjoint evaluation seed; coverage reflects the generator, not arbitrary
151
+ real-world tool APIs.
152
+ - Not a general assistant and does not write code; it orchestrates and hands
153
+ off. Inherits the base model's knowledge limits.
154
+
155
+ ## Citation
156
+
157
+ ```bibtex
158
+ @misc{samgcobratooling2026,
159
+ title = {SAM-G-CobraTooling: Risk-Flagged Agentic Tool-Call Orchestration at 30M Parameters},
160
+ author = {AMEFORGE Lab},
161
+ year = {2026}
162
+ }
163
+ ```