mezoAgent 0.7.2__py3-none-any.whl → 0.8.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mezoAgent
3
- Version: 0.7.2
3
+ Version: 0.8.0
4
4
  Summary: A Python package for Mezo Agent transactions with LangChain tools
5
5
  Author: Dreadwulf, Duck, Digi
6
6
  Requires-Dist: python-dotenv
@@ -1,18 +1,19 @@
1
- mezo_agent/__init__.py,sha256=1UatqstSlOF8pU5-fu675ONGteB6INqyE74xMi8S1o4,752
1
+ mezo_agent/__init__.py,sha256=fxRf_Z-SEitzT7dp3V0DWmi3nO8yOrb26Avl3kib4QA,795
2
2
  mezo_agent/characters.py,sha256=wub7y9BrAAdAKWwcNAdgrvhRi2zHMaZNzTr2y3qtbsw,515
3
3
  mezo_agent/chat.py,sha256=ZtNurUDV7UzJjbFyU96DNGy37hO3gl0osn19mRu7ER8,859
4
4
  mezo_agent/config.py,sha256=6xFgk80eiBLTasKGW73Ne8hNhMtx8BbQ_Ef79YOyDlc,3233
5
- mezo_agent/parsing.py,sha256=dnS5Qw9V8qvSA_IPgn6nCUnyEfZP9TphO8DnH8oUuiM,5080
5
+ mezo_agent/parsing.py,sha256=PeR1R6gqzM9VXt7OdWANDoL7GbzMMRjKLzuP10uugEs,5101
6
+ mezo_agent/safe_mode_btc_tool.py,sha256=6e8P00Mk570qfPpEiUdMmfvhN3hnHLyOAKrYHu89v4g,3410
6
7
  mezo_agent/swap_musd_btc.py,sha256=Co-XcfK73spm94VC6qzGY0VYoGwsMDKKHM8ToGh2JxU,4289
7
- mezo_agent/token_balance_tool.py,sha256=n5xkHWGhkJdQZILN0fDe-n4NHgXSHTSloEHJfkLMsWE,1442
8
+ mezo_agent/token_balance_tool.py,sha256=zOjDJdfYT6LuQzPuAxxNeee1srsepevE71fqboiDSWI,1422
8
9
  mezo_agent/token_price_tool.py,sha256=vD-ukq0D_4zmjIy9bZ9qL44nGctf-hWzkQuTd-0wy2U,930
9
10
  mezo_agent/token_utils.py,sha256=3NH_Z_vbZ0uupuuGjEbmwsbUkubluQbL-0xR9kia7nU,1118
10
11
  mezo_agent/transaction.py,sha256=YpfWrkEaf0YGM_Kc4cFwlT9GmBGZkeJHWm0VGHs9Gks,4199
11
12
  mezo_agent/twitter_client.py,sha256=Va8ZQaK5lZjJUq3-bhIJWnDmX4Mmt4kWRW3aKSGbLq8,3248
12
- mezo_agent/twitter_manager.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ mezo_agent/twitter_manager.py,sha256=KvxiMOhBmQbLuLoVrAQ77DpAnFIdiDSztsKbZ_3-ar4,2363
13
14
  mezo_agent/utils.py,sha256=hsGtL_iXvUVGnY5aHPQ0v6Jejxd4P4qw0yOtS1omToU,1397
14
15
  mezo_agent/data/new_router.json,sha256=A8U-NVfe1F-hDyR90_SuH8jDAxmzyyHWdJW62j9TZsc,26756
15
- mezoAgent-0.7.2.dist-info/METADATA,sha256=UmaWJ9SG3FkEPtKYQ2AYlAu28Dm8vqyyENlVLanIsYM,273
16
- mezoAgent-0.7.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
17
- mezoAgent-0.7.2.dist-info/top_level.txt,sha256=rrAci_NyTR9z6w_BrQhQrAhzMW_A0NYhVa0x2USl0nQ,11
18
- mezoAgent-0.7.2.dist-info/RECORD,,
16
+ mezoAgent-0.8.0.dist-info/METADATA,sha256=xRxuyZCpP3HcmYhcdGFDnWIZdzSM-zX0c8qm-A_nn_g,273
17
+ mezoAgent-0.8.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
18
+ mezoAgent-0.8.0.dist-info/top_level.txt,sha256=rrAci_NyTR9z6w_BrQhQrAhzMW_A0NYhVa0x2USl0nQ,11
19
+ mezoAgent-0.8.0.dist-info/RECORD,,
mezo_agent/__init__.py CHANGED
@@ -2,10 +2,10 @@ from .transaction import mezo_agent_transaction_btc, mezo_agent_musd_transaction
2
2
  from .swap_musd_btc import mezo_agent_swap_musd_btc
3
3
  from .chat import mezo_character_chat
