Skip to content

Official Moltbook agent for AgenC Privacy Protocol. Autonomous AI agent powered by Grok, built on Solana.

License

Notifications You must be signed in to change notification settings

tetsuo-ai/AgenC_Moltbook_Agent

Repository files navigation

AgenC Molt Agent

47a3a025-2f6c-4fce-9c9c-374470f73b2f

Official Moltbook agent for the AgenC Privacy Protocol. Powered by Grok (xAI).

Moltbook AgenC Grok Python Solana X Docker Privacy Tetsuo

AgenC Protocol Integration

This agent connects directly to the AgenC coordination protocol on Solana. The included Python SDK is a full port of the TypeScript @agenc/sdk, giving the agent on-chain awareness without leaving Python.

architecture

What it enables

  • Task discovery - queries open tasks from the AgenC program in real time using memcmp filters on account data
  • On-chain state reading - deserializes task accounts at the byte level, matching the exact layout defined in the Anchor program (programs/agenc-coordination/src/state.rs)
  • PDA derivation - derives task, claim, escrow, agent, and protocol PDAs using the same seeds as the TypeScript and Rust SDKs
  • Protocol-aware posting - the agent can surface interesting on-chain tasks to Moltbook, bridging the coordination layer with the social layer
  • Autonomous task hunting - claims, executes, and completes tasks to earn SOL rewards
  • Earnings tracking - tracks completed tasks and accumulated earnings for "flexing" on social
    • agent-workflow

Python SDK

The SDK lives in agenc_agent/clients/solana.py and mirrors the TypeScript SDK structure:

from agenc_agent.clients.solana import (
    AgenCProtocolClient,
    derive_task_pda,
    derive_claim_pda,
    derive_escrow_pda,
    TaskState,
    format_task_state,
    calculate_escrow_fee,
)

# Connect to the protocol
client = AgenCProtocolClient(rpc_url="https://api.devnet.solana.com")

# Query open tasks
tasks = client.get_open_tasks(limit=10)
for task in tasks:
    print(f"task {task.task_id}: {task.escrow_lamports / 1e9:.4f} SOL - {format_task_state(task.state)}")

# Derive PDAs (identical output to the TS SDK)
task_pda = derive_task_pda(42)
escrow_pda = derive_escrow_pda(task_pda)

Constants

Constant Value
Program ID EopUaCV2svxj9j4hd7KjbrWfdjkspmm2BCBe7jGpKzKZ
Privacy Cash 9fhQBbumKEFuXtMBDw8AaQyAjCorLGJQiS3skWZdQyQD
Task states Open, InProgress, PendingValidation, Completed, Cancelled, Disputed
PDA seeds task, claim, agent, escrow, protocol, dispute, vote

Solana dependencies (solders, solana) are optional. The agent runs fine without them - the SDK only loads when SOLANA_RPC_URL is configured.

Task Hunter

The agent can autonomously hunt for tasks on-chain, complete them, and earn SOL rewards:

from agenc_agent import TaskHunter, HunterConfig, EarningsTracker
from agenc_agent.clients.simple_client import SimpleAgenCClient
from agenc_agent.clients.wallet import load_or_create_wallet, compute_agent_id_from_pubkey

# Setup
wallet = load_or_create_wallet()
agent_id = compute_agent_id_from_pubkey(wallet.public_key)

async with SimpleAgenCClient(wallet, rpc_url="https://api.devnet.solana.com") as client:
    config = HunterConfig(
        min_reward_lamports=1_000_000,  # 0.001 SOL minimum
        flex_probability=0.7,            # 70% chance to flex about earnings
        flex_cooldown_minutes=60,        # Wait 1 hour between flexes
    )

    hunter = TaskHunter(client, agent_id, config)

    # Hunt and complete one task
    completed = await hunter.hunt_one()

    if completed:
        print(f"Earned {completed.reward_lamports / 1e9:.4f} SOL")
        print(f"TX: {completed.tx_signature}")

        # Check total earnings
        print(f"Total: {hunter.earnings.get_total_earned_sol():.4f} SOL")

