Skip to main content

Goat adapter for SmolAgents

Project description

Smolagents Adapter for GOAT

Integrate the more than +200 onchain tools of GOAT with Smolagents, a framework for building agentic systems with small language models.

Installation

poetry add goat-sdk-adapter-smolagents

Usage

# --- Setup GOAT Wallet and Plugins (Example: Solana + SPL Token) --- 
import os
from dotenv import load_dotenv
from solders.keypair import Keypair
from solana.rpc.api import Client as SolanaClient
from goat_plugins.spl_token import spl_token, SplTokenPluginOptions
from goat_plugins.spl_token.tokens import SPL_TOKENS
from goat_wallets.solana import solana

# Load environment variables
load_dotenv()
solana_rpc_endpoint = os.getenv("SOLANA_RPC_ENDPOINT")
solana_wallet_seed = os.getenv("SOLANA_WALLET_SEED")
openai_api_key = os.getenv("OPENAI_API_KEY")

# Make sure environment variables are set
if not solana_rpc_endpoint or not solana_wallet_seed:
    raise ValueError("SOLANA_RPC_ENDPOINT and SOLANA_WALLET_SEED must be set in .env")

if not openai_api_key:
    raise ValueError("OPENAI_API_KEY must be set in .env to use GPT-4o")

client = SolanaClient(solana_rpc_endpoint)
keypair = Keypair.from_base58_string(solana_wallet_seed)
wallet = solana(client, keypair)

spl_token_plugin = spl_token(SplTokenPluginOptions(
    network="mainnet",
    tokens=SPL_TOKENS
))

# --- Import Smolagents and the GOAT Adapter --- 
from smolagents import OpenAIServerModel, ToolCallingAgent
from goat_adapters.smolagents import get_smolagents_tools

# --- Generate Smolagents Tools from GOAT --- 
goat_smolagents_tools = get_smolagents_tools(
    wallet=wallet,
    plugins=[spl_token_plugin]
)

# --- Define Smolagents Agent using GOAT Tools --- 
model = OpenAIServerModel(
    model_id="gpt-4o",
)

agent = ToolCallingAgent(
    tools=goat_smolagents_tools,
    model=model,
    add_base_tools=False  # Don't include Smolagents default tools
)

# Set custom system prompt
agent.prompt_templates["system_prompt"] = (
    "You are an expert analyst focused on the Solana blockchain and its SPL token ecosystem. "
    "You have access to specialized tools that can query SPL token balances and potentially other relevant information directly from the blockchain. "
    "Your task is to understand the user's question, use the appropriate tool(s) if necessary, and provide a clear, concise answer."
)

# --- Run the agent with a specific task ---
result = agent.run("What is the balance of USDC for my wallet?")
print(result)

Tool Collection

You can also create a Smolagents ToolCollection to manage your GOAT tools:

from smolagents import ToolCollection, ToolCallingAgent

# Create the tools first
goat_tools = get_smolagents_tools(wallet=wallet, plugins=[spl_token_plugin])

# Create a custom tool collection with your GOAT tools
my_tool_collection = ToolCollection(
    tools=goat_tools
)

# Now use this collection with your agent
agent = ToolCallingAgent(
    tools=my_tool_collection.tools,
    model=model,
    add_base_tools=False
)


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

goat_sdk_adapter_smolagents-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

goat_sdk_adapter_smolagents-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file goat_sdk_adapter_smolagents-0.1.0.tar.gz.

File metadata

  • Download URL: goat_sdk_adapter_smolagents-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.16 Linux/6.8.0-1021-azure

File hashes

Hashes for goat_sdk_adapter_smolagents-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa40a25d2963afa4c0052d5054244b07ef595276ea4c5c8929b0d7b4c48aa3fa
MD5 c6aa89d4df8c1ed3a82eb072ea4c9094
BLAKE2b-256 1fab5d11971ab59cab3025d44fcb55a47b8cc0c333f2c61a1c014a57506799ae

See more details on using hashes here.

File details

Details for the file goat_sdk_adapter_smolagents-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for goat_sdk_adapter_smolagents-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1cb4ecf80d2696cde9b0db57ee557ee848b8755a4b49b749420a348cbabc1a1
MD5 f759c51be803f0eca889a389a5bf48cc
BLAKE2b-256 652c99ad85342168477b4a188a2b868a4a7668323eeeced3820bc5e837cfd0f4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page