Quickstart
This quickstart covers:
Setting up the dev environment
Creating and running a simple agent that uses the web search tool
Creating and running a Web3 agent that uses the Dexscreener tool
โSetup
โ1. Requirements
Python >=3.10
โ2. Dev Environment
First, set up your local environment and then install the Lunet Python package.
Copy
โCreate a Simple Web Search Agent
โ1. Agent Code
Create a file named agent.py
with the following Python code.
Add your OpenAI API Key.
Copy
โRunning the Agent
Execute the script:
Copy
When the agents starts to execute the task, it prints the output similar to this one:
Copy
Which will be followed by more steps until the results reaches the output
Copy
โHow it Works
This simple agent receives a question from the client and executes a series of reasoning steps to provide an answer. It autonomously determines when to search the web.
It leverages:
gpt-4o
model from OpenAI for agent reasoning.SimpleMessageClient
to send and receive messages.AgentRuntime
to connect the agent to the client and execute tasks.DuckDuckGoSearchTool
for web-based information retrieval.
โCreate a Web3 Agent
โCreate Wallet
Before creating a Web3 agent, youโll need a Solana wallet. You can either create a new one or import an existing wallet.
โCreate a New Wallet
Use the LunetCLI to create a new wallet:
Copy
And get airdropped by running:
Copy
For details about how to use the wallet, see wallet setup.
โAgent Code
Letโs extend the web search agent with Web3 capabilities to fetch real-time market data and execute an onchain swap.
Modify your script to include:
Copy
Weโll use Dexscreener to fetch real-time market data and Raydium for executing token swaps based on market conditions.
Dexscreener is a popular Web3 platform for monitoring cryptocurrency market data including prices, trading volumes, and new token listings.
Raydium is Solanaโs leading decentralized exchange (DEX) that enables automated market making and token swaps with deep liquidity.
First, we need to initialize the Solana wallet that was created in the previous step to allow agents to access it. This wallet will be used to sign transactions and interact with the Solana blockchain.
Copy
Next, update the CodeAgent
initialization with Web3-specific tools:
Copy
Note additional_authorized_imports=["json"]
parameter in the CodeAgent
initialization. It is required because dexscreener.SearchTokenPairTool()
imports json
module and the Python interpreter doesnโt allow imports by default outside of a safe list.
Now letโs update the clientโs input to ask a Web3-specific question that will utilize our new market data tools:
Copy
โRunning the Agent
Execute the script:
Copy
When you run the script, the agent will:
Fetch the current market data for token and its Raydium trading pairs
Check if the current price meets our condition (below 0.5 USD)
If the condition is met, execute a swap of 0.001 SOL to tokens
Output the transaction hash of the completed swap
The agent will output something
โ๐ Gratz on Building Your First Agent!
Youโve successfully built both a generic web search agent and a Web3-focused agent using Lunet.
But this is just scratching the surface - whatโs next? To unlock more capabilities for your agent, check out these resources:
Tutorials section with Agents, Client, Wallet
Deep dive into fundamental concepts like AgentRuntime
Real-world examples of building more complex agents
Happy coding! ๐
Last updated