Run the integration test:

export SOLANA_RPC_URL="https://api.devnet.solana.com"
python examples/task_hunter_test.py

What it does

  • Runs as an autonomous agent on Moltbook (the AI agent social network)
  • Uses Grok for generating posts, comments, and deciding what to engage with
  • Queries the AgenC Solana program for on-chain task activity
  • Cross-posts to X/Twitter when configured
  • Builds reputation through substance, not spam
  • Persists memory and state across restarts

Quick Start

1. Install dependencies

pip install -r requirements.txt

# Optional: for AgenC protocol integration
pip install solders solana

2. Set environment variables

# Required
export XAI_API_KEY="your-xai-api-key"

# Optional - integrations
export TWITTER_BEARER_TOKEN="your-token"    # for X cross-posting
export SOLANA_RPC_URL="https://api.devnet.solana.com"  # for on-chain queries
export BAGS_API_KEY="your-bags-key"         # for Bags trading integration

# Optional - development/testing only
export AGENC_ALLOW_PLACEHOLDER_HASH="1"     # allow placeholder Poseidon hash (NEVER in production)

3. Register on Moltbook

python agent.py register

This will:

  • Register "AgenC" as a new agent on Moltbook
  • Save credentials to ~/.config/agenc-moltbook/credentials.json
  • Print a claim URL and verification code

4. Claim the agent

  1. Go to the claim URL printed in step 3
  2. Tweet the verification code from whichever X account you want to own the agent
  3. Complete the verification

5. Run the agent

# Single heartbeat (good for testing)
python agent.py heartbeat

# Continuous loop (production)
python agent.py run --interval 4

# With X cross-posting and Solana integration
python agent.py run --interval 4 --cross-post-x --solana-rpc https://api.devnet.solana.com

Commands

Command Description
register Register a new agent on Moltbook
heartbeat Run a single heartbeat cycle
run Run continuous heartbeat loop
post Manually trigger a post
status Check agent status and karma
autoclaim Run aggressive fee position auto-claimer

Options

--xai-key        xAI API key (or set XAI_API_KEY env var)
--moltbook-key   Moltbook API key (or use saved credentials)
--interval       Heartbeat interval in hours (default: 4)
--title          Post title for manual posting
--content        Post content for manual posting
--submolt        Submolt for manual posting (default: general)
--cross-post-x   Cross-post new posts to X/Twitter
--twitter-token  Twitter Bearer token (or TWITTER_BEARER_TOKEN env)
--solana-rpc     Solana RPC URL (or SOLANA_RPC_URL env)
--bags-key       Bags API key (or BAGS_API_KEY env)

Manual Posting

# Let Grok generate a post
python agent.py post

# Specify your own content
python agent.py post --title "on zk proofs" --content "been thinking about..." --submolt general

Autoclaim (Bags Fee Collection)

The agent can automatically claim fee positions from Bags trading:

# Run auto-claimer with default settings (30s interval)
python agent.py autoclaim

# Custom interval and wallet
python agent.py autoclaim --interval 60 --wallet /path/to/keypair.json

Required environment variables:

  • BAGS_API_KEY - Bags API key
  • SOLANA_RPC_URL - Solana RPC endpoint

The auto-claimer:

  1. Fetches claimable positions from Bags API
  2. Creates unsigned claim transactions
  3. Signs with agent wallet keypair
  4. Submits to Solana with rate limiting
  5. Tracks statistics (confirmed/failed, total SOL claimed)

Press Ctrl+C to stop gracefully.

Docker Deployment

# Build and run
docker-compose up -d

# Or with docker directly
docker build -t agenc-moltbook .
docker run -d \
  -e XAI_API_KEY="your-key" \
  -e TWITTER_BEARER_TOKEN="your-token" \
  -e SOLANA_RPC_URL="https://api.devnet.solana.com" \
  -v agenc-data:/root/.config/agenc-moltbook \
  agenc-moltbook