4
4
  from .characters import get_character_prompt
5
- from .token_balance_tool import mezo_agent_token_balance_tool
6
- from .token_price_tool import mezo_agent_token_price_tool
7
- from .token_utils import get_token_address_by_symbol
8
- from .twitter_manager import TwitterManager
5
+ from .tools.token_balance_tool import mezo_agent_token_balance_tool
6
+ from .tools.token_price_tool import mezo_agent_token_price_tool
7
+ # Import the new Safe Mode BTC Transaction Tool
8
+ from .tools.safe_mode_btc_tool import mezo_agent_safe_mode_btc_transaction
9
9
 
10
10
  __all__ = [
11
11
  "mezo_agent_transaction_btc",
@@ -14,7 +14,6 @@ __all__ = [
14
14
  "mezo_character_chat",
15
15
  "mezo_agent_token_balance_tool",
16
16
  "mezo_agent_token_price_tool",
17
- "get_token_address_by_symbol",
18
- "TwitterManager",
17
+ "mezo_agent_safe_mode_btc_transaction", # Expose new tool
19
18
  "get_character_prompt"
20
- ]
19
+ ]
mezo_agent/parsing.py CHANGED
@@ -3,7 +3,7 @@ from langchain.prompts import PromptTemplate
3
3
  from langchain_openai import ChatOpenAI
4
4
  from .config import OPENAI_API_KEY
5
5
 
