Skip to main content

Coinbase Agentkit Alith Python Integration

Project description

Coinbase Agentkit Alith Python Integration

This integration provides the following methods:

  1. Use Agentkit actions within Alith: You can directly leverage a variety of actions from the agentkit ecosystem without the need to rewrite them in Alith.
import json
import os

from coinbase_agentkit import (
    AgentKit,
    AgentKitConfig,
    CdpWalletProvider,
    CdpWalletProviderConfig,
    cdp_api_action_provider,
    cdp_wallet_action_provider,
    erc20_action_provider,
    pyth_action_provider,
    wallet_action_provider,
    weth_action_provider,
)
from coinbase_agentkit_alith import get_alith_tools
from alith import Agent
from dotenv import load_dotenv

# Configure a file to persist the agent's CDP API Wallet Data.
wallet_data_file = "wallet_data.txt"

load_dotenv()


def initialize_agent() -> Agent:
    """Initialize the agent with CDP Agentkit."""

    # Initialize CDP Wallet Provider
    wallet_data = None
    if os.path.exists(wallet_data_file):
        with open(wallet_data_file) as f:
            wallet_data = f.read()

    cdp_config = None
    if wallet_data is not None:
        cdp_config = CdpWalletProviderConfig(wallet_data=wallet_data)

    wallet_provider = CdpWalletProvider(cdp_config)

    agentkit = AgentKit(
        AgentKitConfig(
            wallet_provider=wallet_provider,
            action_providers=[
                cdp_api_action_provider(),
                cdp_wallet_action_provider(),
                erc20_action_provider(),
                pyth_action_provider(),
                wallet_action_provider(),
                weth_action_provider(),
            ],
        )
    )

    wallet_data_json = json.dumps(wallet_provider.export_wallet().to_dict())

    with open(wallet_data_file, "w") as f:
        f.write(wallet_data_json)

    # use get_langchain_tools
    tools = get_alith_tools(agentkit)

    preamble = (
        "Be creative and do something interesting on the blockchain. "
        "Choose an action or set of actions and execute it that highlights your abilities."
    )

    # Create an Alith Agent and CDP Agentkit tools.
    return Agent(
        name="A dummy Agent",
        model="gpt-4o-mini",
        preamble=preamble,
        tools=tools,
    )


agent = initialize_agent()
print(agent.prompt("Transfer 0.5 ETH to 0xAABB"))

Reference

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coinbase_agentkit_alith-0.2.0.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coinbase_agentkit_alith-0.2.0-py3-none-any.whl (2.5 kB view details)

Uploaded Python 3

File details

Details for the file coinbase_agentkit_alith-0.2.0.tar.gz.

File metadata

File hashes

Hashes for coinbase_agentkit_alith-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f4f86d64b820918ac1e960b72f927df357b520c990e8591dc8b0b5e7c3f7787c
MD5 b9d001af3fdc3fe18d95d544496e92bc
BLAKE2b-256 060d1bb490faf29d051e0a8198ecde00ba5c25021f72211a258a5c446e058378

See more details on using hashes here.

File details

Details for the file coinbase_agentkit_alith-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for coinbase_agentkit_alith-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b443c47e6f333cb8c476b99fdd98cfb0cda24377fe67aaec5c2be5ceb1e84c48
MD5 347aafa9521bb2cd0e70da2effae6fe5
BLAKE2b-256 ccdfe52f59f1d9744eb4389984f7c4f39be8ecfcfacb9134f8ea31c999c19a95

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page