kikocis/Based-Agent public
Changesets · Branches · Tags · Compare
| Changeset | 8a8f406d160acbd021e9c06b150b1c37f1a352f42a966f8a9fb2d2c88498e4fb |
|---|---|
| Author | Lincoln Murr <lincoln.murr@coinbase.com> · 2024-10-26 11:07 -04:00 |
| Committer | Lincoln Murr <lincoln.murr@coinbase.com> · 2024-10-26 11:07 -04:00 |
| Parents | af54ff081530 |
2 files changed
modified Based-Agent/agents.py +22 −4
| @@ -8,8 +8,11 @@ | ||
| 8 | 8 | from typing import Union |
| 9 | 9 | from web3 import Web3 |
| 10 | 10 | from web3.exceptions import ContractLogicError |
| 11 | +from cdp.errors import ApiError, UnsupportedAssetError | |
| 12 | + | |
| 13 | + | |
| 11 | 14 | # Configure the CDP SDK |
| 12 | -Cdp.configure_from_json("./examples/based_agent/cdp_api_key.json") | |
| 15 | +Cdp.configure_from_json("./Based-Agent/cdp_api_key.json") | |
| 13 | 16 | |
| 14 | 17 | # If you want to create a wallet on Base Mainnet, use Wallet.create(network_id="base-mainnet") and comment out the faucet line |
| 15 | 18 | agent_wallet = Wallet.create() |
| @@ -33,9 +36,23 @@ | ||
| 33 | 36 | asset_id: Asset identifier ("eth", "usdc" are the only supported values) or contract address of another ERC-20 token. Unless the asset is ETH or USDC, you must use the contract address of the token. |
| 34 | 37 | destination_address: Recipient's address |
| 35 | 38 | """ |
| 36 | - transfer = agent_wallet.transfer(amount, asset_id, destination_address) | |
| 37 | - transfer.wait() | |
| 38 | - return f"Transferred {amount} {asset_id} to {destination_address}" | |
| 39 | + try: | |
| 40 | + # Check if the asset exists and is ready for transfer | |
| 41 | + try: | |
| 42 | + Asset.fetch(asset_id) | |
| 43 | + except ApiError as e: | |
| 44 | + if e.api_code == "400": | |
| 45 | + return f"The asset {asset_id} is not yet available for transfer. It may have been recently deployed. Please try again in about 30 minutes." | |
| 46 | + else: | |
| 47 | + raise e | |
| 48 | + | |
| 49 | + transfer = agent_wallet.transfer(amount, asset_id, destination_address) | |
| 50 | + transfer.wait() | |
| 51 | + return f"Transferred {amount} {asset_id} to {destination_address}" | |
| 52 | + except UnsupportedAssetError as e: | |
| 53 | + return f"Error: The asset {asset_id} is not supported on this network. It may have been recently deployed. Please try again in about 30 minutes." | |
| 54 | + except Exception as e: | |
| 55 | + return f"Error transferring asset: {str(e)}. If this is a custom token, it may have been recently deployed. Please try again in about 30 minutes, as it needs to be indexed by CDP first." | |
| 39 | 56 | |
| 40 | 57 | def get_balance(asset_id): |
| 41 | 58 | """Get the balance of a specific asset in the agent's wallet. |
| @@ -174,6 +191,7 @@ | ||
| 174 | 191 | L2_RESOLVER_ADDRESS_MAINNET = "0xC6d566A56A1aFf6508b41f6c90ff131615583BCD" |
| 175 | 192 | L2_RESOLVER_ADDRESS_TESTNET = "0x6533C94869D28fAA8dF77cc63f9e2b2D6Cf77eBA" |
| 176 | 193 | |
| 194 | +# Create registration arguments for Basenames | |
| 177 | 195 | def create_register_contract_method_args(base_name: str, address_id: str, is_mainnet: bool) -> dict: |
| 178 | 196 | """ |
| 179 | 197 | Create registration arguments for Basenames. |
modified Based-Agent/run.py +5 −5
| @@ -137,17 +137,17 @@ | ||
| 137 | 137 | print("\nAvailable modes:") |
| 138 | 138 | print("1. chat - Interactive chat mode") |
| 139 | 139 | print("2. auto - Autonomous action mode") |
| 140 | - print("3. openai - AI-to-agent conversation mode") | |
| 140 | + print("3. two-agent - AI-to-agent conversation mode") | |
| 141 | 141 | |
| 142 | 142 | choice = input("\nChoose a mode (enter number or name): ").lower().strip() |
| 143 | 143 | |
| 144 | 144 | mode_map = { |
| 145 | 145 | '1': 'chat', |
| 146 | 146 | '2': 'auto', |
| 147 | - '3': 'openai', | |
| 147 | + '3': 'two-agent', | |
| 148 | 148 | 'chat': 'chat', |
| 149 | 149 | 'auto': 'auto', |
| 150 | - 'openai': 'openai' | |
| 150 | + 'two-agent': 'two-agent' | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | if choice in mode_map: |
| @@ -160,7 +160,7 @@ | ||
| 160 | 160 | mode_functions = { |
| 161 | 161 | 'chat': lambda: run_demo_loop(based_agent), |
| 162 | 162 | 'auto': lambda: run_autonomous_loop(based_agent), |
| 163 | - 'openai': lambda: run_openai_conversation_loop(based_agent) | |
| 163 | + 'two-agent': lambda: run_openai_conversation_loop(based_agent) | |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | print(f"\nStarting {mode} mode...") |
| @@ -168,4 +168,4 @@ | ||
| 168 | 168 | |
| 169 | 169 | if __name__ == "__main__": |
| 170 | 170 | print("Starting Based Agent...") |
| 171 | - main() | |
| No newline at the end of the file | ||
| 171 | + main() |