Using Bedrock Agents for Blockchain Analysis and Decentralized Finance Assistance
Blockchain Challenges and Opportunities
- Blockchains present novel opportunities for new applications such as decentralized finance and enabling cross-border micro-payments.
- However, working with blockchains also presents unique challenges:
- Technical challenges, such as managing cryptocurrency wallet private keys and analyzing complex blockchain data structures.
- Large language models and generative AI agents can help address these challenges.
Use Case 1: Analyzing Blockchain Data using Bedrock Agents
Building the Data Analyst Agent
- Create the Bedrock Agent: The team used the CLA anthropic kou model due to the limited context embedded in the agent itself.
- Define the Agent's Behavior: They created an agent instruction that defines the agent as a SQL developer creating queries for Amazon Athena's Bitcoin and Ethereum databases.
- Add Additional Context: The team used Bedrock's advanced prompt feature to embed the actual schemas for the Bitcoin and Ethereum databases, providing more context for the agent.
- Create an Action Group: The action group defines an API for invoking a Lambda function that executes the SQL query on Amazon Athena and returns the response to the agent.
Demonstrating the Agent's Capabilities
- The agent can understand natural language queries and translate them into SQL queries against the AWS public blockchain data sets.
- Examples include finding the largest Bitcoin transaction, number of Ethereum contracts created, USDC transfers, and most expensive Ethereum transaction.
Key Learnings
- LLMs are inherently aware of popular tokens and smart contracts, automatically recognizing them without additional user input.
- The agent can automatically convert hexadecimal values in Bitcoin blocks to readable text.
- Implementing an error-handling technique where the agent can retry with a modified query is crucial for handling exceptions when querying blockchain data.
- Amazon Managed Blockchain Query can be a more cost-efficient solution for certain use cases compared to scanning large amounts of blockchain data.
Use Case 2: Bedrock Agent as a Decentralized Finance Assistant
Objectives for the DeFi Assistant Agent
- Research: Gather on-chain and off-chain data to inform trading and investment strategies.
- Trading: Securely manage the user's crypto wallet to execute transactions on their behalf.
- Protection: Leverage a knowledge base of security threats to protect the user from interacting with compromised DeFi protocols.
Agent Interaction and Architecture
- The agent interacts with the user through a text-based interface built using Streamlit.
- The agent's action groups include:
- Lending rate: Fetches current lending rates from the blockchain.
- Wallet management: Constructs transactions, signs them using the user's KMS-stored wallet, and executes them.
- The agent uses session attributes to identify the user and their associated wallet.
- A knowledge base built with Amazon Opensearch Service stores security threat data from off-chain sources, which the agent uses to protect the user.
Future Expansion Opportunities
- Implementing multi-party wallets for increased security.
- Enabling peer-to-peer payments.
- Developing LLM-powered gaming assistants.
Conclusion
The presenters have demonstrated how Bedrock agents can be leveraged to address the challenges of working with blockchains, enabling natural language analysis of blockchain data and secure, intelligent interactions with decentralized finance protocols.