- 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.102. Dev Environment
First, set up your local environment and then install thegaladriel Python package.
Create a Simple Web Search Agent
1. Agent Code
Create a file namedagent.py with the following Python code.
Add your OpenAI API Key.
Running the Agent
Execute the script: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-4omodel from OpenAI for agent reasoning.SimpleMessageClientto send and receive messages.AgentRuntimeto connect the agent to the client and execute tasks.DuckDuckGoSearchToolfor 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 Galadriel CLI to create a new wallet: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: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.
CodeAgent initialization with Web3-specific tools:
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.Running the Agent
Execute the script:- Fetch the current market data for DAIGE 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 DAIGE tokens
- Output the transaction hash of the completed swap
🎉 Gratz on Building Your First Agent!
You’ve successfully built both a generic web search agent and a Web3-focused agent using Galadriel. 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

