mezoAgent 0.5.4__tar.gz → 0.6.0__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {mezoagent-0.5.4 → mezoagent-0.6.0}/PKG-INFO +1 -1
- {mezoagent-0.5.4 → mezoagent-0.6.0}/mezoAgent.egg-info/PKG-INFO +1 -1
- {mezoagent-0.5.4 → mezoagent-0.6.0}/mezoAgent.egg-info/SOURCES.txt +1 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/mezo_agent/parsing.py +34 -1
- mezoagent-0.6.0/mezo_agent/token_price_tool.py +27 -0
- mezoagent-0.6.0/mezo_agent/utils.py +70 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/setup.py +1 -1
- mezoagent-0.5.4/mezo_agent/utils.py +0 -31
- {mezoagent-0.5.4 → mezoagent-0.6.0}/MANIFEST.in +0 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/README.md +0 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/mezoAgent.egg-info/dependency_links.txt +0 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/mezoAgent.egg-info/requires.txt +0 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/mezoAgent.egg-info/top_level.txt +0 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/mezo_agent/__init__.py +0 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/mezo_agent/characters.py +0 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/mezo_agent/chat.py +0 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/mezo_agent/config.py +0 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/mezo_agent/data/new_router.json +0 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/mezo_agent/swap_musd_btc.py +0 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/mezo_agent/token_balance_tool.py +0 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/mezo_agent/transaction.py +0 -0
- {mezoagent-0.5.4 → mezoagent-0.6.0}/setup.cfg +0 -0
@@ -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)}"
|
@@ -0,0 +1,70 @@
|
|
1
|
+
from mezo_agent.config import web3_instance, query_graph
|
2
|
+
from mezo_agent.utils import get_token_address_by_symbol
|
3
|
+
|
4
|
+
def get_token_address_by_symbol(symbol: str) -> str:
|
5
|
+
"""
|
6
|
+
Fetches the token contract address dynamically from the Goldsky subgraph.
|
7
|
+
:param symbol: Token symbol (e.g., 'MUSD', 'WBTC').
|
8
|
+
:return: Ethereum checksum address of the token.
|
9
|
+
"""
|
10
|
+
if symbol.lower() == "btc":
|
11
|
+
symbol = "wtbtc"
|
12
|
+
|
13
|
+
query_all = '''
|
14
|
+
{
|
15
|
+
tokens(first: 100) {
|
16
|
+
id
|
17
|
+
symbol
|
18
|
+
}
|
19
|
+
}
|
20
|
+
'''
|
21
|
+
data = query_graph(query_all)
|
22
|
+
tokens = data.get("data", {}).get("tokens", [])
|
23
|
+
matching_tokens = [t for t in tokens if t["symbol"].lower() == symbol.lower()]
|
24
|
+
|
25
|
+
if matching_tokens:
|
26
|
+
token_address = matching_tokens[0]["id"]
|
27
|
+
checksum_address = web3_instance.to_checksum_address(token_address)
|
28
|
+
print(f"✅ Token {symbol} found at address: {checksum_address}") # Debugging
|
29
|
+
return checksum_address
|
30
|
+
else:
|
31
|
+
available_symbols = [t["symbol"] for t in tokens]
|
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}"
|
@@ -1,31 +0,0 @@
|
|
1
|
-
from mezo_agent.config import web3_instance, query_graph
|
2
|
-
|
3
|
-
def get_token_address_by_symbol(symbol: str) -> str:
|
4
|
-
"""
|
5
|
-
Fetches the token contract address dynamically from the Goldsky subgraph.
|
6
|
-
:param symbol: Token symbol (e.g., 'MUSD', 'WBTC').
|
7
|
-
:return: Ethereum checksum address of the token.
|
8
|
-
"""
|
9
|
-
if symbol.lower() == "btc":
|
10
|
-
symbol = "wtbtc"
|
11
|
-
|
12
|
-
query_all = '''
|
13
|
-
{
|
14
|
-
tokens(first: 100) {
|
15
|
-
id
|
16
|
-
symbol
|
17
|
-
}
|
18
|
-
}
|
19
|
-
'''
|
20
|
-
data = query_graph(query_all)
|
21
|
-
tokens = data.get("data", {}).get("tokens", [])
|
22
|
-
matching_tokens = [t for t in tokens if t["symbol"].lower() == symbol.lower()]
|
23
|
-
|
24
|
-
if matching_tokens:
|
25
|
-
token_address = matching_tokens[0]["id"]
|
26
|
-
checksum_address = web3_instance.to_checksum_address(token_address)
|
27
|
-
print(f"✅ Token {symbol} found at address: {checksum_address}") # Debugging
|
28
|
-
return checksum_address
|
29
|
-
else:
|
30
|
-
available_symbols = [t["symbol"] for t in tokens]
|
31
|
-
raise Exception(f"Token '{symbol}' not found. Available: {', '.join(available_symbols)}")
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|