Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds Allora Network AI price inference to the CDP AgentKit #110

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cdp-agentkit-core/python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
### Added

- Added `wrap_eth` action to wrap ETH to WETH on Base.
- Added support for Allora Chain machine learning (`get_price_inference` and `get_all_topics` actions).

## [0.0.7] - 2025-01-08

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from cdp_agentkit_core.actions.address_reputation import AddressReputationAction
from cdp_agentkit_core.actions.deploy_contract import DeployContractAction
from cdp_agentkit_core.actions.allora.get_all_topics import GetAllTopicsAction
from cdp_agentkit_core.actions.allora.get_price_inference import GetPriceInferenceAction
from cdp_agentkit_core.actions.cdp_action import CdpAction
from cdp_agentkit_core.actions.deploy_nft import DeployNftAction
from cdp_agentkit_core.actions.deploy_token import DeployTokenAction
from cdp_agentkit_core.actions.get_balance import GetBalanceAction
Expand Down Expand Up @@ -65,4 +68,6 @@ def get_all_cdp_actions() -> list[type[CdpAction]]:
"SuperfluidCreateFlowAction",
"SuperfluidUpdateFlowAction",
"SuperfluidDeleteFlowAction",
"GetPriceInferenceAction",
"GetAllTopicsAction",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Allora

[Allora Network](https://allora.network/) is an AI-powered inference platform that delivers real-time, self-improving forecasts and insights for various use cases. By aggregating and analyzing data from diverse sources—such as blockchain networks and off-chain APIs—Allora seamlessly provides low-latency, high-performance analytics without requiring complex infrastructure. The platform’s intuitive approach allows developers to focus on building intelligence-driven solutions, while Allora takes care of the heavy lifting behind the scenes.

### Actions

- get_all_topics: Lists all available topics from Allora Network.
- get_price_inference: Returns the future price inference for a given crypto asset from Allora Network. It takes the crypto asset and timeframe as inputs. e.g.: "Get the inference for BTC in 5 min".


Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from cdp_agentkit_core.actions.allora.action import AlloraAction
from cdp_agentkit_core.actions.allora.get_all_topics import GetAllTopicsAction
from cdp_agentkit_core.actions.allora.get_price_inference import GetPriceInferenceAction


def get_all_allora_actions() -> list[type[AlloraAction]]:
actions = []
for action in AlloraAction.__subclasses__():
actions.append(action())

return actions


ALLORA_ACTIONS = get_all_allora_actions()

__all__ = [
"ALLORA_ACTIONS",
"GetPriceInferenceAction",
"GetAllTopicsAction",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from collections.abc import Callable

from pydantic import BaseModel


class AlloraAction(BaseModel):
"""Allora Action Base Class."""

name: str
description: str
args_schema: type[BaseModel] | None = None
func: Callable[..., str]
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import json
from collections.abc import Callable

from allora_sdk.v2.api_client import AlloraAPIClient
from pydantic import BaseModel

from cdp_agentkit_core.actions.allora.action import AlloraAction

GET_ALL_TOPICS_PROMPT = """
This tool will get all available topics from Allora Network.
"""


async def get_all_topics(client: AlloraAPIClient) -> str:
"""Get all available topics from Allora Network.

Args:
client (AlloraAPIClient): The Allora API client.

Returns:
str: A list of available topics from Allora Network in JSON format

"""
try:
topics = await client.get_all_topics()
topics_json = json.dumps(topics, indent=4)
return f"The available topics at Allora Network are:\n{topics_json}"
except Exception as e:
return f"Error getting all topics: {e}"


class GetAllTopicsAction(AlloraAction):
"""Get all topics action."""

name: str = "get_all_topics"
description: str = GET_ALL_TOPICS_PROMPT
args_schema: type[BaseModel] | None = None
func: Callable[..., str] = get_all_topics
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from collections.abc import Callable

from allora_sdk.v2.api_client import AlloraAPIClient
from pydantic import BaseModel, Field

from cdp_agentkit_core.actions.allora.action import AlloraAction

GET_PRICE_INFERENCE_PROMPT = """
This tool will get the future price inference for a given crypto asset from Allora Network.
It takes the crypto asset and timeframe as inputs.
"""


class GetPriceInferenceInput(BaseModel):
"""Input argument schema for get price inference action."""

token: str = Field(
..., description="The crypto asset to get the price inference for, e.g. `BTC`"
)
timeframe: str = Field(
..., description="The timeframe to get the price inference for, e.g. `5m` or `8h`"
)


async def get_price_inference(client: AlloraAPIClient, token: str, timeframe: str) -> str:
"""Get the future price inference for a given crypto asset from Allora Network.

Args:
client (AlloraAPIClient): The Allora API client.
token (str): The crypto asset to get the price inference for, e.g. `BTC`
timeframe (str): The timeframe to get the price inference for, e.g. `5m` or `8h`

Returns:
str: The future price inference for the given crypto asset

"""
try:
price_inference = await client.get_price_inference(token, timeframe)
return f"The future price inference for {token} in {timeframe} is {price_inference.inference_data.network_inference_normalized}"
except Exception as e:
return f"Error getting price inference: {e}"


class GetPriceInferenceAction(AlloraAction):
"""Get price inference action."""

name: str = "get_price_inference"
description: str = GET_PRICE_INFERENCE_PROMPT
args_schema: type[BaseModel] | None = GetPriceInferenceInput
func: Callable[..., str] = get_price_inference
Loading