Talk to Your Cronos Data: AI Agent based User Experiences for Blockchain Insights

Deep Chenna
Google Cloud - Community
8 min readNov 8, 2024

Web3, with its decentralized and often complex data structures, presents significant user experience challenges. Navigating blockchain networks and accessing relevant information can be daunting for non-technical users. This is where AI agents can play a crucial role. By acting as intelligent assistants, they can simplify data access by understanding user needs expressed in natural language and translating them into the necessary queries for retrieving information from the blockchain. This abstraction layer empowers users to interact with Web3 services in a more intuitive and user-friendly way, fostering wider adoption and a smoother user experience overall.

In this blog post, we will delve into the process of using Google cloud Agent Builder to create AI Agents capable of interacting with users in a natural, conversational manner. This agent will be designed to interpret user queries posed in everyday language, then autonomously retrieve the relevant information from the Cronos zkEVM BigQuery dataset. The final step involves presenting the extracted insights to the user in a clear, easily understandable format. By bridging the gap between complex blockchain data and human comprehension, this AI agent has the potential to unlock valuable knowledge and facilitate more accessible interactions with the Cronos zkEVM ecosystem.

For example, such an AI agent could:

  • Retrieve and explain all the crypto transactions of a specific user or business;
  • Create accounting or tax reports on behalf of specific users or businesses;
  • Monitor the behavior of top blockchain users in order to identify trading opportunities and notify a user about them;
  • Monitor transaction patterns and notify a business about potential fraud or risks;
  • Continuously rebalance a cryptocurrency portfolio or execute trading strategies based on goals set by specific users.

We will explore the technical intricacies, design considerations, and potential benefits of implementing such a solution.

Cronos zkEVM

Cronos zkEVM is a Layer 2 blockchain scaling solution built on Ethereum, leveraging zkSync’s advanced ZK Stack technology. Cronos zkEVM is an open-source project resulting from a partnership between Cronos Labs and the engineering teams at Matter Labs, the team behind zkSync, and Crypto.com. Cronos zkEVM is directly connected to the Ethereum Mainnet via a shared bridge, ensuring enhanced security and efficiency. Cronos zkEVM is specifically designed to support the growth of the Cronos ecosystem as the Ethereum Layer 2 market expands. With the capability to process over 100 transactions per second at some of the lowest fees among blockchain solutions, Cronos zkEVM is poised to become a significant player in the DeFi space. Cronos recently announced an ambitious roadmap that aims to enable a wide range of A.I. agents to pay, receive and move value over its blockchain infrastructure.

Google Cloud BigQuery

Google Cloud BigQuery is a fully managed, serverless data warehouse that enables scalable analysis over petabytes of data. It’s like a giant, super-fast spreadsheet in the cloud where you can store and analyze massive datasets without worrying about infrastructure.

Cronos zkEVM BigQuery Datasets

Indexed Cronos zkEVM blockchain data is available as BigQuery Dataset via Analytics hub. BiqQuery Dataset offers you access to reliable data with you the overhead of operating nodes or developing and maintaining an indexer. You can now query the full history of blocks, transactions & logs on Cronos zkEVM. This integration eliminates the complexities of running your own nodes or building and maintaining a dedicated indexer. By leveraging the BigQuery dataset, you gain the ability to seamlessly query the entire history of Cronos zkEVM, encompassing blocks, transactions, and logs. A similar dataset is available for the Cronos EVM blockchain, and both can be found on the Google Cloud Web3 Discover Page as follows:

Google Cloud Vertex AI

Google Cloud Vertex AI is a unified machine learning (ML) platform that aims to streamline the entire ML workflow, making it easier for data scientists and ML engineers to build, deploy, and manage AI models at scale.Think of it as a one-stop shop for all your AI needs on Google Cloud. It brings together various tools and services into a single platform, simplifying the process of building and deploying AI solutions.

Vertex AI Agent Builder

Google Cloud Vertex AI Agent Builder is a powerful tool that allows developers to easily create and deploy generative AI agents. These agents can understand natural language, engage in conversations, and perform tasks to help users.

Use case

To democratize blockchain data and enhance its accessibility, we’re exploring the use of AI to simplify complex information. Our goal is to develop an AI agent that empowers users to interact with on-chain data using natural language queries. This approach aims to provide a generative AI experience, making blockchain insights readily available to a broader audience.

Users can engage with the Talk to Cronos AI Agent as demonstrated in the following example.

Solution

This solution showcases how to connect Google Cloud’s Conversational AI agents with the Cronos zkEVM BigQuery public dataset. We establish this connection by utilizing Cloud Functions to build a custom datastore. This datastore possesses the ability to transform natural language queries into SQL queries and subsequently execute them on the dataset.

