Skip to main content

The Insight

Agent tool-call sequences are approximately first-order Markov chains. The probability of the next tool call depends primarily on the current tool call, not the full history. This means we can apply well-studied stochastic process analysis to understand agent behavior.

The 9-State Taxonomy

Every tool call maps to one of nine behavioral states:
StateDescriptionExample Tools
ORIENTUnderstanding the taskRead prompt, list files
READReading existing codeRead file, search code
EDITModifying codeWrite file, edit file
BUILDCompilingRun maven/gradle build
TESTRunning testsExecute test suite
JAR_INSPECTExamining dependenciesInspect JAR contents
SEARCHBroad explorationGrep, glob, web search
METAAgent self-managementTask creation, planning
TERMINALDoneSuccess or failure

What Markov Analysis Reveals

Transition Probability Engineering (TPE)

The transition matrix P(next_state | current_state) is the agent’s “behavioral fingerprint.” Different variants produce measurably different fingerprints.

Key Metrics

  • Expected steps to completion — From the fundamental matrix N = (I - Q)^
  • P(success) — Absorbing chain probability of reaching success vs. failure
  • Thrash score — Loop amplification in BUILD→TEST→EDIT cycles
  • JAR cluster % — Time spent in dependency inspection (correlates with knowledge availability)

What We’ve Found

From Code Coverage v1:
  1. Knowledge reduces JAR inspection — Variants with domain knowledge spend less time inspecting dependencies
  2. Thrashing predicts failure — High BUILD→TEST→EDIT loop counts correlate with lower T3 scores
  3. SAE changes the fingerprint — Structured Agent Execution produces measurably different transition matrices
  4. Two independent axes — Knowledge injection and prompt hardening affect different parts of the transition matrix

Tools

The analysis pipeline is implemented in the markov-agent-analysis Python library.
Key function: build_absorbing_chain_from_traces() — transforms raw tool-call logs into absorbing Markov chains.

Role in the Growth Cycle

Markov analysis is the primary diagnostic lens in the DIAGNOSE step of the Improvement Flywheel. It converts raw tool-call traces into actionable signals about where the agent gets stuck and why.

Loop Amplification Signals

SignalDiagnosisLever
Amplification > 2.0 on BUILD→FIX→BUILDAgent is in a fix loop — build fails, fix attempt fails, rebuild failsKnowledge (Lever 2) or deterministic tool (Lever 3)
Amplification > 2.0 on SEARCH statesAgent is searching for something it can’t findAdd the target information to knowledge/ (Lever 2)
Amplification > 2.0 on EXPLOREAgent is reading many files without making progressClarify task decomposition in prompt (Lever 1) or pre-analysis script (Lever 3)

Transition Gap Signals

SignalDiagnosisLever
VERIFY never reachedAgent produces output but doesn’t confirm correctnessAdd stopping condition to prompt (Lever 1)
READ_KB never reachedAgent ignores knowledge filesReference knowledge files in prompt, improve routing table (Lever 1)
WRITE reached late (after many EXPLORE/SEARCH cycles)Agent spends too long understanding before actingTemplates, scaffolding, explicit first steps (Lever 3)

Failure Pattern Signals

SignalDiagnosisLever
Error state reachable from multiple pathsStructural/tooling issueFix the tooling, not the agent (Lever 3)
Single dominant failure path (BUILD → ERROR 80%)Invalid strategyChange strategy, not retry count (Lever 1 or 2)
Agent stops after N fix attemptsCapability ceilingAdd fix pattern to knowledge (Lever 2) or restructure task (Lever 3)

Loop Type Classification

Not all loops are problems. Classify before intervening:
Loop TypePatternAction
ProductiveWRITE → VERIFY → FIX → VERIFYLeave it alone
FrictionSEARCH → READ → SEARCH → READAdd knowledge or routing
FailureBUILD → FIX → BUILD → FIX (same error)Change strategy
DiagnosticBUILD → ERROR → READ_LOG → FIXLeave it alone
DegenerateEXPLORE → EXPLORE → EXPLOREIntervene — agent is stuck

Improvement Flywheel

The feedback loop that this analysis drives

Forge Methodology

Define → Forge → Run → Grow pipeline

Blog: I Read My Agent's Diary

Narrative walkthrough of the Markov analysis

Agent Journal

The trace capture layer that feeds this analysis