-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path02_swap.py
35 lines (26 loc) · 1.13 KB
/
02_swap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from typing import List
import dotenv
from alphaswarm.agent import AlphaSwarmAgent
from alphaswarm.config import Config
from alphaswarm.core.tool import AlphaSwarmToolBase
from alphaswarm.tools.core import GetTokenAddress
from alphaswarm.tools.exchanges import ExecuteTokenSwap, GetTokenPrice
dotenv.load_dotenv()
config = Config(network_env="test") # Use a testnet environment (as defined in config/default.yaml)
# Initialize tools
tools: List[AlphaSwarmToolBase] = [
GetTokenAddress(config), # Get token address from a symbol
GetTokenPrice(config), # Get the price of a token pair from available DEXes given addresses
# GetTokenPrice outputs a quote needed for ExecuteTokenSwap tool
ExecuteTokenSwap(config), # Execute a token swap on a supported DEX
]
# Create the agent
llm_config = config.get_default_llm_config("anthropic")
agent = AlphaSwarmAgent(tools=tools, model_id=llm_config.model_id)
# Interact with the agent
async def main() -> None:
response = await agent.process_message("Swap 3 USDC for WETH on Ethereum Sepolia")
print(response)
if __name__ == "__main__":
import asyncio
asyncio.run(main())