converge-core 1.0.0

Converge Agent OS - correctness-first, context-driven multi-agent runtime
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# Converge Core

> **Context is the only shared state.**
> **The engine decides; agents propose.**

A correctness-first, context-driven multi-agent runtime library.

[![Crates.io](https://img.shields.io/crates/v/converge-core.svg)](https://crates.io/crates/converge-core)
[![Documentation](https://docs.rs/converge-core/badge.svg)](https://docs.rs/converge-core)

**Website:** [converge.zone]https://converge.zone | **Docs:** [docs.rs]https://docs.rs/converge-core | **Crates.io:** [converge-core]https://crates.io/crates/converge-core

---

## What Is Converge Core?

Converge Core is the **foundational semantic engine** of the Converge ecosystem. It provides:

- **Context** — The single source of truth, append-only and typed
- **Engine** — The convergence loop that orchestrates agents to a fixed point
- **Agent Trait** — The contract for capabilities that observe and propose
- **Invariants** — Runtime constraints that guard correctness (Gherkin-style)
- **Capability Traits** — Interfaces that providers implement

### What Converge Core IS

| Aspect | Description |
|--------|-------------|
| **The authority** | The engine decides what becomes a Fact |
| **Context owner** | Context is the API; all collaboration happens through it |
| **Convergence guarantor** | Execution proceeds until a fixed point is reached |
| **Invariant enforcer** | Constraints are checked continuously and at convergence |
| **Trait definer** | Defines `Agent`, `LlmProvider`, `Embedding`, etc. |

### What Converge Core is NOT

| Anti-pattern | Why Not |
|--------------|---------|
| **Not a workflow engine** | No predefined steps; agents react to context |
| **Not an event bus** | No pub/sub; context changes trigger eligibility |
| **Not an actor system** | Agents never call each other; no message passing |
| **Not eventual consistency** | Convergence is explicit and observable |
| **Not provider implementations** | Providers live in `converge-provider` |

---

## Core Axioms

These are the non-negotiable principles that define Converge.

### 1. Context Is the Only Shared State

Agents do not call each other. They read Context and emit effects.
Context is the API.

### 2. Agents Propose, Engine Decides

Agents return `AgentEffect` containing `Fact` or `ProposedFact`.
The engine validates, merges, and commits.

### 3. Convergence Is Mandatory

Execution proceeds until:
- `Context_{n+1} == Context_n` (fixed point), or
- Budget exhausted, or
- Invariant failed

### 4. Correctness Over Availability

Wrong answers are worse than no answers.
Invariants block invalid states.

### 5. Determinism Is Transparent

Same input → same output.
All decisions are traceable.

### 6. LLMs Suggest, Never Decide

LLM outputs become `ProposedFact`, not `Fact`.
Validators promote proposals after verification.

---

## Converging Flow Principles

Beyond the core axioms, Converge is built on a systems-level understanding of **converging flows**.

### What Is a Converging Flow?

A converging flow is a goal-directed, multi-agent process where:
- Multiple partial perspectives iteratively reduce uncertainty
- Progress is measured by **reduction of ambiguity**, not by speed or steps completed
- Execution continues until a stable decision, artifact, or state is reached

### Canonical Phases

All flows decompose into six structural phases:

```
Intent → Framing → Exploration → Tension → Convergence → Commitment
```

If any phase is missing, the system oscillates, over-optimizes locally, or produces brittle outcomes.

### Flow Truths

**Intent must be explicit.** Without declared intent, convergence must not begin.

**Constraints precede exploration.** Exploration without surfaced constraints produces invalid outcomes.

**Tension is mandatory.** If multiple perspectives immediately agree without conflict, force contradiction search.

**Commitment freezes state.** The system must commit or explicitly defer — no ambiguous endings.

### Flow Classification

Flows are classified by dominant uncertainty:
- **Epistemic** ("What is true?") — high exploration, late commitment
- **Pragmatic** ("What works?") — bounded exploration, early feasibility pruning
- **Normative** ("What should be done?") — explicit values, narrative convergence
- **Strategic** ("What matters most?") — reframing loops, ranking under uncertainty

See [converge-business/knowledgebase/core-CONVERGING_FLOWS.md](../../converge-business/knowledgebase/core-CONVERGING_FLOWS.md) for the complete flow theory.

---

## Architecture

```
┌─────────────────────────────────────────────────────────────────┐
│                        converge-core                            │
│  The foundational layer. Depends on NOTHING in the ecosystem.   │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐         │
│  │   Engine    │    │   Context   │    │  Invariant  │         │
│  │  (decides)  │───▶│  (shared)   │◀───│  (guards)   │         │
│  └─────────────┘    └─────────────┘    └─────────────┘         │
│         │                  ▲                                    │
│         │                  │                                    │
│         ▼                  │                                    │
│  ┌─────────────┐    ┌─────────────┐                            │
│  │   Agent     │───▶│ AgentEffect │                            │
│  │ (proposes)  │    │  (buffered) │                            │
│  └─────────────┘    └─────────────┘                            │
│                                                                 │
│  Trait Definitions:                                             │
│  • Agent           • LlmProvider      • Embedding               │
│  • Invariant       • VectorRecall     • GraphRecall             │
│  • Reranking       • ModelSelector                              │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘
                              │ implements traits
┌─────────────────────────────────────────────────────────────────┐
│                     converge-provider                           │
│  Capability adapters (Anthropic, OpenAI, Gemini, etc.)          │
└─────────────────────────────────────────────────────────────────┘
                              │ uses providers in agents
┌─────────────────────────────────────────────────────────────────┐
│                      converge-domain                            │
│  Domain agents, use cases, business logic                       │
└─────────────────────────────────────────────────────────────────┘
```

### Dependency Rules

| Crate | May Depend On | Must NOT Depend On |
|-------|---------------|-------------------|
| `converge-core` | (nothing) | `converge-provider`, `converge-domain` |
| `converge-provider` | `converge-core` | `converge-domain` |
| `converge-domain` | `converge-core`, `converge-provider` ||

---

## Installation

```toml
[dependencies]
converge-core = "0.6"
```

## Related Crates

| Crate | Version | Description |
|-------|---------|-------------|
| **converge-core** | 0.6.2 | Runtime engine, agent traits, capabilities |
| [converge-provider]https://crates.io/crates/converge-provider | 0.2.4 | 14+ LLM providers, model selection |
| [converge-domain]https://crates.io/crates/converge-domain | 0.2.4 | 12 business use cases |

---

## Quick Start

```rust
use converge_core::{Engine, Context, ContextKey, Fact, Agent, AgentEffect};

// Define a simple agent
struct GreetingAgent;

impl Agent for GreetingAgent {
    fn name(&self) -> &str { "greeting" }
    fn dependencies(&self) -> &[ContextKey] { &[ContextKey::Seeds, ContextKey::Signals] }

    fn accepts(&self, ctx: &Context) -> bool {
        ctx.has(ContextKey::Seeds) &&
        !ctx.get(ContextKey::Signals).iter().any(|f| f.id.starts_with("greeting-"))
    }

    fn execute(&self, _ctx: &Context) -> AgentEffect {
        AgentEffect::with_fact(Fact::new(
            ContextKey::Signals,
            "greeting-response",
            "Hello from Converge!",
        ))
    }
}

fn main() {
    let mut engine = Engine::new();
    engine.register(GreetingAgent);

    let mut ctx = Context::new();
    ctx.add_fact(Fact::new(ContextKey::Seeds, "input", "Start")).unwrap();

    let result = engine.run(ctx).expect("should converge");
    println!("Converged in {} cycles", result.cycles);
}
```

---

## Core Types

### Context

The shared, typed, evolving state of a job.

```rust
pub struct Context {
    // Internally organized by ContextKey
    // Seeds → Signals → Hypotheses → Strategies → Evaluations
}

pub enum ContextKey {
    Seeds,       // Initial input data
    Signals,     // Observations and discoveries
    Hypotheses,  // Tentative conclusions
    Strategies,  // Proposed solutions
    Evaluations, // Quality assessments
    Constraints, // Domain constraints
    Proposals,   // Pending LLM suggestions
    Approvals,   // Human-approved items
}
```

### Agent

A capability that reads context and emits effects.

```rust
pub trait Agent: Send + Sync {
    /// Unique name for this agent
    fn name(&self) -> &str;

    /// Context keys this agent depends on
    fn dependencies(&self) -> &[ContextKey];

    /// Whether this agent should run given current context
    fn accepts(&self, ctx: &Context) -> bool;

    /// Execute and return effects (facts to add)
    fn execute(&self, ctx: &Context) -> AgentEffect;
}
```

### AgentEffect

Buffered output from an agent. Never mutates context directly.

```rust
pub struct AgentEffect {
    pub facts: Vec<Fact>,
    pub proposed_facts: Vec<ProposedFact>,
    pub trace: Option<String>,
}
```

### Fact vs ProposedFact

```
┌─────────────────────────────────────────────────────────────────┐
│                        TRUST LEVELS                             │
├─────────────────────────────────────────────────────────────────┤
│  Fact (authoritative)        │  ProposedFact (tentative)       │
│  ─────────────────────────   │  ─────────────────────────────  │
│  Emitted by deterministic    │  Emitted by LLM agents          │
│  agents or promoted from     │  Requires validation before     │
│  validated proposals         │  becoming a Fact                │
│  Added directly to Context   │  Held in Proposals key          │
└─────────────────────────────────────────────────────────────────┘
```

### Engine

The convergence loop that orchestrates agents.

```rust
pub struct Engine {
    agents: Vec<Box<dyn Agent>>,
    invariants: Vec<Box<dyn Invariant>>,
    budget: Budget,
}

impl Engine {
    /// Run until convergence or budget exhaustion
    pub fn run(&self, ctx: Context) -> Result<ConvergeResult, ConvergeError>;
}
```

---

## Agent Idempotency Contract

**All agents must follow this rule:**

> An agent has contributed if any artifact it emitted exists in the context — regardless of acceptance or validation.

```rust
impl Agent for MyAgent {
    fn dependencies(&self) -> &[ContextKey] {
        // Include BOTH input AND output keys
        &[ContextKey::Seeds, ContextKey::Hypotheses]
    }

    fn accepts(&self, ctx: &Context) -> bool {
        // 1. Check precondition
        if !ctx.has(ContextKey::Seeds) { return false; }

        // 2. Check idempotency (context-based, not hidden state)
        let my_prefix = format!("{}-", self.name());
        !ctx.get(ContextKey::Hypotheses)
            .iter()
            .any(|f| f.id.starts_with(&my_prefix))
    }

    fn execute(&self, _ctx: &Context) -> AgentEffect {
        AgentEffect::with_fact(Fact::new(
            ContextKey::Hypotheses,
            "myagent-result-1",
            "derived content",
        ))
    }
}
```

---

## Invariants

Runtime constraints that guard correctness.

```rust
pub trait Invariant: Send + Sync {
    /// Name of this invariant
    fn name(&self) -> &str;

    /// When to check: Structural, Semantic, or Acceptance
    fn class(&self) -> InvariantClass;

    /// Check the invariant against current context
    fn check(&self, ctx: &Context) -> InvariantResult;
}

pub enum InvariantClass {
    /// Checked on every merge (schema, types)
    Structural,
    /// Checked per-cycle (domain rules)
    Semantic,
    /// Checked at convergence (success criteria)
    Acceptance,
}
```

---

## Capability Traits

Traits for providers to implement.

```rust
// LLM completion
pub trait LlmProvider: Send + Sync {
    fn name(&self) -> &str;
    fn model(&self) -> &str;
    fn complete(&self, request: &LlmRequest) -> Result<LlmResponse, LlmError>;
}

// Embeddings
pub trait Embedding: Send + Sync {
    fn embed(&self, request: &EmbedRequest) -> Result<EmbedResponse, CapabilityError>;
}

// Vector similarity search
pub trait VectorRecall: Send + Sync {
    fn query(&self, query: &VectorQuery) -> Result<Vec<VectorMatch>, CapabilityError>;
}

// Graph pattern matching
pub trait GraphRecall: Send + Sync {
    fn query(&self, query: &GraphQuery) -> Result<GraphResult, CapabilityError>;
}

// Re-ranking
pub trait Reranking: Send + Sync {
    fn rerank(&self, request: &RerankRequest) -> Result<RerankResponse, CapabilityError>;
}
```

---

## Guarantees

| Guarantee | Mechanism |
|-----------|-----------|
| **Determinism** | Agents sorted by name; effects merged in order |
| **Termination** | Budget limits cycles, facts, and wall-clock time |
| **Isolation** | Agents read-only context; effects buffered |
| **Auditability** | Every fact has provenance |
| **Correctness** | Invariants block invalid states |

---

## Execution Model

```
repeat
    1. Determine eligible agents (accepts() == true)
    2. Execute eligible agents in parallel (read-only context)
    3. Collect AgentEffects (buffered)
    4. Merge effects into context (serialized, deterministic order)
    5. Check structural invariants (immediate)
    6. Check semantic invariants (per-cycle)
until
    Context unchanged (convergence) OR
    Budget exhausted OR
    Invariant failed

finally
    Check acceptance invariants (convergence gate)
```

---

## Testing

```bash
# Run all convergence axiom tests
cargo test -p converge-core --test engine_convergence_axioms -- --nocapture

# Run all tests
cargo test -p converge-core

# Run property-based tests
cargo test -p converge-core --test property_tests
```

### Test Categories

| Test File | What It Tests |
|-----------|---------------|
| `engine_convergence_axioms` | Core convergence guarantees |
| `convergence` | Basic convergence behavior |
| `parallel_execution` | Parallel agent execution |
| `transparent_determinism` | Determinism guarantees |
| `hitl_pause_resume_axioms` | Human-in-the-loop flows |
| `property_tests` | Property-based testing |

---

## Documentation

See [docs/](docs/) for detailed documentation:

- [docs/ARCHITECTURE.md]docs/ARCHITECTURE.md — Layering and contracts
- [docs/architecture/]docs/architecture/ — Core concepts and execution model
- [docs/agents/]docs/agents/ — Agent lifecycle and patterns
- [docs/governance/]docs/governance/ — Design tenets and terminology
- [docs/testing/]docs/testing/ — Invariant and validation testing

---

## Repository

This crate is part of the [Converge](https://github.com/kpernyer/converge) project.

**Standalone repo:** [github.com/kpernyer/converge-core](https://github.com/kpernyer/converge-core)

## License

Proprietary (Aprio One AB)