Skip to main content
This quickstart covers:
  1. Setting up the dev environment
  2. Creating and running a simple agent that uses the web search tool
  3. 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 galadriel Python package.

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.

Running the Agent

Execute the script:
When the agents starts to execute the task, it prints the output similar to this one:
Which will be followed by more steps until the results reaches the output

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 Galadriel CLI to create a new wallet:
And get airdropped by running:
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:
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.
Next, update the 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.
Now letโ€™s update the clientโ€™s input to ask a Web3-specific question that will utilize our new market data tools:

Running the Agent

Execute the script:
When you run the script, the agent will:
  1. Fetch the current market data for DAIGE token and its Raydium trading pairs
  2. Check if the current price meets our condition (below 0.5 USD)
  3. If the condition is met, execute a swap of 0.001 SOL to DAIGE tokens
  4. Output the transaction hash of the completed swap
The agent will output something like:
You can verify this transaction on Solana Explorer by visiting https://explorer.solana.com/ or https://solscan.io/.

๐ŸŽ‰ 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: Happy coding! ๐Ÿš€