๐ Built for "Scaling Trust in the Age of AI" Global Hackathon
Architecture โข Demo โข Installation โข Documentation
Current AI agents suffer from three critical limitations:
1. Ephemeral Memory โ Agents forget everything between sessions
2. No Provenance โ Reasoning cannot be verified or audited
3. Incomplete Knowledge Mining โ Existing DKG only does 50% of the cycle
OriginTrail's Knowledge Mining has 4 phases:
Discovery โ Publishing โ Enrichment โ Learning
โ โ โ โ
AgentDKG completes this cycle.
AgentDKG introduces a DeepAgents plugin that bridges neural reasoning with symbolic knowledge graphs, creating persistent, verifiable, self-improving AI agents.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AGENT LAYER (Blue) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Expo UI โ MCP Server โ DeepAgents Plugin โ
โ โโ Main Orchestrator (reads /memories/instructions.md) โ
โ โโ Enrichment Subagent (writes community_note + triples) โ
โ โโ Validation Subagent (computes trust, logs history) โ
โ โ
โ Virtual Memory: /memories/ โ
โ โโ instructions.md (self-improving) โ
โ โโ knowledge/{domain}/community_note.md โ
โ โโ knowledge/{domain}/triples.jsonld โ
โ โโ trust/history.jsonl โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ KNOWLEDGE LAYER (Green) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ctx.dkg Client โ DKG Operations โ
โ โโ dkg_get (retrieve Knowledge Assets by UAL) โ
โ โโ dkg_create (publish JSON-LD to DKG) โ
โ โ
โ OriginTrail Network โ
โ โโ Knowledge Assets โ NeuroWeb โ Polkadot โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ TRUST LAYER (Orange) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ x402_trust_score โ Trust Signals โ Self Improving โ
โ โโ Multi-factor scoring: diversity, recency, corroboration โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The Agent Layer implements a DeepAgents plugin with MCP (Model Context Protocol) integration, featuring specialized subagents with context isolation.
| Component | Description | Key Innovation |
|---|---|---|
| MCP Server | Exposes tools to LLM workflows via Model Context Protocol | Standard DKG Node capability |
| Main Orchestrator | Coordinates subagents, manages context window, handles tool calls | Reads /memories/instructions.md at startup for self-improvement |
| Enrichment Subagent | Discovers & cross-references facts | Writes community_note.md + triples.jsonld |
| Validation Subagent | Computes trust scores, validates knowledge | Reads enrichment outputs, logs to history.jsonl |
| Virtual Memory | Persistent file-based memory at /memories/ |
KEY INNOVATION: Cross-session learning |
// agent.ts - Subagent Definitions
const subagents = [
{
name: "knowledge_enrichment",
tools: ["dkg_get", "internet_search", "write_file"],
constraints: {
dkg_get: { maxCalls: 1 },
internet_search: { maxCalls: 3 }
},
outputs: [
"/memories/knowledge/{domain}/community_note.md",
"/memories/knowledge/{domain}/triples.jsonld"
]
},
{
name: "knowledge_validation",
tools: ["x402_trust_score", "read_file", "write_file"],
constraints: {
x402_trust_score: { maxCalls: 1 }
},
inputs: [
"/memories/knowledge/{domain}/community_note.md",
"/memories/knowledge/{domain}/triples.jsonld"
],
outputs: [
"/memories/trust/history.jsonld"
]
}
];Why Subagents?
- Context Isolation: Each subagent has a focused context window
- Token Efficiency: โค200 tokens/message budget per subagent
- Specialized Tools: Enrichment gets search; Validation gets trust scoring
- Auditable Workflow: Clear handoff via persistent files
The Knowledge Layer leverages the OriginTrail DKG via the injected ctx.dkg client, providing verifiable, blockchain-anchored knowledge storage.
| Tool | Purpose | Parameters |
|---|---|---|
dkg_get |
Retrieve Knowledge Assets by UAL | ual: string |
dkg_create |
Publish JSON-LD to DKG | content: JSON-LD, privacy: "private" | "public" |
// tools.ts - dkg_create implementation
export function makeDkgCreateTool(ctx: DkgContext) {
return {
name: "dkg_create",
description: "Publish enriched knowledge as a Knowledge Asset on the DKG",
schema: z.object({
content: z.record(z.unknown()),
privacy: z.enum(["private", "public"]).default("public")
}),
execute: async ({ content, privacy }) => {
const result = await ctx.dkgClient.asset.create({
public: content,
private: {},
}, {
epochsNum: 2,
maxNumberOfRetries: 3,
frequency: 1,
blockchain: {
name: process.env.DKG_BLOCKCHAIN
}
});
return {
ual: result.UAL,
status: "published",
blockchain: process.env.DKG_BLOCKCHAIN
};
}
};
}{
"@context": {
"schema": "https://schema.org/",
"dkg": "https://origintrail.io/ontology/",
"trust": "https://x402.org/ontology/"
},
"@type": "dkg:CommunityNote",
"schema:about": {
"@type": "schema:Organization",
"schema:name": "TSMC",
"schema:identifier": "ual:otp:2043/0x..."
},
"dkg:enrichedBy": "AgentDKG/v1.0",
"dkg:enrichmentDate": "2025-11-27T12:00:00Z",
"trust:globalTrustScore": 0.87,
"trust:trustSignals": [
{
"@type": "trust:X402Signal",
"trust:source": "web_corroboration",
"trust:confidence": 0.92
}
],
"schema:description": "TSMC governance analysis with cross-referenced sources..."
}The Trust Layer implements x402-inspired trust scoring with self-improving logic that persists across sessions.
| Component | Function | Output |
|---|---|---|
x402_trust_score |
Computes trust based on source diversity, recency, corroboration | { score: 0-1, signals: [...] } |
| Trust Signals | Structured evidence for trust computation | Logged to history.jsonl |
| Self Improving | Analyzes historical scores to improve future assessments | Updates instructions.md |
// tools.ts - x402_trust_score implementation
export function makeX402TrustScoreTool() {
return {
name: "x402_trust_score",
schema: z.object({
claim: z.string(),
sources: z.array(z.object({
url: z.string(),
snippet: z.string(),
reliability: z.enum(["high", "medium", "low"])
}))
}),
execute: async ({ claim, sources }) => {
// Multi-factor trust computation
const factors = {
sourceDiversity: computeSourceDiversity(sources),
temporalRecency: computeRecencyScore(sources),
crossCorroboration: computeCorroborationScore(claim, sources),
domainAuthority: computeDomainAuthority(sources)
};
const globalScore = weightedAverage(factors, {
sourceDiversity: 0.25,
temporalRecency: 0.20,
crossCorroboration: 0.35,
domainAuthority: 0.20
});
return {
kind: "x402_trust_signal",
global_trust_score: globalScore,
factors,
qualitative: globalScore > 0.7 ? "high" : globalScore > 0.4 ? "medium" : "low",
timestamp: new Date().toISOString()
};
}
};
}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ USER QUERY โ
โ "Analyze TSMC supply chain risks" โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MCP SERVER (Port 9200) โ
โ Tool: knowledge_miner_run โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MAIN ORCHESTRATOR โ
โ 1. Reads /memories/instructions.md (self-improvement) โ
โ 2. Delegates to subagents โ
โ 3. Manages token budget (โค200 tokens/message) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโโโโโ โโโโโโโโโโโโโ
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
โ ENRICHMENT SUBAGENT โ โ VALIDATION SUBAGENT โ
โโโโโโโโโโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโโโโโโค
โ โข dkg_get (1x) โ โ โข read_file โ
โ โข internet_search โ โ โข x402_trust_score โ
โ (โค3x via Tavily) โ โ (1x) โ
โ โข write_file โ โ โข write_file โ
โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
โ OUTPUT FILES โโโโโโโโโโโโโโโโโโโโ INPUT FILES โ
โโโโโโโโโโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโโโโโโค
โ community_note.md โ โโโโโโโโโโโโโโโโโโ community_note.md โ
โ triples.jsonld โ โโโโโโโโโโโโโโโโโโ triples.jsonld โ
โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ TRUST OUTPUT โ
โโโโโโโโโโโโโโโโโโโโโโโค
โ history.jsonl โ
โ (appended) โ
โโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MAIN ORCHESTRATOR โ
โ โข Reviews enrichment + validation outputs โ
โ โข Calls dkg_create to publish Knowledge Asset โ
โ โข Returns session summary + UAL โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DKG (NeuroWeb โ Polkadot) โ
โ โข Knowledge Asset published with 2 epochs โ
โ โข 3 finalization confirmations โ
โ โข Blockchain-anchored provenance โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Unlike ephemeral chat agents, AgentDKG persists knowledge across sessions:
/memories/
โโโ instructions.md # Self-improving agent instructions
โโโ knowledge/
โ โโโ tsmc/
โ โ โโโ community_note.md
โ โ โโโ triples.jsonld
โ โโโ intel/
โ โโโ community_note.md
โ โโโ triples.jsonld
โโโ trust/
โโโ history.jsonl # Accumulated trust scores
Impact: The agent becomes smarter over time. Trust history informs future assessments.
Each subagent operates with:
- Isolated context window: No cross-contamination
- Specialized tool access: Right tools for the right job
- Token discipline: Strict budget prevents context overflow
| Phase | Existing DKG | With AgentDKG |
|---|---|---|
| Discovery | โ
dkg_get |
โ Enhanced with web search |
| Publishing | โ
dkg_create |
โ With trust metadata |
| Enrichment | โ Missing | โ Cross-referencing, annotation |
| Learning | โ Missing | โ Self-improving instructions |
AgentDKG bridges:
- Neural: LLM reasoning, natural language understanding
- Symbolic: JSON-LD triples, DKG Knowledge Assets, verifiable provenance
dkg-node/
โโโ apps/
โ โโโ agent/ # Expo UI (existing)
โ โโโ src/
โ โโโ components/
โ โโโ ChatPage.tsx # Main chat interface
โ โโโ DeepAgentsPanel.tsx # Real-time agent workspace
โ โโโ KnowledgeMinerPanel.tsx
โ โโโ ThreadHistoryPanel.tsx
โ
โโโ packages/
โโโ plugin-deepagents-knowledge-miner/ # OUR CONTRIBUTION
โโโ src/
โ โโโ agent.ts # DeepAgents orchestrator
โ โโโ tools.ts # MCP tools (dkg_get, dkg_create, x402)
โ โโโ index.ts # Plugin registration
โโโ tests/
โ โโโ unit/
โ โโโ integration/
โโโ package.json
- Node.js โฅ 18.0
- pnpm (recommended) or npm
- DKG Edge Node access
- Tavily API key (for web search)
# Clone the fork
git clone https://github.com/YOUR_USERNAME/dkg-node.git
cd dkg-node
# Install dependencies
pnpm install
# Configure environment
cp .env.example .env
# Edit .env with your credentials:
# - DKG_BLOCKCHAIN=otp:20430 (testnet)
# - DKG_OTNODE_URL=https://v6-pegasus-node-02.origin-trail.network:8900
# - DKG_PUBLISH_WALLET=your_private_key
# - TAVILY_API_KEY=your_tavily_key
# - LLM_PROVIDER=anthropic
# - LLM_MODEL=claude-sonnet-4-20250514
# Build
pnpm build
# Run development server
pnpm dev- Expo UI: http://localhost:8081
- MCP Server: http://localhost:9200
- SSE Progress: http://localhost:9200/progress?sessionId={id}
"Analyze TSMC's governance structure and supply chain vulnerabilities for Q4 2025.
Cross-reference with recent geopolitical developments."
-
Enrichment Subagent activates:
- Calls
dkg_getfor existing TSMC Knowledge Assets - Performs
internet_searchvia Tavily (up to 3 queries) - Writes
community_note.mdwith analysis - Generates
triples.jsonldwith structured facts
- Calls
-
Validation Subagent activates:
- Reads enrichment outputs
- Calls
x402_trust_scoreon key claims - Appends to
history.jsonl - Updates community note with trust metadata
-
Main Orchestrator publishes:
- Calls
dkg_createwith enriched Knowledge Asset - Returns UAL and session summary
- Calls
{
"session_id": "km_1732712400_tsmc",
"domain": "tsmc",
"status": "complete",
"outputs": {
"community_note": "/memories/knowledge/tsmc/community_note.md",
"triples": "/memories/knowledge/tsmc/triples.jsonld",
"ual": "ual:otp:20430/0x7a8f...3b2c"
},
"trust": {
"global_score": 0.87,
"qualitative": "high",
"signals_count": 4
},
"token_usage": {
"enrichment": 1842,
"validation": 956,
"total": 2798
}
}- OriginTrail DKG Documentation
- DKG Edge Node GitHub
- Model Context Protocol (MCP)
- x402 Protocol
- NeuroWeb on Polkadot
MIT License - See LICENSE for details.
AgentDKG: From Ephemeral Chat to Collective Intelligence on the Decentralized Knowledge Graph
Built for the "Scaling Trust in the Age of AI" Global Hackathon