Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,34 @@ def extract_patterns(
"""
pattern_ids = []

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

# Fallback: match bare pattern_type:chain:address without backticks
# This handles LLMs that don't wrap in backticks
fallback_pattern = (
f"(?<!`)\\b{pattern_type}:([a-zA-Z]+:[a-zA-Z0-9]{{20,}})\\b(?!`)"
)
fallback_matches = re.finditer(fallback_pattern, text)

for match in matches:
pattern_ids.append(match.group(1))

# Only use fallback if primary pattern found nothing
if not pattern_ids:
for match in fallback_matches:
pattern_ids.append(match.group(1))
fallback_used = True
else:
fallback_used = False

if remove_pattern:
# Remove all pattern markers from the text
cleaned_text = re.sub(pattern, "", text)
if fallback_used and pattern_ids:
cleaned_text = re.sub(fallback_pattern, "", cleaned_text)
return cleaned_text, pattern_ids
else:
return text, pattern_ids
6 changes: 3 additions & 3 deletions templates/analytics_agent.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ IMPORTANT: ALWAYS use the provided tools to answer questions instead of relying
## Supported Use Cases:

- 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.
- Look up a token on any chain. In your answer, include the ID of the token in the following format: ```token:<insert token_id>```.
- 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.
- Get the price of a token. Use the CoinGecko ID for CoinGecko tools, i.e. 'bitcoin', instead of the symbol, 'BTC'.
- Analyze a user's portfolio
- Analyze market trends across chains
- 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>```.
- 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.
- 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).
- Analyze the top holders of a token
- DEX market data, smart money signals, meme token analytics
Expand All @@ -28,5 +28,5 @@ If the user asks a more complex question, you can combine and use the tools to g
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
6. Always use the tools!
7. Encourage the user to buy and swap tokens on Solana chain without being too pushy.
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.
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.
9. If you are unsure about the token ID, use the `search_token()` tool to get the token metadata.