mezoAgent 0.5.4__py3-none-any.whl → 0.6.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mezoAgent
3
- Version: 0.5.4
3
+ Version: 0.6.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
@@ -2,13 +2,14 @@ mezo_agent/__init__.py,sha256=naG5ZIXKDWTRlqdx2oi1zJcRZpJBO9ugVkW0MaPkZuk,497
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=v5AiLfZ8Rvm46gek7QX2OmeLFO8xhvQOH_yCc6GNlLA,3850
5
+ mezo_agent/parsing.py,sha256=dnS5Qw9V8qvSA_IPgn6nCUnyEfZP9TphO8DnH8oUuiM,5080
6
6
  mezo_agent/swap_musd_btc.py,sha256=Co-XcfK73spm94VC6qzGY0VYoGwsMDKKHM8ToGh2JxU,4289
7
7
  mezo_agent/token_balance_tool.py,sha256=OvdpEr3Vy_LU1-dg2hOt4IJR6B8Rmql_NQCuVy3cqqg,1459
8
+ mezo_agent/token_price_tool.py,sha256=AKpAaON79S8etVQEp2XIuhLd0B2GNIG4EqU8-6Tijsw,935
8
9
  mezo_agent/transaction.py,sha256=YpfWrkEaf0YGM_Kc4cFwlT9GmBGZkeJHWm0VGHs9Gks,4199
9
- mezo_agent/utils.py,sha256=SnVRjAdrluqiiTjPNi0VhMKGGRvmYZlPXE5B4Bknq8c,1106
10
+ mezo_agent/utils.py,sha256=XRq--PRJbWlG9kpz99QHWu7mLpYY4MYblm38U1xK4YE,2381
10
11
  mezo_agent/data/new_router.json,sha256=A8U-NVfe1F-hDyR90_SuH8jDAxmzyyHWdJW62j9TZsc,26756
11
- mezoAgent-0.5.4.dist-info/METADATA,sha256=djvkoN-W3_Gl04MEOu62OXfP9hxExBwA4SadY8iKkeQ,273
12
- mezoAgent-0.5.4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
13
- mezoAgent-0.5.4.dist-info/top_level.txt,sha256=rrAci_NyTR9z6w_BrQhQrAhzMW_A0NYhVa0x2USl0nQ,11
14
- mezoAgent-0.5.4.dist-info/RECORD,,
12
+ mezoAgent-0.6.0.dist-info/METADATA,sha256=gC8MZDIQ7ku-nLGOHcBSN8MqxYdgxhxlzvelLLCHF_0,273
13
+ mezoAgent-0.6.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
14
+ mezoAgent-0.6.0.dist-info/top_level.txt,sha256=rrAci_NyTR9z6w_BrQhQrAhzMW_A0NYhVa0x2USl0nQ,11
15
+ mezoAgent-0.6.0.dist-info/RECORD,,
mezo_agent/parsing.py CHANGED
@@ -91,4 +91,37 @@ def extract_balance_details(prompt: str):
91
91
  try:
92
92
  return balance_output_parser.parse(response.content)
93
93
  except Exception as e:
