Getting On-Chain Data for AI Agents
Using D.A.T.A Framework Backend for Query Generation
The D.A.T.A Framework provides a backend service that can generate dynamic queries based on user input. The backend supports various types of queries, including SQL, key-value queries, and vector-based queries for more advanced use cases such as AI-driven data retrieval.
How It Works:
User Input: The AI agent receives a natural language query from the user. The query could be something like, “What is the total gas used yesterday, and how many transactions occurred yesterday?”
Query Generation: The AI agent send the user query to D.A.T.A Framework backend, which processes the user input and generates the corresponding queries (SQL, key-value, vector) to fetch the required data. This is done by analyzing the query and breaking it down into structured data requests.
Query Types:
SQL Queries: For complex data retrieval from on-chain transaction histories, token transfers, gas usage, etc.
Key-Value Queries: For fetching specific data points like balances, token ownership, etc.
Vector Queries: For fetching off-chain data related to blockchain activity, such as relevant social media posts or market sentiment analysis.
Assembling the Query: After generating the necessary queries, the backend will assemble them into a response format. The output typically includes the SQL or key-value queries with placeholders for the result (e.g.,
{{result}}
), which will later be replaced with actual data.Query Execution: The generated queries are then posted to the D.A.T.A Framework backend. The backend handles querying the relevant blockchain or data sources, processes the data, and formats the response accordingly.
Response Handling: After execution, the provider info is returned to the AI agent in a structured format, allowing it to make informed decisions or trigger further actions.
Example Workflow:
User Query: “What is the total gas used yesterday, and how many transactions happened yesterday?”
AI Agent send the user query to D.A.T.A framework backend and then generates SQL Query:
AI Agent posts to D.A.T.A Backend: The AI agent sends these SQL queries to the D.A.T.A backend.
Response Format: The backend executes the queries, retrieves the data, and returns a structured response with the requested information:
2. Using Arbtrary AI Models to Generate Queries and Assemble Output
In addition to using the D.A.T.A Framework backend for query generation, any AI models can also be used to generate custom queries based on prompts. This allows developers to integrate the D.A.T.A Framework into their own AI models, giving them flexibility in how they interact with on-chain data.
How It Works:
Custom AI Agent: In this approach, the user or developer integrates the D.A.T.A Framework with their custom AI agent, leveraging any model capable of understanding user prompts and generating the necessary queries (SQL, key-value, vector, etc.).
Query Generation via Prompts: The AI model generates the queries based on pre-trained data and the user’s request. For example, the prompt might instruct the model to generate a SQL query to fetch the total gas usage and transaction counts for a specific date range.
Prompt Example for SQL Query Generation:
Prompt:
Posting Queries to D.A.T.A Backend: Once the model generates the queries, they are posted to the D.A.T.A Framework backend for execution, just like in the first approach. The backend handles querying the blockchain data, processes the data, and returns the results in a structured format.
Response Handling: The response is then provided to the AI agent, and depending on the implementation, it can trigger further actions or display results to the user.
Example of a Custom AI Agent Prompt and Query Handling in Eliza:
Response Format Handling
Whether you are using the D.A.T.A Framework backend or your own custom AI model to generate queries, the response format is consistent. Here’s what you can expect:
SQL Queries: Executed against the blockchain data sources and returned as JSON with placeholders for results.
Key-Value Data: Specific data points such as balances, transaction counts, or token holdings.
Vector Data: For more advanced use cases, such as AI-powered analysis or machine learning tasks.
The framework is designed to ensure that responses are easy to handle and can be integrated seamlessly into the AI agent's decision-making process.
Summary of Approaches
Using the D.A.T.A Framework Backend:
Automatically generate and execute SQL, key-value, or vector queries based on user input.
AI agents can autonomously fetch on-chain data and trigger actions based on that data.
Using Custom AI Models for Query Generation:
Leverage AI models to generate custom queries based on specific prompts.
AI agents use these custom queries to interact with the D.A.T.A Framework backend for data retrieval, enabling more flexibility and adaptability in querying blockchain data.
Both approaches enable AI agents to query on-chain data effectively, making them more intelligent and autonomous in blockchain-driven decision-making.
Last updated