Skip to main content
This tutorial demonstrates how to create a research agent that receives SOL payments from users before executing tasks. The agent analyzes investment-related queries and retrieves data from Web3 tools.

Overview

The agent leverages:
  • gpt-4o model from OpenAI for language processing.
  • CodeAgent to orchestrate a series of steps toward a final result.
  • AgentRuntime to connect clients to the agent and manage execution.
  • Clients:
    • SimpleMessageClient for local testing with predefined messages.
    • (Optional) TwitterMentionClient for processing mentions on Twitter.
  • Web3 Tools:
    • get_coin_price (CoinGecko) to fetch real-time cryptocurrency prices.
    • get_token_profile (DexScreener) to retrieve token profiles.
  • A Pricing Mechanism using Solana (SOL) payments. The agent will validate payment before executing the task.

Payment & Transaction Requirements

To use the agent, a client (user) must provide a task with either:
  • A link to a Solana transaction (e.g., from Solscan)
  • A transaction signature on the Solana blockchain

Setup

  1. Local Environment & Galadriel Installation:
  2. Agent Wallet Creation: The agent needs a Solana wallet to receive payments. If you don’t have one, create a new one. The tutorial is described in Wallet Tutorial.
  3. Environment Variables Configuration: Rename template.env to .env and populate it with your OpenAI API key, agent wallet address, and optional Twitter API credentials (if using TwitterMentionClient):
    • Make sure you have configured SOLANA_KEY_PATH in .agents.env file to point the path to your Solana wallet
  4. Agent Code (agent.py): Create a file named agent.py with the following Python code. Remember to replace placeholders with your actual values.
    Code Explanation:
    • Imports: Imports necessary libraries and modules.
    • Environment Variables: Loads environment variables from a .env file.
    • Model Setup: Initializes the LiteLLMModel with the specified model ID and API key.
    • Tool Setup:
      • Initializes coingecko.get_coin_price and dexscreener.get_token_profile
    • Agent Setup:
      • Initializes the CodeAgent with the specified tools
    • Client Setup:
      • Initializes the SimpleMessageClient with a sample question and Solana transaction link.
    • Runtime Setup:
      • Initializes the AgentRuntime with the agent, pricing, input, and output.
  5. Run the agent:

Optional: Running the agent with Twitter Client

To use the Twitter client, you have to set TWITTER_CONSUMER_API_KEY, TWITTER_CONSUMER_API_SECRET, TWITTER_ACCESS_TOKEN and TWITTER_ACCESS_TOKEN_SECRET environment variables defined inside .env file.
  1. Uncomment Twitter related code snippets:
    • TwitterMentionClient import statement
    • twitter_client initialization with the proper credentials
    • Pass twitter_client client to the AgentRuntime arguments for inputs and outputs
  2. Run the agent:
The agent will now monitor Twitter mentions, check the transaction signature for payment, and provide its analysis if payment validation is successful.