Alogotron commited on
Commit
8ad1d02
·
verified ·
1 Parent(s): 0b3707a

feat: dataset v1 - 102 A0 tool-call SFT pairs from arm chats

Browse files
Files changed (3) hide show
  1. README.md +62 -0
  2. a0-toolcall-sft-v1.jsonl +0 -0
  3. extract_a0_toolcalls.py +108 -0
README.md ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ task_categories:
4
+ - text-generation
5
+ tags:
6
+ - agentic
7
+ - tool-calling
8
+ - agent-zero
9
+ - sft
10
+ - function-calling
11
+ language:
12
+ - en
13
+ size_categories:
14
+ - n<1K
15
+ pretty_name: A0 Tool-Call SFT v1
16
+ ---
17
+
18
+ # a0-toolcall-sft (v1)
19
+
20
+ Supervised-fine-tuning dataset of **Agent Zero tool-call JSON replies**, extracted from real agent conversation logs. Goal: teach small open models to reliably emit the A0 reply format — a single JSON object with `thoughts`, `headline`, `tool_name`, `tool_args` — instead of stalling in plain text.
21
+
22
+ Motivated by two real stall incidents (2026-10-02/03) where a local 27B model emitted plain text instead of tool-call JSON.
23
+
24
+ ## Format
25
+
26
+ Each JSONL line is one assistant turn that issued a tool call:
27
+
28
+ | field | content |
29
+ |---|---|
30
+ | `chat_id` | source chat log id |
31
+ | `turn_no` | log entry number |
32
+ | `timestamp` | unix timestamp of the turn |
33
+ | `context_user_msg` | most recent user message before the turn (truncated 1500 chars) |
34
+ | `thoughts_headline` | assistant headline (truncated 200 chars) |
35
+ | `target_json` | **training target**: full reply JSON `{thoughts, headline, tool_name, tool_args}` |
36
+
37
+ Training target example shape:
38
+
39
+ ```json
40
+ {"thoughts": ["..."], "headline": "...", "tool_name": "code_execution_tool", "tool_args": {"runtime": "terminal", "code": "..."}}
41
+ ```
42
+
43
+ ## Extraction & filtering
44
+
45
+ - Source: Agent Zero `chat.json` logs (`log.logs` entries, `type=agent` with `kvps.tool_name`).
46
+ - Only successful calls kept: turns whose nearest downstream result looks like an error (traceback / tool-not-found / error status) are dropped.
47
+ - Empty-arg calls dropped.
48
+ - Extraction script included: `extract_a0_toolcalls.py` (rerunnable as chats accumulate — self-improving corpus).
49
+
50
+ ## Redaction policy
51
+
52
+ Before writing, every record is scanned and scrubbed against patterns for: OpenAI-style keys, GitHub PATs (`ghp_`, `gho_`/`ghu_`/`ghs_`), HuggingFace tokens (`hf_`), JWTs, Slack tokens, AWS access keys, private key blocks, and `api_key/secret/token/password = value` assignments. Matches are replaced with `[REDACTED]`. Post-extraction QA on v1: **zero leftover secret-like strings, zero emails, zero IPv4s, zero password assignments.**
53
+
54
+ ## v1 scope & honest limitations
55
+
56
+ - 102 records from 3 arm-side chats. The brain-side host chat corpus was **not** reachable from the arm container in this session (no host CLI bridge / no host filesystem access) — planned for v2.
57
+ - Tool distribution is skewed toward `code_execution_tool` (89/102) because the arm's recent work is build/verify-heavy; expect distribution shift vs general assistant traffic.
58
+ - Context is a truncated nearest user message, not the full rolling conversation state.
59
+
60
+ ## Intended use
61
+
62
+ SFT for small (7–14B) open models to emit valid A0 tool-call JSON. Eval plan: tool-call validity rate + stall rate, base vs tuned, on held-out chats.
a0-toolcall-sft-v1.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
extract_a0_toolcalls.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Extract A0 tool-call SFT pairs from chat logs (brain + arm).
3
+
4
+ Input: chat.json files with log.logs entries.
5
+ type=agent -> assistant turn, kvps has thoughts/headline/tool_name/tool_args
6
+ type=user -> user message
7
+ type=code_exe/text_editor/tool/etc -> tool results (context only)
8
+ Output: JSONL records {system_hint, context_summary, target_json}
9
+ Success filter: keep only calls that produced a non-error result.
10
+ """
11
+ import json, re, sys, os, glob, hashlib
12
+
13
+ SECRET_PATTERNS = [
14
+ re.compile(r'sk-[A-Za-z0-9_\-]{20,}'), # openai-style keys
15
+ re.compile(r'ghp_[A-Za-z0-9]{30,}'), # github PAT
16
+ re.compile(r'gh[ous]_[A-Za-z0-9]{30,}'), # github tokens
17
+ re.compile(r'hf_[A-Za-z0-9]{30,}'), # HF tokens
18
+ re.compile(r'eyJ[A-Za-z0-9_\-\.]{20,}'), # JWT
19
+ re.compile(r'xox[baprs]-[A-Za-z0-9\-]{10,}'), # slack
20
+ re.compile(r'AKIA[0-9A-Z]{16}'), # AWS
21
+ re.compile(r'-----BEGIN[ A-Z]*PRIVATE KEY-----'),
22
+ re.compile(r'(?i)(api[_-]?key|secret|token|password)\s*[:=]\s*["\'][A-Za-z0-9_\-\.]{16,}["\']'),
23
+ ]
24
+
25
+ def redact(text):
26
+ if not isinstance(text, str):
27
+ return text
28
+ for pat in SECRET_PATTERNS:
29
+ text = pat.sub('[REDACTED]', text)
30
+ return text
31
+
32
+ def is_error_result(entry):
33
+ c = entry.get('content') or ''
34
+ k = entry.get('kvps') or {}
35
+ if not isinstance(c, str): c = str(c)
36
+ err_markers = ('Traceback (most recent call last)', 'not found. Available tools',
37
+ '"status": "error"', 'Error:', 'error:')
38
+ return any(m in c[:2000] for m in err_markers) or k.get('error') is not None
39
+
40
+ def extract_chat(chat_path):
41
+ with open(chat_path) as f:
42
+ d = json.load(f)
43
+ logs = d.get('log', {}).get('logs', [])
44
+ chat_id = d.get('id', os.path.basename(os.path.dirname(chat_path)))
45
+ records = []
46
+ # Build rolling context: map tool-call entry index -> result entry index
47
+ for i, entry in enumerate(logs):
48
+ if entry.get('type') != 'agent':
49
+ continue
50
+ kvps = entry.get('kvps') or {}
51
+ tool_name = kvps.get('tool_name')
52
+ tool_args = kvps.get('tool_args')
53
+ if not tool_name:
54
+ continue
55
+ # Find the next result entry (any type that carries content after this)
56
+ result_entry = None
57
+ for j in range(i+1, min(i+15, len(logs))):
58
+ t = logs[j].get('type')
59
+ if t in ('code_exe','text_editor','tool','util','response') or (t and t not in ('agent','user','progress')):
60
+ result_entry = logs[j]
61
+ break
62
+ # Success filter: skip if result looks like error
63
+ if result_entry is not None and is_error_result(result_entry):
64
+ continue
65
+ # Skip empty/no-op calls
66
+ if tool_args is None or tool_args == {}:
67
+ continue
68
+ # Build context: previous user message + prior assistant headline
69
+ prev_user = None
70
+ for j in range(i-1, -1, -1):
71
+ if logs[j].get('type') == 'user':
72
+ prev_user = logs[j].get('content')
73
+ break
74
+ rec = {
75
+ 'chat_id': chat_id,
76
+ 'turn_no': entry.get('no'),
77
+ 'timestamp': entry.get('timestamp'),
78
+ 'context_user_msg': redact((prev_user or '')[:1500]),
79
+ 'thoughts_headline': redact(str(kvps.get('headline',''))[:200]),
80
+ 'target_json': redact(json.dumps({
81
+ 'thoughts': kvps.get('thoughts', []),
82
+ 'headline': kvps.get('headline',''),
83
+ 'tool_name': tool_name,
84
+ 'tool_args': tool_args,
85
+ }, ensure_ascii=False)),
86
+ }
87
+ records.append(rec)
88
+ return records
89
+
90
+ def main():
91
+ chat_globs = sys.argv[1:] or ['/a0/usr/chats/*/chat.json']
92
+ all_records = []
93
+ for g in chat_globs:
94
+ for cp in sorted(glob.glob(g)):
95
+ try:
96
+ recs = extract_chat(cp)
97
+ print(f'{cp}: {len(recs)} tool calls', file=sys.stderr)
98
+ all_records.extend(recs)
99
+ except Exception as e:
100
+ print(f'{cp}: SKIP ({e})', file=sys.stderr)
101
+ out = '/a0/usr/archive/armft/a0-toolcall-sft-v1.jsonl'
102
+ with open(out, 'w') as f:
103
+ for r in all_records:
104
+ f.write(json.dumps(r, ensure_ascii=False) + '\n')
105
+ print(f'WROTE {len(all_records)} records -> {out}', file=sys.stderr)
106
+
107
+ if __name__ == '__main__':
108
+ main()