> loading_
# How to leverage AI-powered descriptions for dynamically generated tools.
# This example shows the conceptual flow of how the agent now enriches
# tools created from a contract ABI.
from langchain.tools import DynamicStructuredTool
from web3agent.agent import initialize_agent # Fictionalized module
from web3agent.utils import get_abi, get_natspec # Fictionalized helpers
from web3agent.llm import generate_ai_description # Fictionalized LLM call
# 1. Define the target contract and get its ABI and NatSpec
contract_address = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" # USDC
contract_abi = get_abi(contract_address)
natspec = get_natspec(contract_address)
# 2. Dynamically create tools with AI-generated descriptions
enriched_tools = []
for function_abi in contract_abi:
if function_abi.get('type') == 'function':
# --- NEW: AI Autoresearch Step ---
# Previously, the description was a generic template.
# Now, we generate a rich, semantic description using an LLM.
ai_description = generate_ai_description(function_abi, natspec)
# Example ai_description for 'transfer(address,uint256)':
# "Transfers a specific amount of the token to a designated address. Use this to send tokens to another wallet or contract."
# Create the tool using the new, smarter description
tool = DynamicStructuredTool.from_function(
func=create_contract_function_caller(contract, function_abi), # Your function caller
name=function_abi['name'],
description=ai_description, # <-- The intelligent description is used here
args_schema=create_args_schema(function_abi) # Your schema generator
)
enriched_tools.append(tool)
# 3. Initialize the agent with the intelligent toolset
# The agent now has a much better understanding of what each tool does,
# enabling it to form more accurate and complex plans.
agent = initialize_agent(enriched_tools, llm)
# 4. Run the agent with an abstract goal
# The agent can now correctly map "send USDC" to the 'transfer' tool
# because of the improved description.
agent.run("Send 150 USDC to vitalik.eth")