# Tracking Agents

AgentGPT’s agent tracking system provides end-to-end visibility into AI-driven operations on blockchain networks. Track:

* 🧠 **AI Decision Making**: GPT-4 reasoning traces mapped to smart contract calls
* ⛓ **On-Chain Actions**: Gas usage, transactions, and contract interactions
* 🎯 **Workflow Outcomes**: Success/fail states with ZK-proof verification

***

#### **Architecture**

```mermaid
flowchart TD  
    Agent[Autonomous Agent] -->|Logs| Tracker[Tracking Engine]  
    Tracker -->|Proofs| Blockchain  
    Tracker -->|Analytics| Dashboard  
    Blockchain -->|Confirmation| Agent  
    style Tracker fill:#8f8,stroke:#333  
```

**Components**:

* **Smart Contract Hooks**: ERC-6551 Agent Binding Standard
* **AI Model Profiler**: Tracks GPT-4 inference costs and latency
* **Cross-Chain Verifier**: Validates actions across 15+ networks

***

#### **Setup & Configuration**

**Step 1: Install Tracking Module**

```bash
npm install @agentgpt/tracker  
# OR  
pip install agentgpt-tracker  
```

**Step 2: Initialize Tracking Session**

```typescript
import { initTracker } from '@agentgpt/tracker';  

initTracker({  
  chainId: 137, // Polygon Mainnet  
  agentType: 'DEFI_ARBITRAGE',  
  zkCircuit: 'agent_proof_v2.zk',  
  gasToken: 'AGPT',  
  maxGasPrice: '45 gwei'  
});  
```

**Step 3: Track Agent Activity**

```solidity
// Auto-injected in AgentGPT workflows  
function trackAgentAction(  
    bytes32 agentId,  
    string memory actionType,  
    bytes memory proof  
) public returns (uint256 trackingNonce) {  
    // Anchors to ERC-6551 registry  
    emit AgentAction(agentId, actionType, proof);  
}  
```

***

#### **Key Tracking Metrics**

| Metric               | Description                          | Blockchain Proof        |
| -------------------- | ------------------------------------ | ----------------------- |
| **Decision Latency** | Time from GPT-4 input to on-chain TX | Transaction Timestamp   |
| **Gas Efficiency**   | Cost per completed workflow          | GasUsed × GasPrice      |
| **Success Rate**     | Percentage of fully executed tasks   | ZK-SNARK Finality Proof |
| **Model Accuracy**   | AI prediction vs actual outcome      | Oracle Attestation      |

***

#### **Custom Tracking Rules**

**YAML Configuration**

```yaml
tracking_rules:  
  - agent_type: "NFT_MINTER"  
    required_proofs:  
      - "ERC-4519_METADATA"  
      - "ROYALTY_COMPLIANCE"  
    alert_thresholds:  
      gas_exceeded: "0.1 ETH"  
      delay_blocks: 12  
  - agent_type: "CROSS_CHAIN_SWAP"  
    validation:  
      bridges: ["LayerZero", "Wormhole"]  
      price_tolerance: 1.5%  
```

**CLI Monitoring**

```bash
agentgpt tracker monitor \  
    --agent 0x... \  
    --metrics gas,latency \  
    --export-format csv  
```

***

#### **Real-Time Dashboard**

**Web3 Interface Features**:

* Cross-chain agent status aggregation
* Liquidity heatmaps for DeFi agents
* NFT minting efficiency analytics

**Sample Output**:

```
AGENT 0x... [POLYGON]  
┌─────────────────────┬──────────────┬────────────┐  
│ Metric              │ Current      │ Target     │  
├─────────────────────┼──────────────┼────────────┤  
│ Gas/Transaction     │ 0.0031 ETH   │ 0.0028 ETH │  
│ Decisions/Minute    │ 142          │ 150        │  
│ Cross-Chain Success │ 98.7%        │ 95%        │  
└─────────────────────┴──────────────┴────────────┘  
Active Alerts: 0 | Pending Actions: 5  
```

***

#### **Troubleshooting**

**Common Issues**:

| Error Code | Scenario                     | Resolution                                   |
| ---------- | ---------------------------- | -------------------------------------------- |
| AGT-401    | Agent TX Stuck for >6 Blocks | `agentgpt tracker accelerate --gas-bump 40%` |
| AGT-412    | ZK Proof Validation Failed   | Regenerate proofs with updated circuits      |
| AGT-430    | Insufficient Tracking Budget | Deposit AGPT to agent wallet                 |

**Recovery Protocol**:

```solidity
function emergencyAgentPause(bytes32 agentId) external {  
    require(hasRole(ADMIN_ROLE, msg.sender));  
    agents[agentId].status = AgentStatus.PAUSED;  
    emit AgentPaused(agentId, block.timestamp);  
}  
```

***

#### **Compliance & Security**

**Data Retention Policy**:

```yaml
storage_policy:  
  on_chain:  
    duration: "6 years"  
    standard: "ERC-4519"  
  off_chain:  
    location: "IPFS/Arweave"  
    encryption: "AES-256-GCM"  
```

**Audit Controls**:

```python
def generate_audit_report(agent_id):  
    return ZKProver.validate(  
        circuit="agent_audit_v3.zk",  
        public_inputs={"agentId": agent_id},  
        proof=load_proof(agent_id)  
    )  
```

***

**Quick Start**:

1. Deploy agent contract:

   ```bash
   agentgpt deploy --type defi --network polygon  
   ```
2. Start tracking:

   ```bash
   agentgpt tracker start 0x... --metrics all  
   ```
3. Monitor performance:

   ```bash
   agentgpt dashboard open --agent 0x...  
   ```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://agent-gpt.gitbook.io/agent-gpt/usage/tracking-agents.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