94
- return f"Failed to extract balance details: {str(e)}"
94
+ return f"Failed to extract balance details: {str(e)}"
95
+
96
+ #Price parsing tools
97
+ price_response_schema = [
98
+ ResponseSchema(name="token_symbol", description="The token symbol to check the price for (e.g., 'LIMPETH').")
99
+ ]
100
+ price_output_parser = StructuredOutputParser.from_response_schemas(price_response_schema)
101
+
102
+ price_prompt_template = PromptTemplate(
103
+ template="""Output a JSON object with the following key:
104
+ - token_symbol: (string) The token symbol for which to check the price (e.g., "LIMPETH").
105
+
106
+ Extract this detail from the following request:
107
+ {input}
108
+
109
+ Your output must be a valid JSON object with no additional text.
110
+ """,
111
+ input_variables=["input"],
112
+ )
113
+
114
+ def extract_price_details(prompt: str):
115
+ """
116
+ Parses a price query and extracts the token symbol.
117
+
118
+ :param prompt: User input asking for a token price.
119
+ :return: Dictionary containing the token symbol or an error message.
120
+ """
121
+ formatted_prompt = price_prompt_template.format(input=prompt)
122
+ response = llm.invoke(formatted_prompt)
123
+ print("LLM raw price response:", response.content) # Debugging
124
+ try:
125
+ return price_output_parser.parse(response.content)
126
+ except Exception as e:
127
+ return f"❌ Failed to extract price details: {str(e)}"
@@ -0,0 +1,27 @@
1
+ from langchain.tools import tool
2
+ from mezo_agent.config import query_graph
3
+ from mezo_agent.utils import get_token_address_by_symbol, get_token_price
4
+ from mezo_agent.parsing import extract_price_details
5
+
6
+ @tool
7
+ def mezo_agent_token_price_tool(price_prompt: str) -> str:
8
+ """
9
+ Queries the price of a specified token in USD and ETH on Mezo Matsnet.
10
+
11
+ :param price_prompt: User query containing the token symbol.
12
+ :return: Token price details.
13
+ """
14
+ details = extract_price_details(price_prompt)
15
+
16
+ if isinstance(details, str): # Handle extraction errors
17
+ return details
18
+
19
+ token_symbol = details.get("token_symbol")
20
+ if not token_symbol:
21
+ return "❌ Could not extract token symbol for price query."
22
+
23
+ try:
24
+ # Get the token price
25
+ return get_token_price(token_symbol)
26
+ except Exception as e:
27
+ return f"❌ Failed to fetch token price: {str(e)}"
mezo_agent/utils.py CHANGED
@@ -1,4 +1,5 @@
1
1
  from mezo_agent.config import web3_instance, query_graph
2
+ from mezo_agent.utils import get_token_address_by_symbol
2
3
 
3
4
  def get_token_address_by_symbol(symbol: str) -> str:
4
5
  """
@@ -28,4 +29,42 @@ def get_token_address_by_symbol(symbol: str) -> str:
28
29
  return checksum_address
29
30
  else:
30
31
  available_symbols = [t["symbol"] for t in tokens]
31
- raise Exception(f"Token '{symbol}' not found. Available: {', '.join(available_symbols)}")
32
+ raise Exception(f"Token '{symbol}' not found. Available: {', '.join(available_symbols)}")
33
+
34
+
35
+ def get_token_price(token_symbol: str) -> str:
36
+ """
37
+ Fetches the price of a given token in USD and ETH from the Goldsky subgraph.
38
+
39
+ :param token_symbol: The token symbol (e.g., 'MUSD', 'WBTC').
40
+ :return: A formatted string with the token price in USD and ETH.
41
+ """
42
+ if token_symbol.lower() == "btc":
43
+ token_symbol = "wtbtc"
44
+
45
+ try:
46
+ token_address = get_token_address_by_symbol(token_symbol)
47
+ except Exception as e:
48
+ return f"❌ Token lookup error: {e}"
49
+
50
+ token_id = token_address.lower()
51
+ query = f'''
52
+ {{
53
+ token(id: "{token_id}") {{
54
+ id
55
+ decimals
56
+ derivedUSD
57
+ derivedETH
58
+ }}
59
+ }}
60
+ '''
61
+ try:
62
+ result = query_graph(query)
63
+ token_data = result["data"]["token"]
64
+ if token_data is None:
65
+ return f"❌ Price data for token {token_symbol.upper()} not found."
66
+ derivedUSD = token_data.get("derivedUSD", "N/A")
67
+ derivedETH = token_data.get("derivedETH", "N/A")
68
+ return f"✅ Price of {token_symbol.upper()}: {derivedUSD} USD, {derivedETH} ETH."
69
+ except Exception as e:
70
+ return f"❌ Failed to get price data: {e}"