Bayesian-Agent: A Bayesian Self-Evolving Agent Framework with Cross-Harness Adaptation
π English | π¨π³ δΈζ |
π Docs |
π GitHub |
π arXiv:2606.08348
Bayesian-Agent is a Bayesian self-evolving layer for turning verified agent trajectories into reusable, evidence-weighted Skills and SOPs across agent frameworks and execution harnesses.
It supports three usage patterns:
- Run from scratch: start with no prior traces and evolve Skills during full benchmark or production runs.
- Repair incrementally: attach to an existing agent, read its failed trajectories, and rerun only the tasks that need repair.
- Run native or adapt across harnesses: use the first-party Bayesian-Agent harness by default, or integrate with GenericAgent, mini-swe-agent, Claude Code, and other runtimes through a portable trajectory schema and adapter boundary.
v0.5 adds a first-party native harness on top of the Bayesian Skill Evolution core. GenericAgent, mini-swe-agent, and Claude Code are compatibility backends; they are not copied, vendored, or forked.
π
News
- 2026-06-09: The Bayesian-Agent paper is now available on arXiv: arXiv:2606.08348.
- 2026-06-05: Added full-sample native-harness results for SOP-Bench, Lifelong AgentBench, and RealFin-Bench with
deepseek-v4-flash and deepseek-v4-pro; see Experimental Results.
- 2026-06-05: Added the first-party Bayesian-Agent native harness. It runs its own LLM loop, workspace tools, optional three-layer memory, and trajectory capture; GenericAgent, mini-swe-agent, and Claude Code remain optional compatibility backends. See the Native Harness design note.
- 2026-05-31: Added the Bayesian Evidence Model as the default Skill belief backend, with a categorical likelihood implementation and a legacy Beta-Bernoulli backend for ablations.
- 2026-05-09: Released Bayesian-Agent as a standalone cross-harness Bayesian Skill Evolution package with schemas, CLI utilities, and experiment artifacts.
- 2026-05-09: Added the optional GenericAgent adapter boundary without copying or vendoring GenericAgent.
- 2026-05-09: Published bilingual project documentation and the Bayesian-Agent framework diagram.
π Overview
Prompt Engineering improves task instructions. Context Engineering controls what evidence the model sees at inference time. Harness Engineering puts the model inside an observable, executable, recoverable system with tools, files, tests, memory, logs, and failure recovery.
In this setting, Skills and SOPs become first-class engineering assets. A good Skill is compressed operational knowledge:
- what to inspect first
- which tools to use
- how to verify progress
- which failure modes to avoid
- when to stop, retry, or rewrite the procedure
Bayesian-Agent treats Skills as hypotheses about how to solve tasks. Verified trajectories become evidence for updating, ranking, rewriting, compressing, or retiring those Skills. The same evolution layer can bootstrap Skills from scratch, repair existing agents incrementally, and move across harnesses that emit compatible trajectories.
Bayesian-Agent turns verified trajectories from any compatible harness into evidence-ranked Skills and executable SOP patches.
π§ Core Idea
Most LLM engineering interventions fall into two MECE routes:
- Change the model parameter distribution, such as pretraining, fine-tuning, and reinforcement learning.
- Change the inference condition, such as prompts, context, RAG, tools, memory, and harnesses.
Bayesian-Agent focuses on the second route.
If a base model samples from:
P(X | theta)
then an agent system samples from:
P(X | theta, C)
where C is the inference environment. Skills, SOPs, tools, memory, retrieved evidence, execution traces, and verifier feedback are all part of C.
Bayesian-Agent treats each Skill or SOP as a hypothesis about success:
P(success | theta, C, skill)
After each verified trajectory, the framework updates a posterior belief over that Skill. The posterior is used internally for Skill ranking, rewrite decisions, and failure-mode patches; model-facing benchmark prompts receive executable Skill/SOP text instead of raw probability summaries.
Why Bayesian Instead of Plain Frequency Counting
The surface behavior of Bayesian-Agent may look like failure-driven Skill repair: inspect a trajectory, find what went wrong, and patch the Skill. The Bayesian advantage is that the framework does not only store the patch. It also maintains a posterior belief about when the Skill should be trusted.
Agent runs are expensive: tokens are expensive, latency is high, benchmark cases are limited, and real production failures are even rarer. When samples are scarce, each sample is costly, and we cannot wait for large-sample statistics to stabilize, Bayesian modeling lets Bayesian-Agent combine prior belief, uncertainty, and new verified evidence into more stable decisions.
Bayesian-Agent is most useful for sample-scarce, cost-sensitive, online Skill/SOP evolution. Read the full explanation in Why Bayesian for Skill Evolution.
What "Bayesian" Means in v0.5
Current Bayesian-Agent v0.5 defaults to a Bayesian Evidence Model for each Skill/SOP. The default implementation is a feature-conditioned categorical likelihood model: it estimates whether a Skill will succeed under observed evidence features such as task context, failure mode, token bucket, turn bucket, latency bucket, and selected metadata.
For a Skill hypothesis h_k, evidence D_k = {(x_i, y_i)} contains discrete features x_i and verified labels y_i in {success, failure}:
P(y | h_k) = (N_y + alpha) / (N + alpha * |Y|)
P(x_j = v | y, h_k) = (N_{j,v,y} + alpha) / (N_{j,y} + alpha * |V_j|)
P(y = success | h_k, x) β P(y = success | h_k) * Ξ _j P(x_j | y = success, h_k)
The implementation uses Laplace smoothing with alpha = 1. This is Bayesian in the posterior-belief sense: verified experience updates the probability of a Skill succeeding under a particular context and runtime signature. The default backend is exposed as algorithm="categorical_bayes"; algorithm="naive_bayes" remains accepted as a legacy alias for the same factorized categorical likelihood.
The current likelihood model uses five fixed categorical evidence terms plus optional short metadata terms:
| Evidence term |
Why it is included |
context |
Captures task family, benchmark, or harness context. |
failure_mode |
Captures reusable error patterns that can become concrete Skill/SOP patches. |
token_bucket |
Captures whether a trajectory succeeded cheaply or only after expensive search. |
turn_bucket |
Captures recovery loops and interaction complexity. |
latency_bucket |
Captures slow tool, data, or API paths that may require different SOPs. |
metadata.* |
Adds harness-specific short scalar diagnostics without baking one harness schema into the core. |
metadata.* features are included only when the value is a short scalar (str, int, float, or bool, with string length at most 80). Runtime numbers are bucketed before entering the likelihood model so sparse exact values do not dominate early evidence.
For compatibility and ablation, the original Beta-Bernoulli posterior is still available via algorithm="beta_bernoulli" or bayesian-agent evolve --algorithm beta_bernoulli:
p_k | D_k ~ Beta(alpha_0 + s_k, beta_0 + f_k)
E[p_k | D_k] = (alpha_0 + s_k) / (alpha_0 + beta_0 + s_k + f_k)
Both backends feed the same Skill ranking, posterior audit rendering, and rewrite actions such as patch, split, compress, retire, and explore. Full Bayesian model selection over competing Skill hypotheses is planned, but not claimed in v0.5.
π Core Features
- Evidence-weighted Skill evolution: update Skill beliefs from verified success and failure trajectories.
- Bayesian Skill registry: maintain Bayesian Evidence Model beliefs, optional Beta-Bernoulli posteriors, failure modes, token cost, latency, turns, and context distribution.
- Failure-mode-aware repair: identify recurring errors and generate focused repair plans.
- Catalog-first Skill evolution by default: use handwritten benchmark catalogs as high-precision failure taxonomies and patch rules when they are available.
- Zero-shot automatic failure discovery (opt-in): with
--no-use-skill-catalog, infer generic failure modes from verifier errors, scores, requested artifacts, and trajectory metadata.
- Trajectory-to-Skill distillation: in zero-shot mode, convert repeated discovered failure modes into executable patch rules without requiring a benchmark-specific catalog.
- Overfitting-resistant patch activation: keep single failures as audit evidence, and promote a failure-mode patch into the benchmark prompt only after at least two verified occurrences.
- Token-aware context building: select concise, evidence-backed Skill/SOP text; benchmark prompts receive executable patches and guardrails, while posterior numbers stay in artifacts.
- First-party native harness: run an OpenAI-compatible LLM loop, workspace tools, optional three-layer memory, and trajectory logging inside Bayesian-Agent itself. Native memory prompt/state updates are disabled by default and can be enabled with
--native-memory.
- Full self-evolution from scratch: run all tasks, collect evidence online, and evolve Skills without prior traces.
- Incremental repair for existing agents: consume failed trajectories from a baseline agent and rerun only the failed tasks.
- Cross-harness adaptation: use BA native by default, or integrate with GenericAgent, mini-swe-agent, Claude Code, and other frameworks through adapters instead of vendoring their code.
- Standard-library-first core: the core package has no runtime dependency beyond Python.
𧬠Self-Evolution Mechanism
Bayesian Skill Evolution framework.
[Agent Trajectory]
|
v
[Verifier / Benchmark Grader]
|
v
[TrajectoryEvidence: success, failure mode, tokens, turns, latency]
|
v
[Bayesian Skill Registry: posterior + cost + contexts]
|
v
[Rewrite Policy: compress, patch, split, retire, explore]
|
v
[Executable Skill Patches / Guardrails]
|
v
[Next Agent Run]
For each Skill or benchmark SOP, Bayesian-Agent maintains:
- a Bayesian Evidence Model over success and failure conditioned on evidence features
- an optional Beta-Bernoulli posterior over global success probability
- verified success and failure evidence
- failure mode counts
- input, output, and total token statistics
- latency and turn statistics
- context distribution
- rewrite policy recommendations
The default rewrite policy is intentionally small and matches the current implementation:
| Policy action |
Current trigger |
Why |
explore |
no observations, or posterior remains uncertain |
Avoids rewriting before verified evidence exists. |
retire |
beta >= 4 and success_probability < 0.45 |
Avoids retiring after one or two unlucky failures, but removes clearly harmful Skills. |
patch |
one failure_mode appears at least twice |
Treats repeated failures as actionable evidence while avoiding one-off overfitting. |
split |
at least 3 contexts and at least 4 observations |
Prevents one broad SOP from covering incompatible task contexts. |
compress |
at least 3 observations and success_probability >= 0.72 |
Distills stable Skills to reduce token cost after enough positive evidence. |
These thresholds are conservative v0.5 heuristics, not claims of optimality. The design goal is an inspectable posterior-driven policy that can be swapped out by downstream harnesses.
Automatic Failure Discovery
Bayesian-Agent is catalog-first by default. The built-in benchmark catalogs remain the high-precision path for SOP-Bench, Lifelong AgentBench, and RealFin-Bench. To test a new benchmark without handwritten failure taxonomy, run with --no-use-skill-catalog; this switches the runner into zero-shot automatic failure discovery: