mezoAgent 0.1.3__py3-none-any.whl → 0.1.4__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.
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.1
2
+ Name: mezoAgent
3
+ Version: 0.1.4
4
+ Summary: A LangChain based tool kit for AI Agents to send BTC and mUSD transactions on Mezo Matsnet.
5
+ Author: Dreadwulf
6
+ Author-email: dreadwul@wtf.com
7
+ Requires-Python: >=3.7
8
+ Requires-Dist: web3
9
+ Requires-Dist: langchain
10
+ Requires-Dist: langchain-openai
11
+ Requires-Dist: python-dotenv
@@ -0,0 +1,8 @@
1
+ mezo_agent/__init__.py,sha256=CTQD3Y_lY9lzhuTzIeQjqsNzy7sYjOPygVSSK3wBlps,51
2
+ mezo_agent/config.py,sha256=c16-JHEbK5rFBKO-QdxBRtrl4DSlYzGckD9BzbTw2dY,1708
3
+ mezo_agent/parsing.py,sha256=dFqNHGH0LoG4_TEsHKcorj6aY_Rh4H8f5Yj7ZdfKJzE,1454
4
+ mezo_agent/transaction.py,sha256=75q88q94WJLg0UahMhkAfMqSxBfW-bqK3iZMGykmc-k,2069
5
+ mezoAgent-0.1.4.dist-info/METADATA,sha256=xYqUvTErxTwqLghZILJOFYOAmhOzfx96wOuA8k9eK2Y,343
6
+ mezoAgent-0.1.4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
7
+ mezoAgent-0.1.4.dist-info/top_level.txt,sha256=rrAci_NyTR9z6w_BrQhQrAhzMW_A0NYhVa0x2USl0nQ,11
8
+ mezoAgent-0.1.4.dist-info/RECORD,,
@@ -0,0 +1 @@
1
+ mezo_agent
mezo_agent/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from .transaction import mezo_agent_transaction_btc
mezo_agent/config.py ADDED
@@ -0,0 +1,46 @@
1
+ import os
2
+ import json
3
+ from dotenv import load_dotenv
4
+ from web3 import Web3
5
+ from web3.exceptions import Web3Exception
6
+
7
+ # ✅ Load environment variables
8
+ USER_PROJECT_DIR = os.getcwd()
9
+ USER_ENV_PATH = os.path.join(USER_PROJECT_DIR, ".env")
10
+
11
+ if os.path.exists(USER_ENV_PATH):
12
+ load_dotenv(USER_ENV_PATH)
13
+ else:
14
+ print("⚠️ Warning: No `.env` file found in your project directory! Transactions requiring signing may fail.")
15
+
16
+ # ✅ Load keys from the environment
17
+ PRIVATE_KEY = os.getenv("PRIVATE_KEY")
18
+ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
19
+
20
+ if not PRIVATE_KEY:
21
+ print("⚠️ Warning: PRIVATE_KEY not set. Please create a `.env` file in your project with your keys.")
22
+ PRIVATE_KEY = None # Allow package to be installed but prevent transactions
23
+
24
+ # ✅ Define RPC URL and initialize Web3
25
+ RPC_URL = "https://rpc.test.mezo.org"
26
+ web3_instance = Web3(Web3.HTTPProvider(RPC_URL))
27
+
28
+ if not web3_instance.is_connected():
29
+ raise ConnectionError("❌ Failed to connect to Mezo Matsnet RPC.")
30
+
31
+ # ✅ Initialize account and sender address
32
+ if PRIVATE_KEY:
33
+ account = web3_instance.eth.account.from_key(PRIVATE_KEY)
34
+ sender_address = account.address
35
+ else:
36
+ account = None
37
+ sender_address = None
38
+
39
+ # ✅ Set up contract details (for mUSD)
40
+ MUSD_ADDRESS = "0x637e22A1EBbca50EA2d34027c238317fD10003eB"
41
+ ERC20_ABI = json.loads(
42
+ '[{"constant": false, "inputs": [{"name": "recipient", "type": "address"},'
43
+ '{"name": "amount", "type": "uint256"}],"name": "transfer","outputs": [{"name": "", "type": "bool"}],'
44
+ '"stateMutability": "nonpayable","type":"function"}]'
45
+ )
46
+ musd_contract = web3_instance.eth.contract(address=MUSD_ADDRESS, abi=ERC20_ABI)
mezo_agent/parsing.py ADDED
@@ -0,0 +1,36 @@
1
+ from langchain.output_parsers import StructuredOutputParser, ResponseSchema
2
+ from langchain.prompts import PromptTemplate
3
+ from langchain_openai import ChatOpenAI
4
+ from .config import OPENAI_API_KEY
5
+
6
+ # Define the expected response schema
7
+ response_schemas = [
8
+ ResponseSchema(name="amount", description="The amount of cryptocurrency to transfer."),
9
+ ResponseSchema(name="currency", description="The cryptocurrency (BTC or mUSD)."),
10
+ ResponseSchema(name="recipient", description="The recipient's wallet address."),
11
+ ]
12
+
13
+ # Initialize the structured output parser
14
+ output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
15
+
16
+ # Instantiate the ChatOpenAI LLM
17
+ llm = ChatOpenAI(temperature=0, openai_api_key=OPENAI_API_KEY)
18
+
19
+ # Prepare the prompt template
20
+ prompt_template = PromptTemplate(
21
+ template="Extract transaction details from this request:\n{input}\n{format_instructions}",
22
+ input_variables=["input"],
23
+ partial_variables={"format_instructions": output_parser.get_format_instructions()},
24
+ )
25
+
26
+ def extract_transaction_details(prompt: str):
27
+ """
28
+ Uses LLM to extract structured transaction details from user input.
29
+ """
30
+ formatted_prompt = prompt_template.format(input=prompt)
31
+ response = llm.invoke(formatted_prompt)
32
+
33
+ try:
34
+ return output_parser.parse(response.content)
35
+ except Exception as e:
36
+ return f"❌ Failed to extract transaction details: {str(e)}"
@@ -0,0 +1,53 @@
1
+ from web3.exceptions import Web3Exception
2
+ from langchain.tools import tool
3
+ from .config import web3_instance, sender_address, account
4
+ from .parsing import extract_transaction_details
5
+
6
+ @tool
7
+ def mezo_agent_transaction_btc(transaction_prompt: str) -> str:
8
+ """
9
+ Sends BTC on Mezo Matsnet. Parses a transaction request and executes the transfer.
10
+ """
11
+ transaction_details = extract_transaction_details(transaction_prompt)
12
+
13
+ if isinstance(transaction_details, str): # Handle errors
14
+ return transaction_details
15
+
16
+ amount = float(transaction_details["amount"])
17
+ currency = transaction_details["currency"].lower()
18
+ recipient = transaction_details["recipient"]
19
+
20
+ if currency != "btc":
21
+ return "❌ This function only supports BTC transactions."
22
+
23
+ # Convert amount to Wei (BTC uses 18 decimals on Mezo Matsnet)
24
+ amount_wei = web3_instance.to_wei(amount, "ether")
25
+
26
+ # Check sender's BTC balance
27
+ sender_balance = web3_instance.eth.get_balance(sender_address)
28
+ sender_balance_btc = web3_instance.from_wei(sender_balance, "ether")
29
+
30
+ if sender_balance < amount_wei:
31
+ return f"❌ Insufficient BTC balance! You have {sender_balance_btc} BTC but need {amount} BTC."
32
+
33
+ # Fetch nonce and gas price
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 = {
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
+ try:
48
+ # Sign and send the transaction
49
+ signed_tx = account.sign_transaction(tx)
50
+ tx_hash = web3_instance.eth.send_raw_transaction(signed_tx.raw_transaction)
51
+ return f"✅ BTC Transaction Successful! Hash: {tx_hash.hex()}"
52
+ except Web3Exception as e:
53
+ return f"❌ BTC Transaction Failed: {str(e)}"
@@ -1,15 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: mezoAgent
3
- Version: 0.1.3
4
- Summary: A LangChain tool for sending BTC and mUSD transactions on Mezo Matsnet.
5
- Home-page: https://github.com/yourusername/mezoTransactionTool
6
- Author: Dreadwulf
7
- Author-email: dreadwul@wtf.com
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.7
12
- Requires-Dist: web3
13
- Requires-Dist: langchain
14
- Requires-Dist: langchain-openai
15
- Requires-Dist: python-dotenv
@@ -1,6 +0,0 @@
1
- mezoTransactionTool/__init__.py,sha256=4izlG8P3PTGXZb_RvEQ3HlPMxQ1jzSINnF9nSlxnEXE,161
2
- mezoTransactionTool/transaction_tools.py,sha256=0VxSaiMSQW067K6qw2SJR9dm-CH7obwMF0cagbEEX1g,5013
3
- mezoAgent-0.1.3.dist-info/METADATA,sha256=nMCSfEH-FTHSDb8iEP1W2sGNtNu7ahB-ZzEGy5CZFBo,536
4
- mezoAgent-0.1.3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
5
- mezoAgent-0.1.3.dist-info/top_level.txt,sha256=Czoa5A8CU_I_oPKDa5OXa5H7RM4Jk94PF9mIpz2V9t4,20
6
- mezoAgent-0.1.3.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- mezoTransactionTool
@@ -1,3 +0,0 @@
1
- from .transaction_tools import mezo_agent_transaction_btc, mezo_agent_transaction_musd
2
-
3
- __all__ = ["mezo_agent_transaction_btc", "mezo_agent_transaction_musd"]
@@ -1,126 +0,0 @@
1
- import os
2
- import json
3
- from dotenv import load_dotenv
4
- from web3 import Web3
5
- from web3.exceptions import Web3Exception
6
- from langchain.tools import tool
7
- from langchain_openai import ChatOpenAI
8
- from langchain.output_parsers import StructuredOutputParser, ResponseSchema
9
- from langchain.prompts import PromptTemplate
10
-
11
- # ✅ Load environment variables
12
- USER_PROJECT_DIR = os.getcwd()
13
- USER_ENV_PATH = os.path.join(USER_PROJECT_DIR, ".env")
14
-
15
- if os.path.exists(USER_ENV_PATH):
16
- load_dotenv(USER_ENV_PATH)
17
- else:
18
- print("⚠️ Warning: No `.env` file found in your project directory! Transactions requiring signing may fail.")
19
-
20
- # ✅ Load Private Key from User's `.env`
21
- PRIVATE_KEY = os.getenv("PRIVATE_KEY")
22
- OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
23
-
24
- if not PRIVATE_KEY:
25
- print("⚠️ Warning: PRIVATE_KEY not set. Please create a `.env` file in your project with your keys.")
26
- PRIVATE_KEY = None # Allow package to be installed but prevent transactions
27
-
28
- # ✅ Define RPC URL before initializing Web3
29
- RPC_URL = "https://rpc.test.mezo.org"
30
- web3_instance = Web3(Web3.HTTPProvider(RPC_URL))
31
-
32
- # ✅ Check Web3 connection
33
- if not web3_instance.is_connected():
34
- raise ConnectionError("❌ Failed to connect to Mezo Matsnet RPC.")
35
-
36
- # ✅ Initialize account object using `web3_instance`
37
- if PRIVATE_KEY:
38
- account = web3_instance.eth.account.from_key(PRIVATE_KEY)
39
- sender_address = account.address
40
- else:
41
- account = None
42
- sender_address = None
43
-
44
- MUSD_ADDRESS = "0x637e22A1EBbca50EA2d34027c238317fD10003eB"
45
- ERC20_ABI = json.loads('[{"constant": false, "inputs": [{"name": "recipient", "type": "address"},{"name": "amount", "type": "uint256"}],"name": "transfer","outputs": [{"name": "", "type": "bool"}],"stateMutability": "nonpayable","type":"function"}]')
46
- musd_contract = web3_instance.eth.contract(address=MUSD_ADDRESS, abi=ERC20_ABI)
47
-
48
- # ✅ Define Structured Output Parser for Transaction Details
49
- response_schemas = [
50
- ResponseSchema(name="amount", description="The amount of cryptocurrency to transfer."),
51
- ResponseSchema(name="currency", description="The cryptocurrency (BTC or mUSD)."),
52
- ResponseSchema(name="recipient", description="The recipient's wallet address."),
53
- ]
54
-
55
- output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
56
-
57
- # ✅ Define LLM Prompt for Parsing Transactions
58
- llm = ChatOpenAI(temperature=0, openai_api_key=OPENAI_API_KEY)
59
-
60
- prompt_template = PromptTemplate(
61
- template="Extract transaction details from this request:\n{input}\n{format_instructions}",
62
- input_variables=["input"],
63
- partial_variables={"format_instructions": output_parser.get_format_instructions()},
64
- )
65
-
66
- def extract_transaction_details(prompt: str):
67
- """
68
- Uses LLM to extract structured transaction details from user input.
69
- """
70
- formatted_prompt = prompt_template.format(input=prompt)
71
- response = llm.invoke(formatted_prompt)
72
-
73
- try:
74
- return output_parser.parse(response.content)
75
- except Exception as e:
76
- return f"❌ Failed to extract transaction details: {str(e)}"
77
-
78
- @tool
79
- def mezo_agent_transaction_btc(transaction_prompt: str) -> str:
80
- """
81
- Sends BTC on Mezo Matsnet. Parses a transaction request and executes the transfer.
82
- """
83
- transaction_details = extract_transaction_details(transaction_prompt)
84
-
85
- if isinstance(transaction_details, str): # Handle errors
86
- return transaction_details
87
-
88
- amount = float(transaction_details["amount"])
89
- currency = transaction_details["currency"].lower()
90
- recipient = transaction_details["recipient"]
91
-
92
- if currency != "btc":
93
- return "❌ This function only supports BTC transactions."
94
-
95
- # ✅ Convert amount to Wei (BTC uses 18 decimals on Mezo Matsnet)
96
- amount_wei = web3_instance.to_wei(amount, "ether")
97
-
98
- # ✅ Check sender's BTC balance
99
- sender_balance = web3_instance.eth.get_balance(sender_address)
100
- sender_balance_btc = web3_instance.from_wei(sender_balance, "ether")
101
-
102
- if sender_balance < amount_wei:
103
- return f"❌ Insufficient BTC balance! You have {sender_balance_btc} BTC but need {amount} BTC."
104
-
105
- # ✅ Fetch nonce and gas price
106
- nonce = web3_instance.eth.get_transaction_count(sender_address)
107
- gas_price = web3_instance.eth.gas_price
108
- gas_limit = web3_instance.eth.estimate_gas({"to": recipient, "value": amount_wei, "from": sender_address})
109
-
110
- tx = {
111
- "to": recipient,
112
- "value": amount_wei,
113
- "gas": gas_limit,
114
- "gasPrice": gas_price,
115
- "nonce": nonce,
116
- "chainId": 31611, # Mezo Testnet Chain ID
117
- }
118
-
119
- try:
120
- # ✅ Sign and send the transaction
121
- signed_tx = account.sign_transaction(tx)
122
- tx_hash = web3_instance.eth.send_raw_transaction(signed_tx.raw_transaction)
123
- return f"✅ BTC Transaction Successful! Hash: {tx_hash.hex()}"
124
-
125
- except Web3Exception as e:
126
- return f"❌ BTC Transaction Failed: {str(e)}"