From 36435ce2e3863c9dfd2fb17c75b5eb5d28895670 Mon Sep 17 00:00:00 2001 From: "balogh.adam@icloud.com" Date: Thu, 12 Mar 2026 09:56:58 -0400 Subject: [PATCH] fix token formatting --- server/utils.py | 20 +++++++++++++++++++- templates/analytics_agent.jinja2 | 6 +++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/server/utils.py b/server/utils.py index 1bc5657..fdb4ee2 100644 --- a/server/utils.py +++ b/server/utils.py @@ -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"(?```. 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:```. +- 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:```. 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:```. +- 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:```. 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 @@ -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:``` 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.