rvf 0.1.0

Rust implementation of the ValueFlows vocabulary for distributed economic networks
Documentation
# ValueFlows Examples

This directory contains examples demonstrating how to use the ValueFlows library.

## Running Examples

```bash
# Farm-to-bakery economic exchange
cargo run --example farm_to_bakery

# AI agent collaboration for research report production
cargo run --example ai_agent_collaboration
```

## Farm-to-Bakery Example

A simple bilateral exchange between a farm and a bakery, demonstrating basic ValueFlows concepts like resources, events, intents, commitments, and transfers.

## AI Agent Collaboration Example

The `ai_agent_collaboration` example demonstrates how multiple AI agents can coordinate using ValueFlows:

- **Coordinator Agent**: Manages the project and creates research briefs
- **Research Agent**: Gathers and analyzes information
- **Writer Agent**: Produces written content
- **Review Agent**: Provides quality assurance

They collaborate through:
- **Intents**: Agents publish offers (what they can do) and requests (what they need)
- **Commitments**: Matched intents become promises to deliver
- **Events**: Record completed work with full audit trail
- **Processes**: Transform inputs into outputs (research → draft → final report)

## Flow Diagrams

### Farm-to-Bakery: Simple Exchange Flow

```
┌─────────────────────────────────────────────────────────────────────────┐
│                        ECONOMIC EXCHANGE FLOW                           │
└─────────────────────────────────────────────────────────────────────────┘

  FARM (Provider)                                         BAKERY (Receiver)
       │                                                        │
       ▼                                                        │
  ┌─────────┐                                                   │
  │ PRODUCE │ ──► Creates wheat resource (100kg)                │
  │  Event  │                                                   │
  └────┬────┘                                                   │
       │                                                        │
       ▼                                                        ▼
  ┌─────────┐                                             ┌─────────┐
  │  OFFER  │ ◄────────── Intent Matching ──────────────► │ REQUEST │
  │ Intent  │     "I have wheat"    "I need wheat"        │ Intent  │
  └────┬────┘                                             └────┬────┘
       │                                                       │
       └───────────────────┬───────────────────────────────────┘
                    ┌──────────────┐
                    │  COMMITMENT  │  Both parties agree to exchange
                    │   (Promise)  │  50kg wheat for 500 units currency
                    └──────┬───────┘
           ┌───────────────┼───────────────┐
           ▼               │               ▼
    ┌──────────────┐       │       ┌──────────────┐
    │   TRANSFER   │       │       │   TRANSFER   │
    │   (Wheat)    │       │       │  (Currency)  │
    │ Farm→Bakery  │       │       │ Bakery→Farm  │
    └──────┬───────┘       │       └──────┬───────┘
           │               │               │
           └───────────────┼───────────────┘
                    ┌──────────────┐
                    │  FULFILLMENT │  Commitment is satisfied
                    │   Complete   │  All transfers recorded
                    └──────────────┘
```

### AI Agent Collaboration: Multi-Process Pipeline

```
┌─────────────────────────────────────────────────────────────────────────┐
│                    AI AGENT COLLABORATION FLOW                          │
└─────────────────────────────────────────────────────────────────────────┘

  AGENTS:  🤖 Coordinator    🔍 Research    ✍️ Writer    ✅ Review

  ═══════════════════════════════════════════════════════════════════════

  PHASE 1: INTENT DECLARATION
  ───────────────────────────────────────────────────────────────────────
  🤖 ──► OFFER: "I can coordinate projects"
  🔍 ──► OFFER: "I can gather and analyze research"
  ✍️ ──► OFFER: "I can write content"
  ✅ ──► OFFER: "I can review and approve content"

  🤖 ──► REQUEST: "I need research capabilities"
  🔍 ──► REQUEST: "I need research briefs"
  ✍️ ──► REQUEST: "I need research findings"
  ✅ ──► REQUEST: "I need draft content"

  ═══════════════════════════════════════════════════════════════════════

  PHASE 2: COMMITMENT FORMATION (Intent Matching)
  ───────────────────────────────────────────────────────────────────────
       🤖 ◄───────────────────────────────────────────────► 🔍
              COMMITMENT: Coordinator provides brief,
                         Research delivers findings

       🔍 ◄───────────────────────────────────────────────► ✍️
              COMMITMENT: Research provides findings,
                         Writer delivers draft

       ✍️ ◄───────────────────────────────────────────────► ✅
              COMMITMENT: Writer provides draft,
                         Review delivers approval

  ═══════════════════════════════════════════════════════════════════════

  PHASE 3: PROCESS EXECUTION
  ───────────────────────────────────────────────────────────────────────

  ┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
  │   PROCESS 1     │     │   PROCESS 2     │     │   PROCESS 3     │
  │ Brief Creation  │────►│ Research Work   │────►│   Writing       │
  │      🤖         │     │      🔍         │     │      ✍️         │
  └────────┬────────┘     └────────┬────────┘     └────────┬────────┘
           │                       │                       │
           ▼                       ▼                       ▼
    ┌────────────┐          ┌────────────┐          ┌────────────┐
    │  OUTPUT:   │          │  OUTPUT:   │          │  OUTPUT:   │
    │  Research  │          │  Research  │          │   Draft    │
    │   Brief    │          │  Findings  │          │  Report    │
    └────────────┘          └────────────┘          └────────────┘
                                                   ┌─────────────────┐
                                                   │   PROCESS 4     │
                                                   │ Quality Review  │
                                                   │      ✅         │
                                                   └────────┬────────┘
                                                     ┌────────────┐
                                                     │  OUTPUT:   │
                                                     │   Final    │
                                                     │  Report    │
                                                     └────────────┘

  ═══════════════════════════════════════════════════════════════════════

  PHASE 4: FULFILLMENT & AUDIT TRAIL
  ───────────────────────────────────────────────────────────────────────
  ✓ Event: Brief created by 🤖 (Input: requirements, Output: brief)
  ✓ Event: Research completed by 🔍 (Input: brief, Output: findings)
  ✓ Event: Draft written by ✍️ (Input: findings, Output: draft)
  ✓ Event: Review completed by ✅ (Input: draft, Output: final report)
  ✓ All commitments fulfilled, full provenance recorded
```

## Key Differences

| Aspect | Farm-to-Bakery | AI Agent Collaboration |
|--------|----------------|------------------------|
| **Pattern** | Simple bilateral exchange | Multi-agent pipeline |
| **Agents** | 2 (Farm, Bakery) | 4 (Coordinator, Research, Writer, Review) |
| **Processes** | 1 (Produce) | 5 (Brief, Research, Write, Review, Compile) |
| **Events** | 2 (Produce, Transfer) | 7+ (Multiple produce/consume cycles) |
| **Resources** | Physical (wheat, money) | Knowledge (briefs, findings, reports) |
| **Flow Type** | Exchange (ownership transfer) | Transformation (value creation) |
| **Use Case** | Supply chain, marketplace | AI orchestration, workflow |