6
- # Define the expected response schema
6
+ # Define the expected response schema for extracting transaction details
7
7
  response_schemas = [
8
8
  ResponseSchema(name="amount", description="The amount of cryptocurrency to transfer."),
9
9
  ResponseSchema(name="currency", description="The cryptocurrency (BTC or mUSD)."),
@@ -64,7 +64,7 @@ def extract_swap_details(prompt: str):
64
64
  except Exception as e:
65
65
  return f"Failed to extract swap details: {str(e)}"
66
66
 
67
- #parsing for balance check tool
67
+ #Balance check parsing
68
68
 
69
69
  balance_response_schema = [
70
70
  ResponseSchema(name="token_symbol", description="The token symbol to check the balance for (e.g., 'MUSD').")
@@ -93,7 +93,7 @@ def extract_balance_details(prompt: str):
93
93
  except Exception as e:
94
94
  return f"Failed to extract balance details: {str(e)}"
95
95
 
96
- #Price parsing tools
96
+ #Price parsing
97
97
  price_response_schema = [
98
98
  ResponseSchema(name="token_symbol", description="The token symbol to check the price for (e.g., 'LIMPETH').")
99
99
  ]
@@ -0,0 +1,87 @@
1
+ from langchain.tools import tool
2
+ from web3.exceptions import Web3Exception
3
+ import json
4
+ from mezo_agent.config import web3_instance, sender_address, account
5
+ from mezo_agent.parsing import extract_transaction_details
6
+ from mezo_agent.utils import llm # If you store your ChatOpenAI instance in utils.py
7
+
8
+ @tool
9
+ def mezo_agent_safe_mode_btc_transaction(prompt: str, confirm_before_sending: bool = True) -> str:
10
+ """
11
+ Sends BTC on Mezo Matsnet with a Human-in-the-Loop confirmation step.
12
+ 1) Parses user prompt for transaction details.
13
+ 2) Calls LLM to provide a verbose explanation of the transaction data.
14
+ 3) Shows both raw data and LLM explanation to the user.
15
+ 4) Prompts user for confirmation before broadcasting.
16
+ """
17
+
18
+ # 1) Parse transaction details
19
+ transaction_details = extract_transaction_details(prompt)
20
+ if isinstance(transaction_details, str):
21
+ return transaction_details # Return parsing error if any
22
+
23
+ amount = float(transaction_details["amount"])
24
+ currency = transaction_details["currency"].lower()
25
+ recipient = transaction_details["recipient"]
26
+
27
+ if currency != "btc":
28
+ return "❌ This function only handles BTC transactions."
29
+
30
+ # 2) Convert to Wei (Mezo uses 18 decimals for BTC)
31
+ amount_wei = web3_instance.to_wei(amount, "ether")
32
+
33
+ # 3) Build transaction (do NOT send yet)
34
+ nonce = web3_instance.eth.get_transaction_count(sender_address)
35
+ gas_price = web3_instance.eth.gas_price
36
+ gas_limit = web3_instance.eth.estimate_gas({"to": recipient, "value": amount_wei, "from": sender_address})
37
+
38
+ tx_data = {
39
+ "to": recipient,
40
+ "value": amount_wei,
41
+ "gas": gas_limit,
42
+ "gasPrice": gas_price,
43
+ "nonce": nonce,
44
+ "chainId": 31611, # Mezo Testnet Chain ID
45
+ }
46
+
47
+ # 4) Generate a LLM Explanation
48
+ analysis_prompt = f"""
49
+ You are given the following transaction data on Mezo Matsnet:
50
+ - Recipient: {recipient}
51
+ - Amount (BTC): {amount}
52
+ - Gas Price: {gas_price}
53
+ - Gas Limit: {gas_limit}
54
+ - Nonce: {nonce}
55
+ - Chain ID: 31611 (Mezo Testnet)
56
+
57
+ Explain these details in a user-friendly way, covering:
58
+ 1. The purpose of each field (nonce, gas, etc.).
59
+ 2. Potential fees (approximate cost) or any known risks.
60
+ 3. A short summary of what will happen if the user confirms.
61
+
62
+ Use a concise and helpful tone.
63
+ """
64
+ analysis_response = llm.invoke(analysis_prompt)
65
+ explanation_text = analysis_response.content if analysis_response else "❌ LLM explanation unavailable."
66
+
67
+ # 5) Show user raw data & explanation, confirm
68
+ if confirm_before_sending:
69
+ print("\n--- BTC Transaction Data ---")
70
+ print(json.dumps(tx_data, indent=2))
71
+ print("----------------------------")
72
+
73
+ print("\n--- LLM Analysis ---")
74
+ print(explanation_text)
75
+ print("--------------------")
76
+
77
+ choice = input("Do you want to proceed with this BTC transaction? [y/n]: ").strip().lower()
78
+ if choice != 'y':
79
+ return "❌ Transaction aborted by user."
80
+
81
+ # 6) Sign & send
82
+ try:
83
+ signed_tx = account.sign_transaction(tx_data)
84
+ tx_hash = web3_instance.eth.send_raw_transaction(signed_tx.rawTransaction)
85
+ return f"✅ BTC transaction successful! Hash: {tx_hash.hex()}"
86
+ except Web3Exception as e:
87
+ return f"❌ Transaction failed: {str(e)}"
@@ -1,7 +1,7 @@
1
1
  from langchain.tools import tool
2
2
  from mezo_agent.config import web3_instance, sender_address, ERC20_ABI
3
3
  from mezo_agent.parsing import extract_balance_details
4
- from mezo_agent.token_utils import get_token_address_by_symbol # ✅ Correct import
4
+ from mezo_agent.token_utils import get_token_address_by_symbol
5
5
 
6
6
  @tool
7
7
  def mezo_agent_token_balance_tool(balance_prompt: str) -> str:
@@ -0,0 +1,63 @@
1
+ import os
2
+ import json
3
+
4
+ class TwitterManager:
5
+ """
6
+ Manages Twitter clients for MezoAgent characters.
7
+ """
8
+
9
+ def __init__(self, config_file="twitter_config.json"):
10
+ """
11
+ Initializes the Twitter Manager.
12
+
13
+ :param config_file: The JSON file that stores character Twitter credentials.
14
+ """
15
+ self.config_file = config_file
16
+ self.characters = {}
17
+ self.load_characters()
18
+
19
+ def load_characters(self):
20
+ """
21
+ Loads characters and their Twitter credentials from a JSON config file.
22
+ """
23
+ if os.path.exists(self.config_file):
24
+ with open(self.config_file, "r") as f:
25
+ self.characters = json.load(f)
26
+
27
+ def save_characters(self):
28
+ """
29
+ Saves character Twitter credentials to a JSON config file.
30
+ """
31
+ with open(self.config_file, "w") as f:
32
+ json.dump(self.characters, f, indent=4)
33
+
34
+ def add_character(self, character_name: str, api_key: str, api_secret: str, access_token: str, access_secret: str, personality: str):
35
+ """
36
+ Registers a character with Twitter API credentials and starts their Twitter client.
37
+
38
+ :param character_name: Name of the character.
39
+ :param api_key: Twitter API Key.
40
+ :param api_secret: Twitter API Secret Key.
41
+ :param access_token: Twitter Access Token.
42
+ :param access_secret: Twitter Access Token Secret.
43
+ :param personality: Custom personality description for AI-generated tweets.
44
+ """
45
+ from mezo_agent.twitter_client import TwitterClient # ✅ Move import inside the function
46
+
47
+ if character_name in self.characters:
48
+ print(f"❌ Character '{character_name}' already has a Twitter client.")
49
+ return
50
+
51
+ self.characters[character_name] = {
52
+ "api_key": api_key,
53
+ "api_secret": api_secret,
54
+ "access_token": access_token,
55
+ "access_secret": access_secret,
56
+ "personality": personality
57
+ }
58
+ self.save_characters()
59
+ print(f"✅ Character '{character_name}' registered for Twitter with personality!")
60
+
61
+ # Start the Twitter client with personality
62
+ TwitterClient(character_name, api_key, api_secret, access_token, access_secret, personality)
63
+