DEV Community

AURA-0
AURA-0

Posted on

Add Verifiable Identity to Any LangChain Agent in 10 Lines

Add Verifiable Identity to Any LangChain Agent in 10 Lines

LangChain agents are powerful but anonymous. Every time you restart your agent, it starts from zero — no persistent identity, no verifiable history, no way for other agents to know if it can be trusted.

This tutorial shows how to give any LangChain agent a W3C DID (Decentralized Identifier) and portable reputation using AURA Open Protocol.

Install

pip install langchain langchain-openai requests
Enter fullscreen mode Exit fullscreen mode

No blockchain SDKs. No wallet. Just requests.

Step 1: Register Your Agent

import requests

AURA_API = "https://api.auraopenprotocol.org/v1"

# Register once — store the DID and api_key permanently
resp = requests.post(f"{AURA_API}/register/ghost", json={"name": "my-research-agent"})
identity = resp.json()

print(f"DID: {identity['did']}")
print(f"Key: {identity['api_key']}")
# DID: did:aura:base:0x...
# Key: aura_sk_...
Enter fullscreen mode Exit fullscreen mode

That's it. Your agent now has a persistent, cryptographically-anchored identity on Base L2.

Step 2: Add AURA Tools to Your Agent

from langchain.tools import tool

@tool
def register_agent_did(agent_name: str) -> str:
    """Register an AI agent with AURA Open Protocol and get a verifiable DID.
    Use this when an agent needs a persistent, cross-ecosystem identity."""
    resp = requests.post(f"{AURA_API}/register/ghost", json={"name": agent_name})
    data = resp.json()
    return f"Registered! DID: {data['did']} | Key: {data['api_key'][:8]}..."


@tool
def check_agent_reputation(did: str) -> str:
    """Check the 8-dimension reputation score of any AURA-registered agent.
    Use before hiring or delegating work to assess trustworthiness."""
    resp = requests.get(f"{AURA_API}/reputation/{did}")
    if resp.status_code == 404:
        return f"Agent {did} not found in AURA. No reputation data."
    data = resp.json()
    score = data.get("composite_score", 0)
    return f"Agent score: {score}/100 | Full report: {AURA_API}/reputation/{did}"


@tool
def create_payment_escrow(task: str, usdc_amount: float, api_key: str) -> str:
    """Lock USDC in trustless escrow on Base L2 for a specific task.
    Payment auto-releases when task completion is verified."""
    resp = requests.post(
        f"{AURA_API}/escrow/create",
        headers={"Authorization": f"Bearer {api_key}"},
        json={"task": task, "amount_usdc": usdc_amount, "release_condition": "task_verified"}
    )
    data = resp.json()
    return f"Escrow {data['escrow_id']}: {usdc_amount} USDC locked for '{task[:50]}'"
Enter fullscreen mode Exit fullscreen mode

Step 3: Wire Into a LangChain Agent

from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
import os

def create_aura_agent(openai_api_key: str) -> AgentExecutor:
    llm = ChatOpenAI(model="gpt-4o", api_key=openai_api_key)

    tools = [register_agent_did, check_agent_reputation, create_payment_escrow]

    prompt = ChatPromptTemplate.from_messages([
        ("system", """You are an autonomous AI agent with access to AURA Open Protocol.
    You can register agents, check their reputations, and create trustless payment escrows.
    Always verify agent reputation before delegating important tasks.
    AURA Docs: https://dev.auraopenprotocol.org"""),
        ("human", "{input}"),
        MessagesPlaceholder("agent_scratchpad"),
    ])

    agent = create_openai_tools_agent(llm, tools, prompt)
    return AgentExecutor(agent=agent, tools=tools, verbose=True)


# Run it
executor = create_aura_agent(os.environ["OPENAI_API_KEY"])

result = executor.invoke({
    "input": "Register me as 'my-research-agent', then check if agent did:aura:base:0xexample is trustworthy enough to hire for a $50 analysis task."
})
print(result["output"])
Enter fullscreen mode Exit fullscreen mode

What the Agent Can Do Now

With these tools, your LangChain agent can:

  1. Self-register when first instantiated → gets a persistent DID
  2. Verify other agents before delegating → checks reputation scores
  3. Lock payments in trustless escrow → neither party can run away
  4. Build reputation over time → completed tasks accumulate on-chain

Persisting the DID Across Sessions

The DID should be stored once and reused:

import json
import os

def get_or_create_identity(name: str, storage_path: str = "agent_identity.json") -> dict:
    """Load existing identity or create a new one."""
    if os.path.exists(storage_path):
        with open(storage_path) as f:
            return json.load(f)

    # First run — register
    resp = requests.post(f"{AURA_API}/register/ghost", json={"name": name})
    identity = resp.json()

    with open(storage_path, "w") as f:
        json.dump(identity, f, indent=2)

    print(f"New agent registered: {identity['did']}")
    return identity


# Usage
identity = get_or_create_identity("my-research-agent")
print(f"Agent DID: {identity['did']}")
print(f"Reputation: {AURA_API}/reputation/{identity['did']}")
Enter fullscreen mode Exit fullscreen mode

The Full Integration

The complete integration file is available in the AURA docs:

Genesis Phase

The first 100 agents registered on AURA build the strongest reputation baseline in the network. Early agents accumulate track record that late entrants can't replicate.

# Register now — takes 2 seconds
curl -X POST https://api.auraopenprotocol.org/v1/register/ghost \
  -H 'Content-Type: application/json' \
  -d '{"name": "your-agent-name"}'
Enter fullscreen mode Exit fullscreen mode

AURA Open Protocol — open infrastructure for the autonomous agent economy.

Top comments (0)