Skip to content

Commit aafeed6

Browse files
author
balogh.adam@icloud.com
committed
token format
1 parent e6db60e commit aafeed6

3 files changed

Lines changed: 13 additions & 30 deletions

File tree

onchain/tokens/trending.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def get_trending_tokens(
104104
"""Retrieve the latest trending tokens on the given chain from DEX data."""
105105
chain = chain.lower()
106106
trending_tokens = get_trending_tokens_from_coingecko(chain)[:9]
107-
return f"""Trending tokens: {trending_tokens}. In your answer, include the ID of each token you mention in the following format: ```token:<insert token_id>```, and the name and symbol too."""
107+
return f"""Trending tokens: {trending_tokens}. In your answer, include the ID of each token you mention in the following format: token:<chain>:<address>, and the name and symbol too."""
108108

109109

110110
@tool

server/utils.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,46 +39,29 @@ def extract_patterns(
3939
text: str, pattern_type: str, remove_pattern=False
4040
) -> Tuple[str, List[str]]:
4141
"""
42-
Extract patterns of the form ```pattern_type:ID``` from text and return original text and extracted IDs.
42+
Extract patterns of the form pattern_type:chain:address from text.
43+
44+
Matches bare token:chain:address patterns as well as backtick-wrapped variants.
4345
4446
Args:
4547
text: The text to extract patterns from
46-
pattern_type: The type of pattern to extract (e.g. 'pool', 'token')
48+
pattern_type: The type of pattern to extract (e.g. 'token', 'swap')
4749
remove_pattern: If True, remove the pattern markers from the text
4850
4951
Returns:
5052
Tuple containing (processed_text, extracted_ids)
5153
"""
52-
pattern_ids = []
53-
54-
# Find all occurrences of ```pattern_type:ID``` patterns (with or without backticks)
55-
# Primary format: ```token:ID``` (triple backticks)
56-
pattern = f"```{pattern_type}:([^`]+)```"
54+
# Match pattern_type:chain:address — with or without backticks
55+
# chain is lowercase letters, address is alphanumeric 20+ chars
56+
pattern = f"(?:`{{1,3}})?{pattern_type}:([a-zA-Z]+:[a-zA-Z0-9]{{20,}})(?:`{{1,3}})?"
5757
matches = re.finditer(pattern, text)
5858

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

69-
# Only use fallback if primary pattern found nothing
70-
if not pattern_ids:
71-
for match in fallback_matches:
72-
pattern_ids.append(match.group(1))
73-
fallback_used = True
74-
else:
75-
fallback_used = False
76-
7763
if remove_pattern:
78-
# Remove all pattern markers from the text
7964
cleaned_text = re.sub(pattern, "", text)
80-
if fallback_used and pattern_ids:
81-
cleaned_text = re.sub(fallback_pattern, "", cleaned_text)
8265
return cleaned_text, pattern_ids
8366
else:
8467
return text, pattern_ids

templates/analytics_agent.jinja2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ You help users analyze market trends, evaluate protocols, tokens, buy and swap t
1313

1414
## Supported Use Cases:
1515

16-
- **Buy or swap a token on Solana:** First get the token metadata (search for it by name/symbol if needed), then return the token ID in this format: ```swap:<insert token_id>```. NEVER make up the token ID.
17-
- **Look up a token on any chain:** Search for the token to get metadata. Include the token ID in your answer: ```token:<insert token_id>```.
16+
- **Buy or swap a token on Solana:** First get the token metadata (search for it by name/symbol if needed), then return the token ID using the format token:chain:address. For swaps, use swap:chain:address. NEVER make up the token ID. Example: swap:solana:So11111111111111111111111111111111111111112
17+
- **Look up a token on any chain:** Search for the token to get metadata. Include the token ID in your answer using the format token:chain:address. Example: token:solana:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB
1818
- **Get the price of a token:** Use your price tools. For CoinGecko-based tools, use the CoinGecko ID (e.g. 'bitcoin', not 'BTC').
1919
- **Analyze a portfolio:** Use your portfolio analysis tools.
2020
- **Market overview / sentiment / signals:** Use your available market data, TVL, price trend, and market signal tools to build a comprehensive picture. If you have tools that list supported chains or signal types, call those first to discover what data is available.
21-
- **Trending tokens / memecoins:** Use your trending token tools. Include token IDs in your answer: ```token:<insert token_id>```.
21+
- **Trending tokens / memecoins:** Use your trending token tools. Include token IDs in your answer using the format token:chain:address.
2222
- **Token risk analysis:** Use your risk evaluation tools. If you need a token address, look it up yourself first — don't ask the user for it.
2323
- **Top holders:** Use your holder analysis tools.
2424

@@ -32,5 +32,5 @@ For complex questions, combine multiple tools to build a complete answer. Be res
3232
4. Summarize tool results clearly — don't dump raw data.
3333
5. If a tool returns an error, retry once. If it still fails, tell the user the error. NEVER fabricate data or pretend a tool succeeded when it didn't.
3434
6. Encourage buying/swapping tokens on Solana without being pushy.
35-
7. Token IDs must be the full ID including chain, e.g. 'solana:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'. Use ```swap:<token_id>``` format for buys. NEVER make up token IDs.
35+
7. Token IDs must be the full ID including chain, e.g. 'solana:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'. For buys use swap:chain:address, for lookups use token:chain:address. Write them as plain text — do NOT wrap them in backticks, code blocks, or any other formatting. NEVER make up token IDs.
3636
8. When you don't know something and have no tool to look it up, be honest about it. Don't make up data.

0 commit comments

Comments
 (0)