Here’s a breakdown of how the system works:

  1. User question: A user poses a question in plain language.
  2. Translation to SQL: An AI tool (NL2SQL) converts the question into SQL, a language that the database can interpret.
  3. Data retrieval: The SQL query is sent to the database (BigQuery), which locates and retrieves the relevant data.
  4. Response generation: The AI agent receives the data and presents it to the user. This could be the complete data table or a summarized answer, depending on the user’s request.

This workflow enables users to interact with the database using natural language, making the process more accessible and user-friendly.

Architecture

Pre-requisites

To work with Cronos Blockchain data using Google Cloud BigQuery, you’ll need a GCP account with billing enabled. We recommend the following IAM roles for optimal access, although less permissive roles may still be sufficient:

Additionally, ensure the following IAM policies are in place:

  • The Dialogflow CX service agent requires the Cloud Run invoker role.
  • The default Compute Engine service account (or your custom service account for Cloud Functions) needs both BigQuery Job User and BigQuery Data Viewer roles.

Cronos NL2SQL Cloud Function With AI Prompt

The Cronos NL2SQL Cloud function processes user questions in plain text. It combines these questions with a prompt that defines the Cronos zkEVM BigQuery Dataset schema and provides instructions on data interpretation. The function then calls the Google Cloud Generative AI model to generate SQL queries. These queries are executed on the Cronos zkEVM BigQuery Dataset, and the results are returned to the user.

Prompt should provide a clear and comprehensive explanation of the zkEVM Dataset. Ensure the explanation is suitable for Generative AI to understand and utilize the data effectively. Include guidance on how to interpret the dataset’s key elements and structures.Here is the example prompt designed to describe the zkEVM Dataset and how to interpret the data.

The cloud function accesses a file containing the prompt below to call the Gemini model.

Here’s how you can use prompts and user questions to generate the desired SQL code. Below is a sample code demonstrating this process.

def generate_sql(question: str, model_name: str = "gemini-1.5-pro") -> str:
"""Generates SQL query using an LLM"""

with open(f"{_current_dir}/zkevm-schema-prompt.template", "r", encoding="utf-8") as file:
schema_prompt = file.read().strip()

prompt = "schema = " + schema_prompt + " question =" + question
gen_llm = GenerativeModel(model_name)
try:
logger.info(f"Prompting {model_name}")
result = gen_llm.generate_content(prompt).candidates[0].content.parts[0].text
return _extract_sql_from_markdown(result)
except Exception:
logger.error(f"Failed to generate or extract query", exc_info=True)
raise

The complete function code is available in this Link.

AI Agent Data Store Tool

Data stores, which can include websites, documents, structured data, and external data sources, are utilized by AI agents to retrieve answers to user queries. The AI agent searches the designated data sources and summarizes the relevant information into a coherent response when a user poses a question.

Our solution leverages the Cronos zkEVM BigQuery Dataset functions as the AI agent’s data repository. We utilize an NL2SQL cloud function to extract only the relevant data for each user query, rather than importing the entire dataset. Additionally, we’ve developed an OpenAPI DataStore tool that empowers the AI agent to invoke the cloud function dynamically in response to user questions.

Talk to Cronos — AI Agent

To build an AI agent using Vertex AI Agent Builder, you must define the agent’s goal and provide instructions on how it should achieve this goal based on user queries.

For example, in the “Talk to Cronos” AI agent, we instruct the agent to utilize the Data Store tool to retrieve the necessary information to respond to user questions. If the tool returns a single tabular row with a single result, the agent is instructed to state the result. However, if the tool returns multiple tabular rows, the agent is instructed to reply with the data as is.

The instructions can be programmed to suit the specific use case.

See the AI agent in action with these example conversations:

Conclusion

In conclusion, the integration of AI agents into Web3 applications holds immense potential for improving user experience and accessibility. By leveraging the power of AI, such as through Google Cloud’s Vertex AI and Agent Builder, we can create intelligent assistants capable of understanding natural language queries and seamlessly interacting with blockchain data. This empowers users to navigate complex information and extract valuable insights in a user-friendly manner. Ultimately, users and businesses will communicate their goals, and deploy a wide range of semi-autonomous AI agents powered by Cronos to define and execute strategies aimed at achieving these goals.

Furthermore, the ability to combine on-chain and off-chain data provides a unified and comprehensive view for users. Dapps can leverage this integration to offer intuitive access to a wealth of information, simplifying the user experience and fostering wider adoption of Web3 technologies. As AI continues to advance, we can anticipate even more sophisticated and seamless interactions with blockchain data, unlocking new possibilities for innovation and user engagement in the Web3 ecosystem.

--

--

Google Cloud - Community
Google Cloud - Community

Published in Google Cloud - Community

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Deep Chenna
Deep Chenna

Written by Deep Chenna

Web3 Customer Engineer, Google