Skip to content

Commit

Permalink
Add parameters to CdpAgentkitWrapper used for monitoring (#29)
Browse files Browse the repository at this point in the history
* stash

* add tests

* remove changes to cdp agentkit core

* lint

---------

Co-authored-by: Adrian Lopez <adrian.lopez.1@coinbase.com>
  • Loading branch information
adriangomez24 and Adrian Lopez authored Nov 7, 2024
1 parent 0028817 commit 097702d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cdp-langchain/cdp_langchain/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from cdp_langchain.__version__ import __version__

__all__ = ["__version__"]
1 change: 1 addition & 0 deletions cdp-langchain/cdp_langchain/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.1"
4 changes: 4 additions & 0 deletions cdp-langchain/cdp_langchain/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Specifies package level constants used throughout the package."""

# CDP_LANGCHAIN_DEFAULT_SOURCE (str): Denotes the default source for CDP Langchain Agentkit extensions.
CDP_LANGCHAIN_DEFAULT_SOURCE = "cdp-langchain"
9 changes: 8 additions & 1 deletion cdp-langchain/cdp_langchain/utils/cdp_agentkit_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from pydantic import BaseModel, model_validator

from cdp import Wallet
from cdp_langchain import __version__
from cdp_langchain.constants import CDP_LANGCHAIN_DEFAULT_SOURCE


class CdpAgentkitWrapper(BaseModel):
Expand Down Expand Up @@ -37,7 +39,12 @@ def validate_environment(cls, values: dict) -> Any:
"CDP SDK is not installed. " "Please install it with `pip install cdp-sdk`"
) from None

Cdp.configure(cdp_api_key_name, cdp_api_key_private_key)
Cdp.configure(
api_key_name=cdp_api_key_name,
private_key=cdp_api_key_private_key,
source=CDP_LANGCHAIN_DEFAULT_SOURCE,
source_version=__version__,
)

if wallet_data_json:
wallet_data = WalletData.from_dict(json.loads(wallet_data_json))
Expand Down
17 changes: 14 additions & 3 deletions cdp-langchain/tests/utils/test_cdp_agentkit_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from pydantic import ValidationError

from cdp import Cdp, Wallet, WalletData
from cdp_langchain import __version__
from cdp_langchain.constants import CDP_LANGCHAIN_DEFAULT_SOURCE
from cdp_langchain.utils import CdpAgentkitWrapper


Expand Down Expand Up @@ -62,7 +64,10 @@ def test_initialization_with_env_vars(
assert wrapper.wallet is not None

mock_cdp_configure.assert_called_once_with(
env_vars["CDP_API_KEY_NAME"], env_vars["CDP_API_KEY_PRIVATE_KEY"]
api_key_name=env_vars["CDP_API_KEY_NAME"],
private_key=env_vars["CDP_API_KEY_PRIVATE_KEY"],
source=CDP_LANGCHAIN_DEFAULT_SOURCE,
source_version=__version__,
)

mock_wallet_create.assert_called_once_with(network_id=env_vars["NETWORK_ID"])
Expand All @@ -83,7 +88,10 @@ def test_initialization_with_direct_values(mock_cdp_configure: Mock, mock_wallet
assert wrapper.network_id == test_values["network_id"]

mock_cdp_configure.assert_called_once_with(
test_values["cdp_api_key_name"], test_values["cdp_api_key_private_key"]
api_key_name=test_values["cdp_api_key_name"],
private_key=test_values["cdp_api_key_private_key"],
source=CDP_LANGCHAIN_DEFAULT_SOURCE,
source_version=__version__,
)

mock_wallet_create.assert_called_once_with(network_id=test_values["network_id"])
Expand All @@ -110,7 +118,10 @@ def test_initialization_with_direct_values_and_persisted_wallet(
assert wrapper.network_id == test_values["network_id"]

mock_cdp_configure.assert_called_once_with(
test_values["cdp_api_key_name"], test_values["cdp_api_key_private_key"]
api_key_name=test_values["cdp_api_key_name"],
private_key=test_values["cdp_api_key_private_key"],
source=CDP_LANGCHAIN_DEFAULT_SOURCE,
source_version=__version__,
)

mock_wallet_import_data.assert_called_once()
Expand Down

0 comments on commit 097702d

Please sign in to comment.