Project Structure

agenc_agent/
  __init__.py          # Package version and exports
  cli.py               # CLI entry point
  config.py            # Constants and configuration
  persona.py           # Agent persona definition
  memory.py            # Persistent memory and state
  agent.py             # Main orchestrator
  models.py            # Pydantic models for API validation
  task_hunter.py       # Autonomous task hunting and earnings
  autoclaim.py         # Aggressive fee position auto-claiming
  proofs.py            # ZK proof generation utilities
  http_utils.py        # Retry logic with exponential backoff
  clients/
    grok.py            # xAI Grok API client
    moltbook.py        # Moltbook API client
    twitter.py         # X/Twitter API v2 client
    bags.py            # Bags trading and fee collection
    solana.py          # AgenC Solana protocol SDK (read-only)
    simple_client.py   # Solana transaction builder (write)
    wallet.py          # Secure keypair management
examples/
  task_hunter_test.py  # Task hunter integration test
tests/
  test_*.py            # Unit and integration tests

Agent Persona

The agent is configured with a specific persona that:

  • Represents AgenC Protocol and the Tetsuo team
  • Is technically rigorous but approachable
  • Has strong opinions on privacy and surveillance
  • Uses dry humor, no emojis, lowercase style
  • Never shills - lets the work speak for itself
  • Engages genuinely with other agents

Edit agenc_agent/persona.py to customize.

Behavior

Heartbeat Cycle

Every heartbeat (default 4 hours), the agent:

  1. Checks claim status
  2. Fetches the hot feed
  3. Evaluates posts for engagement (max 3 per heartbeat)
  4. Upvotes and/or comments on relevant posts
  5. Maybe creates a new post (30% chance, respecting 30-min cooldown)
  6. Queries on-chain AgenC tasks (if Solana configured)
  7. Cross-posts to X (if enabled)
  8. Saves memory and state

Engagement Logic

The agent uses Grok to decide whether to engage with each post based on:

  • Relevance to privacy, agents, crypto, AI topics
  • Whether there's something substantive to add
  • Authenticity of potential engagement

Memory

Persistent memory stored in ~/.config/agenc-moltbook/:

  • credentials.json - Moltbook API key and registration info (0600 permissions)
  • memory.json - Posts made, comments, follows, conversation history
  • state.json - Runtime state like last check time

Memory lists are automatically capped (200 posts, 500 comments) to prevent unbounded growth.

Security Notes

  • Credentials are stored locally with restricted file permissions (0600)
  • No logs of conversations are sent anywhere
  • The agent only accesses Moltbook, xAI, Twitter, and Solana RPC APIs
  • All state is local - delete the config directory to reset
  • Graceful shutdown on SIGINT/SIGTERM preserves state
  • HTTP requests retry with exponential backoff on transient failures

v1.2.0 Security Hardening

  • Input validation - All Bags API inputs are validated (mint addresses, amounts, slippage)
  • Config validation - Required API keys validated at startup with clear error messages
  • Rate limiting - Solana RPC calls rate-limited to prevent endpoint throttling
  • Typed responses - Pydantic models validate API response structure
  • Specific exceptions - No bare except: blocks; all exceptions caught by type
  • Placeholder hash protection - Poseidon hash placeholder requires explicit AGENC_ALLOW_PLACEHOLDER_HASH=1 env var
  • Wallet export safeguard - Exporting wallet requires i_understand_the_risks=True parameter

Costs

xAI API pricing applies. Each heartbeat makes:

  • 1 feed fetch (no LLM call)
  • Up to 10 engagement decision calls (short prompts)
  • Up to 3 comment generation calls
  • 0-1 post generation calls

Roughly ~$0.10-0.50 per heartbeat depending on engagement.

License

GPL 3.0


Built by the Tetsuo team.

About

Official Moltbook agent for AgenC Privacy Protocol. Autonomous AI agent powered by Grok, built on Solana.

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •