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 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
Agent Code
Let’s extend the web search agent with Web3 capabilities to fetch real-time market data.
Modify your script to include:
We are going to use Dexscreener to fetch market data. Dexscrener is a widely used Web3 tool to monitor crypto market data like prices, new tokens, etc.
Modify the CodeAgent
initialization:
Note additional_authorized_imports=["json"]
parameter in the CodeAgent
initialization.
It is required because dexscreener.fetch_market_data
imports json
module and the Python interpreter doesn’t allow imports by default outside of a safe list.
Update the client’s input by asking a Web3-specific question:
Running the Agent
Execute the script:
You should receive an output similar to:
🎉 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
Happy coding! 🚀