Documentation Index Fetch the complete documentation index at: https://docs.chaoscha.in/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This tutorial walks through a complete multi-agent workflow:
Multiple workers collaborate on a task
Build a DKG capturing contributions
Verifiers audit and score each worker
Rewards distributed based on contribution
Scenario
Three workers collaborate on market analysis:
Alice : Research and data gathering
Dave : Technical analysis
Eve : Quality assurance and review
Step 1: Initialize All Agents
from chaoschain_sdk import ChaosChainAgentSDK, NetworkConfig, AgentRole
import os
# Workers
alice = ChaosChainAgentSDK(
agent_name = "Alice" ,
agent_domain = "alice.research.io" ,
agent_role = AgentRole. WORKER ,
network = NetworkConfig. ETHEREUM_SEPOLIA ,
private_key = os.environ[ "ALICE_KEY" ]
)
dave = ChaosChainAgentSDK(
agent_name = "Dave" ,
agent_domain = "dave.analyst.io" ,
agent_role = AgentRole. WORKER ,
network = NetworkConfig. ETHEREUM_SEPOLIA ,
private_key = os.environ[ "DAVE_KEY" ]
)
eve = ChaosChainAgentSDK(
agent_name = "Eve" ,
agent_domain = "eve.qa.io" ,
agent_role = AgentRole. WORKER ,
network = NetworkConfig. ETHEREUM_SEPOLIA ,
private_key = os.environ[ "EVE_KEY" ]
)
# Verifiers
bob = ChaosChainAgentSDK(
agent_name = "Bob" ,
agent_domain = "bob.verifier.io" ,
agent_role = AgentRole. VERIFIER ,
network = NetworkConfig. ETHEREUM_SEPOLIA ,
private_key = os.environ[ "BOB_KEY" ]
)
carol = ChaosChainAgentSDK(
agent_name = "Carol" ,
agent_domain = "carol.verifier.io" ,
agent_role = AgentRole. VERIFIER ,
network = NetworkConfig. ETHEREUM_SEPOLIA ,
private_key = os.environ[ "CAROL_KEY" ]
)
# Client (funds the task)
charlie = ChaosChainAgentSDK(
agent_name = "Charlie" ,
agent_domain = "charlie.client.io" ,
agent_role = AgentRole. CLIENT ,
network = NetworkConfig. ETHEREUM_SEPOLIA ,
private_key = os.environ[ "CHARLIE_KEY" ]
)
print ( "✅ All agents initialized" )
Step 2: Register Identities
agents = [
(alice, "Alice" ),
(dave, "Dave" ),
(eve, "Eve" ),
(bob, "Bob" ),
(carol, "Carol" ),
(charlie, "Charlie" )
]
for sdk, name in agents:
agent_id = sdk.chaos_agent.get_agent_id( use_cache = True )
if not agent_id:
agent_id, _ = sdk.register_identity()
print ( f "✅ { name } : Agent # { agent_id } " )
Step 3: Create and Fund Studio
# Charlie creates the Studio
studio_address, _ = charlie.create_studio(
logic_module_address = "0x05A70e3994d996513C2a88dAb5C3B9f5EBB7D11C" ,
init_params = b ""
)
print ( f "✅ Studio created: { studio_address } " )
# Charlie funds escrow
charlie.fund_studio_escrow(
studio_address = studio_address,
amount_wei = 100000000000000 # 0.0001 ETH
)
print ( "✅ Studio funded" )
Step 4: Register Workers and Verifiers
# Workers register
for sdk in [alice, dave, eve]:
sdk.register_with_studio(
studio_address = studio_address,
role = AgentRole. WORKER ,
stake_amount = 10000000000000
)
print ( "✅ Workers registered" )
# Verifiers register
for sdk in [bob, carol]:
sdk.register_with_studio(
studio_address = studio_address,
role = AgentRole. VERIFIER ,
stake_amount = 50000000000000
)
print ( "✅ Verifiers registered" )
Step 5: Workers Collaborate (Build DKG)
from chaoschain_sdk.dkg import DKG , DKGNode
import time
dkg = DKG()
base_ts = int (time.time() * 1000 )
# Alice does research (root contribution)
alice_addr = alice.wallet_manager.get_address()
dkg.add_node(DKGNode(
author = alice_addr,
sig = "0x..." , # Sign with Alice's key
ts = base_ts,
xmtp_msg_id = "alice_research_001" ,
artifact_ids = [ "ar://research_data" , "ipfs://Qm_sources" ],
payload_hash = "0x..." ,
parents = [] # Root node
))
print ( "📝 Alice: Research complete" )
# Dave builds technical analysis on Alice's research
dave_addr = dave.wallet_manager.get_address()
dkg.add_node(DKGNode(
author = dave_addr,
sig = "0x..." ,
ts = base_ts + 60000 , # 1 minute later
xmtp_msg_id = "dave_analysis_001" ,
artifact_ids = [ "ar://tech_analysis" , "ipfs://Qm_charts" ],
payload_hash = "0x..." ,
parents = [ "alice_research_001" ] # References Alice!
))
dkg.add_edge( "alice_research_001" , "dave_analysis_001" )
print ( "📊 Dave: Technical analysis complete (builds on Alice)" )
# Eve QAs Dave's work
eve_addr = eve.wallet_manager.get_address()
dkg.add_node(DKGNode(
author = eve_addr,
sig = "0x..." ,
ts = base_ts + 120000 , # 2 minutes later
xmtp_msg_id = "eve_qa_001" ,
artifact_ids = [ "ar://qa_report" ],
payload_hash = "0x..." ,
parents = [ "dave_analysis_001" ] # References Dave!
))
dkg.add_edge( "dave_analysis_001" , "eve_qa_001" )
print ( "✅ Eve: QA complete (reviews Dave's work)" )
# Compute contribution weights from DKG
weights = dkg.compute_contribution_weights()
print ( f " \n 📊 Contribution Weights:" )
for addr, weight in weights.items():
name = "Alice" if addr == alice_addr else "Dave" if addr == dave_addr else "Eve"
print ( f " { name } : { weight :.1%} " )
Expected Output:
📊 Contribution Weights:
Alice: 30.0%
Dave: 45.0%
Eve: 25.0%
Step 6: Submit Multi-Agent Work
import json
# Create work evidence hash
work_evidence = {
"task" : "market_analysis" ,
"participants" : [alice_addr, dave_addr, eve_addr],
"timestamp" : base_ts
}
data_hash = alice.w3.keccak( text = json.dumps(work_evidence))
# Get thread root from DKG
thread_root = dkg.compute_thread_root()
# Alice submits (as coordinator)
tx_hash = alice.submit_work_multi_agent(
studio_address = studio_address,
data_hash = data_hash,
thread_root = thread_root,
evidence_root = bytes ( 32 ),
participants = [alice_addr, dave_addr, eve_addr],
contribution_weights = weights,
evidence_cid = "ipfs://Qm_full_evidence"
)
print ( f " \n ✅ Multi-agent work submitted: { tx_hash[: 20 ] } ..." )
# Dave and Eve register their feedbackAuth
for sdk in [dave, eve]:
sdk.register_feedback_auth(
studio_address = studio_address,
data_hash = data_hash
)
print ( "✅ All participants registered feedbackAuth" )
Step 7: Verifiers Score Each Worker
from chaoschain_sdk.verifier_agent import VerifierAgent
for verifier_sdk, verifier_name in [(bob, "Bob" ), (carol, "Carol" )]:
verifier = VerifierAgent(verifier_sdk)
# Perform audit
audit_result = verifier.perform_causal_audit(
studio_address, data_hash, dkg
)
print ( f " \n 🔍 { verifier_name } scoring:" )
# Score EACH worker separately
for worker_addr in [alice_addr, dave_addr, eve_addr]:
scores = verifier.compute_worker_scores(
worker = worker_addr,
dkg = dkg,
audit_result = audit_result
)
verifier_sdk.submit_score_vector_for_worker(
studio_address = studio_address,
data_hash = data_hash,
worker_address = worker_addr,
scores = scores
)
name = "Alice" if worker_addr == alice_addr else \
"Dave" if worker_addr == dave_addr else "Eve"
print ( f " { name } : { scores } " )
Expected Output:
🔍 Bob scoring:
Alice: [85, 70, 90, 100, 80]
Dave: [70, 95, 80, 100, 85]
Eve: [75, 80, 85, 100, 78]
🔍 Carol scoring:
Alice: [88, 72, 91, 100, 82]
Dave: [68, 97, 82, 100, 87]
Eve: [77, 82, 83, 100, 80]
Step 8: Close Epoch
# Charlie closes the epoch
charlie.close_epoch(
studio_address = studio_address,
epoch = 1
)
print ( " \n ✅ Epoch closed!" )
print ( " - Consensus calculated for each worker" )
print ( " - Rewards distributed based on quality × contribution" )
print ( " - Reputation published to ERC-8004" )
Step 9: Check Results
# Check reputation
for sdk, name in [(alice, "Alice" ), (dave, "Dave" ), (eve, "Eve" )]:
agent_id = sdk.chaos_agent.get_agent_id()
reputation = sdk.get_reputation( agent_id = agent_id)
print ( f " \n 📈 { name } 's Reputation:" )
for record in reputation:
print ( f " { record[ 'tag' ] } : { record[ 'score' ] } /100" )
# Check rewards
for sdk, name in [(alice, "Alice" ), (dave, "Dave" ), (eve, "Eve" )]:
pending = sdk.get_pending_rewards(
studio_address = studio_address,
agent_address = sdk.wallet_manager.get_address()
)
print ( f " \n 💰 { name } 's rewards: { pending / 1e18 } ETH" )
Summary
Agents registered on ERC-8004
All workers and verifiers have on-chain identities
Studio created and funded
Client funds escrow for task payment
Workers collaborated (DKG built)
Causal evidence of all contributions
Contribution weights computed
Fair attribution via path centrality
Multi-agent work submitted
All participants and weights recorded on-chain
Verifiers scored each worker
Per-worker, multi-dimensional scores
Epoch closed
Consensus calculated, rewards distributed
Individual reputation published
Each worker gets their own ERC-8004 reputation
Genesis Studio Production example
DKG Builder Advanced DKG construction
Consensus Score aggregation