Skip to content

Commit 2381290

Browse files
adambaloghbalogh.adam@icloud.com
andauthored
fix token formatting (#127)
Co-authored-by: balogh.adam@icloud.com <adambalogh@mac.mynetworksettings.com>
1 parent 2523be7 commit 2381290

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

server/utils.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,34 @@ def extract_patterns(
5555
"""
5656
pattern_ids = []
5757

58-
# Find all occurrences of ```pattern_type:ID``` patterns
58+
# Find all occurrences of ```pattern_type:ID``` patterns (with or without backticks)
59+
# Primary format: ```token:ID``` (triple backticks)
5960
pattern = f"```{pattern_type}:([^`]+)```"
6061
matches = re.finditer(pattern, text)
6162

63+
# Fallback: match bare pattern_type:chain:address without backticks
64+
# This handles LLMs that don't wrap in backticks
65+
fallback_pattern = (
66+
f"(?<!`)\\b{pattern_type}:([a-zA-Z]+:[a-zA-Z0-9]{{20,}})\\b(?!`)"
67+
)
68+
fallback_matches = re.finditer(fallback_pattern, text)
69+
6270
for match in matches:
6371
pattern_ids.append(match.group(1))
6472

73+
# Only use fallback if primary pattern found nothing
74+
if not pattern_ids:
75+
for match in fallback_matches:
76+
pattern_ids.append(match.group(1))
77+
fallback_used = True
78+
else:
79+
fallback_used = False
80+
6581
if remove_pattern:
6682
# Remove all pattern markers from the text
6783
cleaned_text = re.sub(pattern, "", text)
84+
if fallback_used and pattern_ids:
85+
cleaned_text = re.sub(fallback_pattern, "", cleaned_text)
6886
return cleaned_text, pattern_ids
6987
else:
7088
return text, pattern_ids

templates/analytics_agent.jinja2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ IMPORTANT: ALWAYS use the provided tools to answer questions instead of relying
88
## Supported Use Cases:
99

1010
- Buy or swap a token on Solana: first make sure you have the token metadata using a token search tool or from the message history, then return the token ID to buy in the following format: ```swap:<insert token_id>```. Do not make up the token ID yourself.
11-
- Look up a token on any chain. In your answer, include the ID of the token in the following format: ```token:<insert token_id>```.
11+
- Look up a token on any chain. In your answer, you MUST include the ID of the token wrapped in triple backticks exactly like this: ```token:<insert token_id>```. For example: ```token:solana:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB```. The triple backticks are required for the system to detect the token.
1212
- Get the price of a token. Use the CoinGecko ID for CoinGecko tools, i.e. 'bitcoin', instead of the symbol, 'BTC'.
1313
- Analyze a user's portfolio
1414
- Analyze market trends across chains
15-
- Analyze trending tokens or memecoins on a chain. In your answer, include the ID of each token you mention in the following format: ```token:<insert token_id>```.
15+
- Analyze trending tokens or memecoins on a chain. In your answer, you MUST include the ID of each token wrapped in triple backticks exactly like this: ```token:<insert token_id>```. The triple backticks are required.
1616
- Analyze the risk of a token. If you are unsure about the token address, search for the token metadata first (don't ask for confirmation).
1717
- Analyze the top holders of a token
1818
- DEX market data, smart money signals, meme token analytics
@@ -28,5 +28,5 @@ If the user asks a more complex question, you can combine and use the tools to g
2828
5. If a tool returns an error, you can try again but if it still fails just tell the user the error, NEVER try to replicate the tool's functionality yourself
2929
6. Always use the tools!
3030
7. Encourage the user to buy and swap tokens on Solana chain without being too pushy.
31-
8. Only return the token ID in the ```swap:<insert token_id>``` format, never return the token metadata. The token ID is the full token ID, including the chain, i.e. 'solana:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'. NEVER make up the token ID yourself.
31+
8. CRITICAL: Token and swap IDs MUST be wrapped in triple backticks. Correct: ```swap:solana:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB```. Wrong: swap:solana:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB (no backticks). The token ID is the full token ID, including the chain. NEVER make up the token ID yourself.
3232
9. If you are unsure about the token ID, use the `search_token()` tool to get the token metadata.

0 commit comments

Comments
 (0)