# Mythos Keeper Architecture

## Agent Loop

```
┌──────────────────────────────────────────────────────┐
│                    AGENT LOOP                         │
│                                                       │
│  ┌─────────┐    ┌─────────┐    ┌─────────┐          │
│  │  SENSE   │───▶│  THINK   │───▶│   ACT    │──┐      │
│  │ minia2a  │    │ eval    │    │ KeeperHub │  │      │
│  │ MCP      │    │ thresholds│   │ workflow  │  │      │
│  └─────────┘    └─────────┘    └─────────┘  │      │
│       ▲                                       │      │
│       └──────────── VERIFY ◀─────────────────┘      │
│                  minia2a onchain-read                 │
└──────────────────────────────────────────────────────┘
```

## MCP Integration

### minia2a → KeeperHub Bridge

minia2a MCP tools return structured data. The agent evaluates against thresholds and calls KeeperHub workflows.

```javascript
// Example: ETH price monitor
const price = await mcp.minia2a.dex_price({ chain: "base", pair: "ETH/USDC" });
if (price < THRESHOLD_BUY) {
  const result = await keeperhub.execute_transfer({
    chain: "base",
    token: "USDC",
    amount: "10",
    to: EXCHANGE_ROUTER
  });
  // Verify
  const balance = await mcp.minia2a.onchain_read({
    chain: "base",
    contract: USDC_ADDRESS,
    calldata: balanceOf(MY_WALLET)
  });
}
```

## KeeperHub Workflows

### 1. mythos-price-monitor (trigger: webhook)
- Input: { chain, pair, threshold, action }
- Steps:
  1. webhook trigger receives price data
  2. code action evaluates threshold
  3. protocol_action executes swap if triggered

### 2. mythos-contract-audit (trigger: webhook)
- Input: { chain, contractAddress }
- Steps:
  1. webhook trigger receives contract address
  2. code action runs security checks
  3. protocol_action logs result on-chain

### 3. mythos-x402-executor (trigger: webhook)
- Input: { serviceUrl, maxAmount }
- Steps:
  1. webhook trigger receives service URL
  2. code action validates x402 endpoint
  3. protocol_action executes payment + receives result

## Security

- **No private keys in agent code**: KeeperHub MPC wallets handle signing
- **Gas sponsorship**: KeeperHub sponsors gas for eligible workflows
- **MEV protection**: KeeperHub bundles transactions
- **Rate limiting**: Agent respects API limits

## Deployment

- minia2a: pm2 on AWS EC2 (99.81.245.60), cloudflared tunnel to minia2a.uk
- KeeperHub: Workflows deployed via REST API, MCP server at app.keeperhub.com/mcp
- Agent: Runs on same EC2 instance, cron-triggered or webhook-driven

## Verified Execution Proof

| # | Workflow | Method | Status | Proof |
|---|----------|--------|--------|-------|
| 1 | sep-eth-balance-test | REST POST | success | executionId: 3k1qflo6u5flu6uwkw5st |
| 2 | sep-eth-balance-test | MCP Wallet | success | executionId: mstsov1y66w2edrdxpvj1 |
| 3 | x402 payment (Base) | MCP Wallet | success | TX: 0x38510c... |
