Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Behavior Shaping for Reliable Coding Agents
Hongli Zhan
Institute of Foundation Models (IFM)
Guest Lecture, Natural Language Processing
The University of Texas at Austin · November 2026
1
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
1
Why Behavior Matters
How behavior changes with training, and what pass or fail misses
2
Turn-Level Best-of-N Sampling
Make every turn better, not just the final outcome
3
Behavior Shaping with Rubrics
Ongoing work: a rubric-guided advisor, training data from its runs, and rubric rewards in RL
4
From Test-Time Help to Built-In Habits
Summary and open problems
2
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
K2 Horizon: Fully Open Models for Agentic Coding
A family of six models
From 0.9B to 375B parameters, dense and mixture-of-experts, with 512K context.
Fully open
Checkpoints, training data and training code are all released.
Strong agentic performance
The flagship 375B-A23B model passes 70.2% of attempts on Terminal-Bench 2.1.
But 70.2% is just one number. What can it tell us about what the agent actually does?
K2 Team, 2026 (arXiv 2611.21003).
3
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
How K2 Horizon Works on a Terminal-Bench Task
Task: write a MIPS interpreter in JavaScript (vm.js) that runs a compiled Doom binary, and save the first frame it renders.
turn 1 of 161
reasoning Explore the environment first: what is in /app, and what kind of file is the binary?
tool call $ ls -la /app; file /app/doomgeneric_mips
observation doom.wad doomgeneric/ doomgeneric_mips (MIPS ELF executable)
⋮
98 more turns (turns 2 to 99)
read the binary and the instruction set, first vm.js at turn 85, crash, patch, crash again
turn 100 of 161
reasoning The code relies on each branch delay slot running only once. Track them and skip them on return.
tool call patch vm.js; $ timeout 25 node vm.js
observation Error: unknown opcode 28 at 0x43a8ac (next crash)
⋮
60 more turns (turns 101 to 160)
add missing instructions, Doom boots at turn 119, chase a rendering crash, verify the frame
turn 161 of 161
reasoning vm.js boots Doom and saves the first frame as a valid 640x400 BMP. Confirm.
tool call mark_task_complete
observation graded by hidden tests → pass
A long-horizon task is a chain of decisions: 161 turns and about two hours here. The tests grade only the end.
Real K2-Horizon-375B trajectory: Terminal-Bench 2.1, make-mips-interpreter, Terminus-2 harness; text shortened.
4
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
What Changed When the Pass Rate Doubled
The pass rate says the model got better. The trajectories say which behaviors changed, and which training stage changed them.
K2-Horizon-375B on Terminal-Bench 2.1 across training checkpoints. Interrupt loop: 5+ consecutive turns of interrupt, exit or kill.
K2 Team, 2026 (arXiv 2611.21003).
5
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Behavior inside a trajectory matters.
But how can we steer it?
PRIOR WORK
Best-of-N over trajectories
Pick the best finished attempt. Still outcome-based.
→
THIS WORK
Best-of-N at every turn
Pick a better action at each turn, before it runs.
6
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
1
Why Behavior Matters
How behavior changes with training, and what pass or fail misses
2
Turn-Level Best-of-N Sampling
Make every turn better, not just the final outcome
3
Behavior Shaping with Rubrics
Ongoing work: a rubric-guided advisor, training data from its runs, and rubric rewards in RL
4
From Test-Time Help to Built-In Habits
Summary and open problems
7
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Part 1
Pick a Better Action at Every Turn
Bhandari*, Gupta*, Zhan*, Wang, Pimpalkhute, Liu, Xing, Srivastava
On Turn-Level Best-of-N Sampling for Scaling LLM Agents · arXiv 2611.06868 · *equal contribution
8
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Same Model, Different Outcomes
● K2-Horizon-375B ● Qwen3.6-35B Terminal-Bench 2.1, 89 tasks, 4 attempts each, no selection
pass@k: solved in at least one of k attempts
consistency@k: solved in at least k of 4 attempts
LLM agents are often inconsistent: the same model passes a task on some attempts and fails on others.
Actions are sampled from a stochastic policy, so every attempt can take a different path.
Run with the mini-SWE-agent harness, so numbers differ from the K2 tech report.
Bhandari, Gupta, Zhan et al., 2026 (arXiv 2611.06868).
9
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Turn-Level Best-of-N Sampling
Only the selected action runs: no extra sandboxes and no trained critic.
Bhandari, Gupta, Zhan et al., 2026 (arXiv 2611.06868).
10
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
What the Selector Picks
fix-ocaml-gc, turn 70: ./ocamlc just failed with "not found", but the file exists. The 8 candidates:
0 lists the compilers
1, 3, 4, 7 repeat the failed compile
2 checks the file types
5 reruns the failed compile
6 checks permissions, calls -version
"... the next step should diagnose why ... rather than blindly repeating the same failing command"
the selector
Baseline: 3 of 4 runs fail after 219 to 316 turns.
Turn-BoN: passes in 80 turns.
Qwen3.6-35B as the agent, Kimi-K3 as the selector, N = 8 (Appendix E, Figure 10a). Bhandari, Gupta, Zhan et al., 2026 (arXiv 2611.06868).
11
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
More Tasks Solved, More Consistently
pass@1: share of single attempts that pass
consistency@k: solved in at least k of 4 attempts
pass@1
+5 to 10%
and pass@k improves too
Consistency
higher
more tasks solved on all 4 attempts
Turns to solve
69.5 → 33.9
K2-Horizon-375B, N = 8
Terminal-Bench 2.1, 89 tasks, 4 attempts. pass@1 bars average the two selectors (Kimi-K3, DeepSeek-V4.1-Flash; Table 2).
Bhandari, Gupta, Zhan et al., 2026 (arXiv 2611.06868).
12
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
What the Selector Prefers at Each Turn
More doing: edits, tests and checks are picked more often than chance.
Less inspecting: actions that only read files drop.
Rare bad actions, such as unrunnable responses, are kept from running.
Terminal-Bench 2.1. Solid: the selector's pick; dashed: a random pick from the same N candidates (Figure 4).
Bhandari, Gupta, Zhan et al., 2026 (arXiv 2611.06868).
13
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Judging Whole Trajectories
An LLM judge reads each whole trajectory and flags 28 bad behaviors, without seeing whether it passed.
Base: share of baseline trajectories flagged. Δ: change with best-of-N. Green is better, red is worse.
Looping drops for both models. Qwen also tests its work more thoroughly.
36 hard tasks, 360 trajectories; * p < 0.05. Top 13 behaviors from Wang et al. (2026b), bottom 15 added by us (Table 3).
Bhandari, Gupta, Zhan et al., 2026 (arXiv 2611.06868).
14
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Even Failed Attempts Behave Better
K2-Horizon, failed attempts
Reruns a failed command
baseline
33%
best-of-N
10%
Ignores task instructions
baseline
28%
best-of-N
15%
Bad behaviors per attempt: 3.9 → 2.7 of 28
Qwen3.6, failed attempts
Retries without diagnosis
baseline
50%
best-of-N
26%
Tests that cannot fail
baseline
65%
best-of-N
47%
Bad behaviors per attempt: 8.9 → 6.8 of 28
A failed best-of-N attempt more often works through the task and still gets it wrong, instead of stalling in a bad habit.
Failed trajectories only across the same 36 hard tasks; an LLM judge flags 28 bad behaviors without seeing the outcome.
Bhandari, Gupta, Zhan et al., 2026 (arXiv 2611.06868).
15
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Part 1 takeaway:
Better choices at each turn bring better behaviors.
But we rely on the selector's judgment and cannot control it. To steer behavior, we first have to define good behavior.
16
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
1
Why Behavior Matters
How behavior changes with training, and what pass or fail misses
2
Turn-Level Best-of-N Sampling
Make every turn better, not just the final outcome
3
Behavior Shaping with Rubrics
Ongoing work: a rubric-guided advisor, training data from its runs, and rubric rewards in RL
4
From Test-Time Help to Built-In Habits
Summary and open problems
17
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Part 2
Behavior Shaping with Rubrics
From test-time help to training data, and a look at RL
Ongoing work at IFM
18
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Where the Rubrics Come From
1
Evaluate frontier models on a set of tasks
2
Study their evaluation trajectories
3
Compare with open-model attempts on the same task
4
Write the difference as a rule
5
Test the rule on new tasks
GPT-6 Astra
A command it relied on printed nothing useful. It reran it to see the real exit status, found a missing config and fixed it.
GLM-5.3
Its own comparison showed 9 config keys missing from the output. It checked some of them and reported success.
Rule: when a check contradicts your claim of success, resolve it before reporting success.
19
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
What a Rubric Looks Like
When something fails, read the error before you try again. Don't rerun the same command and hope. Once you've fixed it, run it again to show it works.
Follows the rule
Reads the error, fixes what it points to, and reruns the failing step to show it works.
Breaks the rule
Runs the same failing command again and again, or says it's fixed without checking.
One behavior, written to apply across tasks: the same habit the selector favored in part 1.
20
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
An Advisor That Steps In While the Agent Works
Block 1
R1
→
TC1
→
O1
→
TC2
→
O2
↑ review while R2 waits
Block 2
R2
→
TC3
→
O3
↑ review while R3 waits
Block 3
R3
→
TC4
→
O4
→
finish
↑ last review before submitting
which rubrics apply?
→
which are slipping?
→
pick one, or none
→
rewrite the waiting reply
R: reasoning · TC: tool call · O: output. At most 10 nudges per run; the advisor never sees the tests.
21
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
One Run, with the Advisor
Before
5 × FileNotFoundError:
'build_extra.py'
After the nudge
$ cat formats_extra.py
formats_extra.py parses ok
"Five attempts in a row, all the same ... Stop retrying. The ls I just ran printed the directory, and build_extra.py was NOT in it ... First READ what actually exists."
the nudge, written as the agent's own reasoning (shortened)
→ The agent reads the file it actually wrote, uses it, and the attempt passes.
22
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
At Test Time
23 hard tasks × 3 attempts
Agent alone
0 / 69
Agent rechecks itself
1 / 68
With advisor
5 passing attempts
5 / 69
Share of applicable rules broken
Agent alone
34%
With advisor
20%
Frontier model
5%
A blind judge tells agent from frontier runs at AUC 0.88 alone, 0.70 with the advisor.
The advisor closes about half the behavior gap to a frontier model; pass-rate gains are small.
GLM-5.3-Flash as agent and advisor on 23 hard Terminal-Bench 4 tasks. Right: Claude Opus 5.5 as blind judge; rubrics were mined on other tasks.
23
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Next: From Advised Runs to Training Data
agent + advisor on many tasks
→
nudges written in the agent's own voice
→
trajectories that show the habits we want
→
mid-training data for our models
● The trajectory reads as one agent noticing a slip and correcting itself.
● Goal: the model learns the habit itself, so no advisor is needed when it is deployed.
● The advisor's cost is paid once, when the data is generated.
24
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Where Our RL Training Loses Signal
55k coding task groups, 8 attempts each
All pass
47%
All fail
21%
Mixed
the only ones that teach
33%
264k
attempts generated, then dropped as zero-advantage; 137k were trained on
39% → 53%
share of all-pass groups, early vs. later training
Two thirds of the groups give GRPO no gradient, and the share grows as the model improves.
Coding tasks in the RL run of our current model; groups with infrastructure failures removed.
25
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
What a Rubric Score Could Add
One hard task, a group of 8 attempts, all fail the tests
Test reward
0
0
0
0
0
0
0
0
no signal
Rubric score
0.3
0.7
0.5
0.2
0.8
0.4
0.6
0.3
signal
The same holds when every attempt passes: the test reward cannot tell a careful pass from a lucky one.
Illustration, not real scores.
26
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Part 2 takeaway:
Rubrics make behavior measurable and steerable. They also show good potential as an RL reward.
27
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
1
Why Behavior Matters
How behavior changes with training, and what pass or fail misses
2
Turn-Level Best-of-N Sampling
Make every turn better, not just the final outcome
3
Behavior Shaping with Rubrics
Ongoing work: a rubric-guided advisor, training data from its runs, and rubric rewards in RL
4
From Test-Time Help to Built-In Habits
Summary and open problems
28
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Summary
Behavior matters: pass rate tells us whether an agent succeeds, not how it works.
Better choices at every turn make agents behave better and succeed more consistently.
Rubrics make good behavior explicit, so we can measure it and steer it.
Ongoing: turn test-time help into built-in habits, through training data and RL rewards.
29
Motivation
why behavior matters
Part 1
turn-level best-of-N
Part 2
behavior shaping
Conclusion
takeaways
Thank you!
Questions?
30