Skip to content

baddiecodes/willow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

34 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌿 Willow

Reference implementation of ShelbyAgent Hub
A decentralized vector database + AI agent identity layer.

Willow implements ShelbyAgent Hub protocol, which defines decentralized infrastructure for AI agents including vector memory, identity (DIDs), and onchain reputation β€” built on Shelby Protocol storage and Aptos Move smart contracts.


What is Willow?

Willow is the reference implementation of ShelbyAgent Hub protocol.

ShelbyAgent Hub defines a decentralized infrastructure layer for:

β€’ AI agent identity (DIDs)
β€’ verifiable agent reputation
β€’ decentralized vector memory
β€’ permissioned blob access via Shelby read proofs

Your AI Agent / LangChain / CrewAI / MCP
           β”‚
   @willow/sdk  (TypeScript)
           β”‚
  Shelby Protocol ◄──────────────────────────────► Aptos Move Contracts
  (blob storage)                                    (ownership Β· access Β· identity)
           β”‚
  @willow/indexer  (local HNSW + query API)

Contract address: 0xb72a54bf4c5fe6e4448e7fd77dcc58c130141a3eba9eed2de7066fde3479aab3
Network: Shelbynet (Aptos testnet)


Architecture diagram

Willow Architecture


Repo structure

willow/
β”œβ”€β”€ sources/                   ← Aptos Move contracts
β”‚   β”œβ”€β”€ collection.move         VectorCollection: chunks + HNSW index blob
β”‚   β”œβ”€β”€ access_control.move     ReadProof auth + APT egress payments
β”‚   β”œβ”€β”€ agent_registry.move     DID registry for AI agents
β”‚   └── reputation.move         Onchain reputation scores
β”œβ”€β”€ tests/
β”‚   └── willow_tests.move       13 unit tests
β”œβ”€β”€ Move.toml
β”œβ”€β”€ INTEGRATION.md              Auth / read-proof / egress payment spec
β”‚
β”œβ”€β”€ willow-sdk/                ← TypeScript SDK (@willow/sdk)
β”‚   └── src/
β”‚       β”œβ”€β”€ client.ts           WillowClient facade
β”‚       β”œβ”€β”€ collection.ts       Collection CRUD + access control
β”‚       β”œβ”€β”€ agent.ts            Agent registry + reputation
β”‚       β”œβ”€β”€ shelby.ts           Shelby blob upload/download
β”‚       β”œβ”€β”€ aptos.ts            Aptos client helpers
β”‚       β”œβ”€β”€ types.ts            All TypeScript interfaces
β”‚       └── constants.ts        Contract addresses + constants
β”‚
└── willow-indexer/            ← Local HNSW indexer + query API
    └── src/
        β”œβ”€β”€ index.ts            Entrypoint
        β”œβ”€β”€ indexer.ts          Index manager + rebuild logic
        β”œβ”€β”€ hnsw.ts             WillowHnsw wrapper (hnswlib-node)
        β”œβ”€β”€ watcher.ts          Aptos event poller
        └── server.ts           Express query API

Quick start

1. Run Move tests

# install Aptos CLI: https://aptos.dev/en/build/cli
aptos move test --named-addresses willow=0xCAFE

2. Use the TypeScript SDK

cd willow-sdk && npm install && npm run build
import { WillowClient, METRIC_COSINE, ACCESS_OPEN } from "@willow/sdk";

const willow = new WillowClient({
  privateKey: process.env.APTOS_PRIVATE_KEY!,
  network:    "testnet",
});

// Create a vector collection
await willow.createCollection({
  name:           "my-rag-kb",
  embeddingModel: "text-embedding-3-small",
  dimensions:     1536,
  distanceMetric: METRIC_COSINE,
  accessPolicy:   ACCESS_OPEN,
});

// Add a chunk (embedding β†’ Shelby blob β†’ on-chain registration)
const result = await willow.addChunk({
  collectionAddr: "<collection_addr>",
  chunkId:        "chunk-001",
  embedding:      new Float32Array(1536).fill(0.1),
  text:           "Willow is a decentralized vector database on Aptos",
});

console.log("blob:", result.blobId, "tx:", result.txHash);

3. Register an AI agent

const agent = await willow.registerAgent({
  metadata: {
    "@context":   "https://schema.org/",
    "@type":      "SoftwareAgent",
    identifier:   "pending",
    name:         "ResearchAgent-Alpha",
    version:      "0.1.0",
    capabilities: ["rag_query", "web_search"],
    framework:    "LangChain",
    createdAt:    new Date().toISOString(),
  },
  memoryCollectionAddr: "<collection_addr>",
  initReputation:       true,
});

console.log("DID:", agent.did);
// β†’ did:willow:aptos:0xb72a...:0

4. Start the local indexer

cd willow-indexer
npm install
cp .env.example .env    # fill in APTOS_PRIVATE_KEY, set SHELBY_MOCK=true for dev
npm run build
npm start

API endpoints:

Method Path Description
POST /track Start tracking a collection
POST /query Vector search (kNN)
GET /status All tracked collections
GET /status/:addr Single collection status
POST /rebuild/:addr Manual index rebuild
# Example query
curl -X POST http://localhost:3001/query \
  -H "Content-Type: application/json" \
  -d '{
    "collectionAddr": "<addr>",
    "vector": [0.1, 0.2, ...],
    "topK": 5
  }'

Move contract functions

Module Key functions
collection create_collection Β· add_chunk Β· add_chunks_batch Β· update_index Β· set_access_policy Β· freeze_collection
access_control configure_access Β· set_allowlist_entry Β· request_read_proof_{open|allowlist|paid|owner}
agent_registry initialize Β· register_agent Β· link_memory_collection Β· deactivate_agent
reputation initialize Β· set_reporter Β· initialise_score Β· submit_score_update

Deployment

# 1. Publish contracts
aptos move publish \
  --named-addresses willow=0xb72a54bf4c5fe6e4448e7fd77dcc58c130141a3eba9eed2de7066fde3479aab3 \
  --profile shelbynet \
  --assume-yes

# 2. Initialise (one-time)
ADDR=0xb72a54bf4c5fe6e4448e7fd77dcc58c130141a3eba9eed2de7066fde3479aab3
aptos move run --function-id "${ADDR}::agent_registry::initialize" --profile shelbynet
aptos move run --function-id "${ADDR}::reputation::initialize"     --profile shelbynet

Access policies

Value Policy Who pays egress?
0 ACCESS_OPEN Collection owner
1 ACCESS_OWNER_ONLY Collection owner
2 ACCESS_ALLOWLIST Collection owner
3 ACCESS_PAID Reader (APT fee onchain)

License

MIT β€” built by @withmewtwo / Junohauz

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors