# ToolAgent

**ToolAgents** are atomic, self-contained modules in AgentGPT that automate individual tasks within a workflow. Each ToolAgent combines GPT-4’s reasoning with blockchain execution to perform actions like swapping tokens, screening compliance, or bridging assets—ensuring end-to-zero human intervention.

**Key Traits**:

* **Specialization**: 1 ToolAgent = 1 task (e.g., swap, audit, bridge).
* **Interoperability**: Link ToolAgents to create complex workflows.
* **Self-Healing**: Auto-retry failed tasks across alternative routes.

***

#### **ToolAgent Architecture**

```mermaid
flowchart LR  
    Strategy{{GPT-4 Strategy}} --> ToolAgent1[DEX Swap ToolAgent]  
    Strategy --> ToolAgent2[Cross-Chain Bridge ToolAgent]  
    Strategy --> ToolAgent3[Compliance Check ToolAgent]  
    ToolAgent1 & ToolAgent2 & ToolAgent3 --> Executor[ERC-7645 Execution Layer]  
    Executor --> Blockchain[Ethereum, Solana, etc.]  
    Blockchain --> Auditor[ZK-Proof Auditor]  
    style ToolAgent1 fill:#8f8,stroke:#333  
```

***

#### **Core Components of a ToolAgent**

| Component            | Role                                   | Example                              |
| -------------------- | -------------------------------------- | ------------------------------------ |
| **Logic Engine**     | GPT-4 generates task-specific logic    | "Route swap via lowest-slippage DEX" |
| **Smart Adapter**    | Translates logic into blockchain calls | Uniswap v4 Router interaction        |
| **Data Feeder**      | Pulls real-time on/off-chain data      | CoinGecko prices + DEX liquidity     |
| **Compliance Guard** | Enforces regulatory checks             | OFAC screening via Chainlink         |

***

#### **ToolAgent Lifecycle**

1. **Initialization**:
   * GPT-4 selects required ToolAgents based on user intent (e.g., "*Pay suppliers in 5 currencies weekly*").
2. **Execution**:
   * Each ToolAgent autonomously handles its task:

     ```python
     # Pseudocode Example: Swap & Bridge ToolAgents  
     def execute_payment(amount):  
         swap_tool = ToolAgent("DEX_SWAP", params={"from": "ETH", "to": "USDC"})  
         bridge_tool = ToolAgent("BRIDGE", params={"chain": "base"})  
         swap_tool.run(amount)  
         bridge_tool.run(swap_tool.output)  
     ```
3. **Validation**:
   * ZK-proofs verify on-chain execution correctness.

***

#### **Popular ToolAgent Examples**

**1. Gas Optimizer ToolAgent**

Weighs gas costs across chains and selects the cheapest route.

* **Input**: ETH → USDC swap.
* **Action**: Chooses Arbitrum over Ethereum, saving 89% in fees.

**2. Compliance Screener ToolAgent**

* **Checks**:
  * Sanctioned addresses
  * Jurisdictional tax rules
  * FATF Travel Rule adherence
* **Enterprise Impact**: $1.5M fines avoided annually.

**3. Emergency Liquidator ToolAgent**

* **Function**: Sells collateral if DeFi position nears liquidation.
* **Triggers**: Health factor < 1.2
* **Success Rate**: 98.7%

***

#### **ToolAgent Performance**

| Metric              | ToolAgent Avg. | Manual Execution |
| ------------------- | -------------- | ---------------- |
| Time per Task       | 2.1s           | 15min            |
| Cost Accuracy       | 97%            | 65%              |
| Error Recovery Rate | 94%            | 23%              |

***

#### **Security & Audits**

* **Isolated Execution**: Each ToolAgent runs in its own trusted execution environment (TEE).
* **Zero-Day Protection**: Auto-blacklists addresses involved in suspicious transactions.
* **Audits**: Formal verification by Certora and OpenZeppelin.

***

#### **Building Custom ToolAgents**

**Template Structure**

```yaml
name: "TaxReportingToolAgent"  
description: "Auto-generates crypto tax reports per jurisdiction"  
steps:  
  - collect_data:  
      sources: [chain_data, exchange_APIs]  
  - apply_rules:  
      jurisdictions: ["US", "EU"]  
  - generate_output:  
      formats: [PDF, CSV]  
```

**SDK Integration**

```python
from agentgpt.toolagents import BaseToolAgent  

class CustomSwapToolAgent(BaseToolAgent):  
    def __init__(self):  
        self.task = "dex_swap"  
        self.supported_chains = ["ethereum", "polygon"]  

    def execute(self, params):  
        # Custom swap logic here  
        return tx_hash  
```


---

# 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/tools/toolagent.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.
