Skip to content

Commit 96c9e97

Browse files
authored
Merge pull request #11 from binghe2727/main
Add a-evolve tb2 harness for clawcode
2 parents 7eeed36 + a04b215 commit 96c9e97

9 files changed

Lines changed: 448 additions & 0 deletions

File tree

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Terminal-Bench 2 (TB2) — Experiment Report
2+
3+
Terminal-Bench 2 is an 89-task benchmark where an LLM agent solves command-line challenges inside Docker containers. Each task provides a prompt, a container image, and a `test.sh` evaluation script. The agent interacts via `bash()`, `python()`, `read_skill()`, and `submit()` tools in a ReAct loop.
4+
5+
This document describes how we run TB2, the task-guidance prompt and evolved skills used, and the results we obtained.
6+
7+
---
8+
9+
## Task-Guidance Prompt
10+
11+
Before each task, the agent receives the following system prompt (see [`prompt.md`](prompt.md)):
12+
13+
```text
14+
You are an AI assistant tasked with solving command-line tasks in a Linux environment.
15+
You will be given a task description and the output from previously executed commands.
16+
You have several tools available to help with finding the solution. You are running as
17+
root inside a Docker container. Do not use sudo — it is not installed and not needed
18+
since you already have root privileges.
19+
20+
Your goal is to solve the task by providing batches of shell commands. If you need to
21+
perform multiple actions, you can always send more messages with additional tool calls.
22+
23+
Before taking action, you should:
24+
1. ANALYZE the current state based on previous tool outputs
25+
2. PLAN your next steps — what commands will you run and why
26+
27+
Format your reasoning as follows before calling tools:
28+
29+
**Analysis:** [Analyze the current state.]
30+
**Plan:** [Describe your plan for the next steps.]
31+
32+
Then call the appropriate tools to execute your plan.
33+
34+
Important: Each bash() call is independent — no state is preserved between calls.
35+
If you need to run commands in sequence, chain them with &&
36+
37+
After you think you have completed the task, read the self-verification skill to
38+
verify your solution.
39+
40+
When you have completed and verified the task, call the submit() tool with "DONE"
41+
as argument to report that the task is complete.
42+
```
43+
44+
Key design choices in this prompt:
45+
46+
- Explicit Analysis → Plan reasoning structure before every tool call.
47+
- Reminder that `bash()` calls are stateless — commands must be chained with `&&`.
48+
- A self-verification nudge: the agent is told to `read_skill("self-verification")` before submitting, which loads a checklist that catches common mistakes.
49+
50+
---
51+
52+
## Evolved Skills (7 Total)
53+
54+
Skills are Markdown documents loaded on-demand via the `read_skill(name)` tool. Seven skills were produced by the A-EVOLVE adaptive_skill pipeline.
55+
56+
### Skill Overview
57+
58+
| # | Skill | Note | Purpose |
59+
|---|-------|--------|---------|
60+
| 1 | `self-verification` | Seed | Checklist to verify every requirement before calling `submit()` |
61+
| 2 | `environment-discovery` | Seed | Quickly discover tools, languages, and files in the container |
62+
| 3 | `debug-and-fix` | Seed | Fix build failures, write structured output, solve constraint tasks |
63+
| 4 | `scientific-computing` | Seed | Numerical methods, bioinformatics, ML training, logic circuits |
64+
| 5 | `build-compiled-extensions` | Seed | Build C/C++/Cython/Fortran extensions and frameworks from source |
65+
| 6 | `python-data-analysis` | Seed | Multi-step Python, HuggingFace datasets, stateless `python()` patterns |
66+
| 7 | `systematic-exploration` | Seed | Avoid dead ends, backtrack when stuck, verify interpretations |
67+
68+
Skills are stored in `skills/<name>/SKILL.md` and injected into the conversation when the agent calls `read_skill("<name>")`.
69+
70+
### Skills
71+
72+
- `self-verification` — A four-step checklist (re-read requirements → verify each one → check assumptions → review common pitfalls). Invoked automatically before submission thanks to the prompt nudge.
73+
- `environment-discovery` — One-liner commands to probe the container (`which`, `ls /app/`, `pip list`, etc.) so the agent doesn't waste turns guessing what's installed.
74+
- `debug-and-fix` — Recipes for C/C++ build fixes, binary inspection without `xxd`, writing complete structured files (ICS/JSON/XML) via Python to avoid heredoc truncation, and systematic constraint-satisfaction solvers.
75+
- `scientific-computing` — Patterns for bioinformatics (primer design, FASTA parsing), logic-circuit simulation, numerical optimization with SciPy, and ML training on CPU-only containers.
76+
- `build-compiled-extensions` — Step-by-step workflows for Cython, GCC manual builds, large framework compilation (Caffe, OpenCV), and protobuf version mismatch fixes.
77+
- `python-data-analysis` — Encodes the critical rule that each `python()` call starts with a blank slate (no state carries over). Default strategy: write a complete `.py` script to a file, then execute it via `bash()`. Includes patterns for HuggingFace dataset loading, token counting, and saving intermediate state to disk between calls.
78+
- `systematic-exploration` — Meta-strategies for when the agent gets stuck: don't reject an approach after a single failure (vary parameters widely first), backtrack after 5+ unproductive turns, verify task interpretation before committing, and treat independent requirements separately.
79+
80+
---
81+
82+
## Results on TB2
83+
84+
We compare two configurations:
85+
86+
- **Baseline** — Vanilla harness, no skills, default system prompt.
87+
- **Opus 4.6 + Evolved Skills** — The full setup described above: updated task-guidance prompt with self-verification nudge and all 7 skills.
88+
89+
### Per-Run Results
90+
91+
| Run | Configuration | Pass Rate |
92+
|-----|---------------|-----------|
93+
| 1 | Baseline | 67.1% |
94+
| 2 | Baseline | 67.0% |
95+
| 3 | Baseline | 69.4% |
96+
| 4 | Opus 4.6 + Evolved Skills | 74.1% |
97+
| 5 | Opus 4.6 + Evolved Skills | 69.4% |
98+
| 6 | Opus 4.6 + Evolved Skills | 75.3% |
99+
100+
### Summary
101+
102+
| Configuration | Avg Pass Rate | Range |
103+
|---------------|---------------|-------|
104+
| Baseline | 67.8% | 67.0–69.4% |
105+
| Opus 4.6 + Evolved Skills | 72.9% | 69.4–75.3% |
106+
| **Improvement** | **+5.1 pp** | |
107+
108+
---
109+
110+
## What Drove the Improvement
111+
112+
The gain comes from four changes layered on top of the baseline:
113+
114+
1. **The evolved skills** — Skills address the common failure modes (e.g., stateless `python()` confusion and premature approach abandonment.)
115+
2. **Self-verification nudge in prompt** — The explicit instruction to read the `self-verification` skill before submitting catches last-mile mistakes.
116+
117+
---
118+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
You are an AI assistant tasked with solving command-line tasks in a Linux environment.
2+
You will be given a task description and the output from previously executed commands.
3+
You have several tools available to help with finding the solution. You are running as root inside a Docker container. Do not use sudo - it is not installed and not needed since you already have root privileges.
4+
5+
Your goal is to solve the task by providing batches of shell commands. If you need to perform multiple actions, you can always send more messages with additional tool calls.
6+
7+
Before taking action, you should:
8+
1. ANALYZE the current state based on previous tool outputs
9+
2. PLAN your next steps - what commands will you run and why
10+
11+
Format your reasoning as follows before calling tools:
12+
13+
**Analysis:** [Analyze the current state. What do you see? What has been accomplished? What still needs to be done?]
14+
15+
**Plan:** [Describe your plan for the next steps. What commands will you run and why? Be specific about what you expect each command to accomplish.]
16+
17+
Then call the appropriate tools to execute your plan.
18+
19+
Important: Each bash() call is independent - no state is preserved between calls. If you need to run commands in sequence, chain them with &&
20+
21+
After you think you have completed the task, read the self-verification skill to verify your solution.
22+
23+
When you have completed and verified the task, call the `submit()` tool with "DONE" as argument to report that the task is complete.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: build-compiled-extensions
3+
description: How to build C/C++/Cython/Fortran extensions and frameworks like Caffe, OpenCV, protobuf-dependent projects from source.
4+
---
5+
6+
# Building Compiled Extensions & Frameworks
7+
8+
## Pre-flight
9+
```bash
10+
pip install setuptools wheel cython 2>/dev/null
11+
apt-get install -y build-essential python3-dev 2>/dev/null
12+
```
13+
14+
## Cython extension workflow
15+
```bash
16+
cython file.pyx # Cythonize to .c first
17+
python setup.py build_ext --inplace 2>&1
18+
# Manual fallback:
19+
gcc -shared -fPIC -O2 $(python3-config --includes) -o mod$(python3-config --extension-suffix) mod.c
20+
```
21+
22+
## Building large C++ frameworks (Caffe, etc.)
23+
1. Check protobuf version: `protoc --version` and `dpkg -l | grep protobuf`
24+
2. Fix API incompatibilities before building (see debug-and-fix skill)
25+
3. Use `make -j$(nproc)` but capture errors: `make 2>&1 | tee build.log`
26+
4. For Caffe specifically:
27+
- Set `CPU_ONLY := 1` in Makefile.config for non-GPU environments
28+
- Fix protobuf SetTotalBytesLimit calls for newer protobuf
29+
- Use `make all -j$(nproc) && make test && make runtest`
30+
31+
## When pip install times out
32+
1. Install dependencies individually first: `pip install numpy scipy`
33+
2. Build extensions only: `python setup.py build_ext --inplace`
34+
3. Or: `pip install --no-deps -e .`
35+
36+
## Common pitfalls
37+
- **Missing numpy headers**: `pip install numpy` before building numpy-dependent C extensions
38+
- **Import from wrong dir**: Test from `/tmp`, not the source directory
39+
- **Protobuf mismatch**: Check version and fix API calls before compiling
40+
41+
## Verification
42+
```bash
43+
find . -name "*.so" -newer setup.py
44+
cd /tmp && python -c "import mypackage; print('OK')"
45+
```
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
name: debug-and-fix
3+
description: Strategies for debugging build failures, runtime errors, writing complete output files (ICS/JSON/config), and constraint satisfaction tasks.
4+
---
5+
6+
# Debug and Fix Skill
7+
8+
## 1. C/C++ build fixes
9+
```bash
10+
apt-get update && apt-get install -y build-essential pkg-config
11+
```
12+
### Protobuf API fix
13+
```bash
14+
find . -name "*.cc" -o -name "*.cpp" | xargs sed -i \
15+
's/SetTotalBytesLimit(\([^,]*\),[^)]*)/SetTotalBytesLimit(\1)/g'
16+
```
17+
18+
## 2. Binary inspection without xxd
19+
```bash
20+
od -A x -t x1z -v file.dat | head -100
21+
```
22+
23+
## 3. Writing complete structured output files
24+
Use Python to write ICS/JSON/XML — avoids heredoc truncation:
25+
```python
26+
from datetime import datetime
27+
lines = ['BEGIN:VCALENDAR','VERSION:2.0','BEGIN:VEVENT',
28+
f'DTSTART:{start:%Y%m%dT%H%M%S}',
29+
f'DTEND:{end:%Y%m%dT%H%M%S}',
30+
f'SUMMARY:{title}',
31+
'END:VEVENT','END:VCALENDAR']
32+
with open('/app/out.ics','w') as f:
33+
f.write('\r\n'.join(lines)+'\r\n')
34+
```
35+
36+
## 4. Scheduling / constraint satisfaction
37+
- Parse ALL constraints before attempting solutions
38+
- Write a systematic solver to a .py file (enumerate candidates, check all constraints)
39+
- Verify solution satisfies EVERY constraint before writing output
40+
```python
41+
# Write complete solver to file to avoid truncation:
42+
with open('/app/solver.py','w') as f:
43+
f.write('''...all imports, logic, output...''')
44+
# Then run: python3 /app/solver.py
45+
```
46+
47+
## 5. Implementation code
48+
- Write complete files — don't build up fragments
49+
- For complex logic, use Python to write files programmatically
50+
- Test immediately after writing
51+
- If tests fail, rewrite the COMPLETE file
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
name: environment-discovery
3+
description: Strategies for quickly discovering what tools, languages, and files are available in a Terminal-Bench container.
4+
---
5+
6+
# Environment Discovery Skill
7+
8+
When starting a new Terminal-Bench challenge, quickly assess the environment.
9+
10+
## 1. Check available tools and languages
11+
```bash
12+
which python python3 pip node npm gcc g++ make cmake perl ruby 2>/dev/null
13+
```
14+
15+
## 2. Check the filesystem
16+
```bash
17+
ls /app/ 2>/dev/null
18+
find /app -type f 2>/dev/null | head -30
19+
```
20+
21+
## 3. Check pre-installed task-specific tools
22+
Many containers have specialized tools already installed:
23+
```bash
24+
# Security/crypto tools
25+
which john hashcat 7z 7za openssl 2>/dev/null
26+
ls /app/john/run/ 2>/dev/null
27+
# Bio tools
28+
which oligotm primer3_core samtools 2>/dev/null
29+
# Data tools
30+
pip list 2>/dev/null | head -30
31+
```
32+
33+
## 4. If python3 is missing, try alternatives
34+
```bash
35+
which python perl 2>/dev/null # python2 may exist as 'python'
36+
# Use perl for text processing if python unavailable
37+
# Use /app/john/run/john for password cracking (has its own perl scripts)
38+
```
39+
40+
## 5. Pre-installed tool locations
41+
- John the Ripper scripts: `/app/john/run/*.pl` (perl-based, use `perl` not `python3`)
42+
- Task binaries often in `/app/` or `/usr/local/bin/`
43+
44+
## Tips
45+
- Check `/app/` first — it often contains task-specific files and tools
46+
- Don't assume python3 exists — verify first, use bash/perl alternatives
47+
- Use `dpkg -l` or `apt list --installed` to see system packages
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
name: python-data-analysis
3+
description: Best practices for multi-step Python tasks including data analysis, HuggingFace datasets, token counting, and any task requiring state across multiple python() calls.
4+
---
5+
6+
# Python Multi-Step Tasks
7+
8+
## RULE #1: Each python() call starts fresh — NO state carries over
9+
Variables, imports, data from previous calls DO NOT EXIST. This is the #1 source of NameError.
10+
11+
**DEFAULT STRATEGY: Write a complete .py script to a file, then run it.**
12+
13+
```python
14+
with open('/app/solve.py', 'w') as f:
15+
f.write('''#!/usr/bin/env python3
16+
import numpy as np
17+
# ALL logic in one file
18+
data = np.load("/app/data.npy")
19+
result = process(data)
20+
with open("/app/answer.txt","w") as out:
21+
out.write(str(result))
22+
''')
23+
```
24+
Then: `bash("python3 /app/solve.py && cat /app/answer.txt")`
25+
26+
## If you must use multiple python() calls:
27+
1. **Save state to files between calls:**
28+
```python
29+
import json, numpy as np
30+
# Save: json.dump(obj, open('/tmp/state.json','w'))
31+
# Save: np.save('/tmp/arr.npy', array)
32+
# Load: obj = json.load(open('/tmp/state.json'))
33+
```
34+
2. **Every call MUST re-import and re-load** — never reference prior variables
35+
3. **NameError = forgot to re-define** — add missing definitions, don't just re-run
36+
37+
## HuggingFace Datasets + Token Counting (ONE call)
38+
```python
39+
from datasets import load_dataset
40+
from transformers import AutoTokenizer
41+
ds = load_dataset("org/name", split="train")
42+
tok = AutoTokenizer.from_pretrained("model-name")
43+
total = sum(len(tok.encode(r["text"])) for r in ds if r["domain"] == "science")
44+
with open("/app/answer.txt","w") as f: f.write(str(total))
45+
```
46+
47+
## For iterative exploration, keep blocks self-contained
48+
```python
49+
# Each block: imports + load + process + print
50+
import pandas as pd
51+
df = pd.read_csv('f.csv')
52+
print(df.describe())
53+
```
54+
55+
## Verification
56+
- Print/cat output files BEFORE submitting
57+
- Confirm formats match expected schema exactly
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
name: scientific-computing
3+
description: Strategies for scientific computing, numerical methods, bioinformatics/DNA tasks, logic circuit design, algorithmic challenges, and ML training tasks.
4+
---
5+
6+
# Scientific Computing & Algorithmic Tasks
7+
8+
## CRITICAL: Write complete scripts to files for complex tasks
9+
Multi-step scientific analysis MUST be written as a single .py file to avoid state loss:
10+
```python
11+
with open('/app/solve.py', 'w') as f:
12+
f.write("""#!/usr/bin/env python3
13+
import numpy as np
14+
# ... complete self-contained solution ...
15+
""")
16+
# Then run: bash("python3 /app/solve.py")
17+
```
18+
19+
## Bioinformatics / DNA primer design
20+
- Use `oligotm` CLI if available for Tm calculation (check with `which oligotm`)
21+
- Use `primer3_core` if available for automated primer design
22+
- Key Tm parameters: `-tp 1 -sc 1 -mv 50 -dv 2 -n 0.8 -d 500` (Santa Lucia, salt-corrected)
23+
- Primer length: 15-30 bp, GC content 40-60%, Tm 55-65°C
24+
- For Gibson/Golden Gate assembly: add overlaps/BsaI sites to 5' end of primers
25+
- Parse FASTA files: handle multi-line sequences, strip whitespace
26+
- Write results in FASTA format to the expected output path
27+
28+
## Logic circuit / hardware design
29+
- Read simulator code FIRST to understand gate semantics and timing
30+
- Key patterns: ripple-carry adder, mux, shift register
31+
- For Fibonacci mod 2^N: doubling method or iterative with registers
32+
33+
## Numerical / distribution tasks
34+
- For optimization: use scipy.optimize (fsolve, minimize, root)
35+
- When searching distributions: verify KL divergence, entropy constraints
36+
- Always validate: check sums to 1, non-negative, constraint satisfaction
37+
38+
## ML training tasks
39+
- Check GPU: `python3 -c "import torch; print(torch.cuda.is_available())"`
40+
- CPU-only: smaller batch size, simpler models, fewer epochs
41+
- Save checkpoints frequently
42+
43+
## Verification
44+
- Verify output format matches task specification exactly
45+
- Save results to exact paths mentioned in task prompt
46+
- Compare against reference values for correctness

0 commit comments

Comments
 (0)