A plugin for Hedera Agent Kit PY that provides integration with the CoinCap API
In this plugin we use CoinCap to get the current price in USD of one HBAR and combine it with the power of the Hedera Agent Kit to get your current balance of HBAR in USD currency.
This plugin enables AI agents to interact with the CoinCap API
1.- Install the plugin
pip install coincap-hedera-agent-kit-plugin2.- Add your CoinCap API Bearer token in the .env file ( You get it in the CoinCap website )
# Coincap API needed by coincap-hedera-plugin
COINCAP_BEARER_TOKEN=******************************
3.- Import the plugin code in your main.py (Hedera Agent)
from coincap_hedera_plugin import conincap_h_plugin4.- Import the core_account_query_plugin plugin code
This core plugin is already provided by the Hedera, it is needed to query the account (read its balance)
from hedera_agent_kit.plugins import core_account_query_plugin5.- Add the plugin in the plugins section of the agent
async def main():
...
configuration=Configuration(
tools=[],
plugins=[
core_account_query_plugin,
conincap_h_plugin # <---- add the plugin here6.- Use a prompt to ask for your current balance and tell the agent to want it in USD currency, for example like this:
response = await agent.ainvoke(
{"messages": [{"role": "user", "content": "Get my balance in HBAR and also convert it to USD please"}]},Note
The previous prompt results in a multi-step tool invocation:
- Fetch the HBAR balance.
- Fetch the current HBAR price.
- Convert the balance to USD.
It is important for developers to be aware of, as configurations that limit the agent to only one tool call per request will cause this prompt to fail or behave incorrectly.
7.- Now you can run the example agent and you should get your current HBAR balance converted to USD currency
python main.pyInvoke the CoinCap API to get the current price in USD of one HBAR
def get_hbar_price_from_coincap():None
| Value | Type | Description |
|---|---|---|
| Result | float |
Value in USD currency of 1 HBAR according to CoinCap |
Get my balance in HBAR and also convert it to USD please
Use a code formatter, for example black
pip install black
black .Optional - Distribution (only needed when creating your own python package) How to publish a PyPI package
1.- Read the instructions
2.- Create the distribution package
python setup.py sdist3.- Install twine
pip install twine4.- Upload package
twine upload dist/*