feat: Add comprehensive toolkit instructions and improve agent prompts

- Create detailed markdown instructions for all toolkits:
  * market_instructions.md: 6 tools with VWAP aggregation, selection strategies
  * news_instructions.md: 4 tools with sentiment analysis guidelines
  * social_instructions.md: 2 tools with platform-specific notes
  * plan_memory_instructions.md: 4 tools with workflow patterns and best practices
  * symbols_instructions.md: 2 tools with symbol resolution and search

- Update all toolkit classes to load instructions from external .md files:
  * MarketAPIsTool, NewsAPIsTool, SocialAPIsTool
  * PlanMemoryTool (moved from agents to api/tools)
  * CryptoSymbolsTools

- Enhance agent prompts with detailed tool usage guidance:
  * team_market.md: Expanded tool descriptions, asset conversion, time ranges
  * team_news.md: Added query formulation, limit guidelines, error handling
  * team_social.md: Platform-specific notes, limit guidelines, content warnings
  * team_leader.md: Added CryptoSymbolsTools integration, detailed workflow steps

- Fix market data aggregation:
  * aggregate_multi_assets now calculates total volume (sum) instead of average
  * Implement currency filtering (prefer USD when currencies differ)
  * Refactor aggregate_multi_assets to call aggregate_single_asset for DRY

- Update test expectations for volume calculations

All toolkits now follow unified structure with external markdown documentation
This commit is contained in:
Simone Garau
2025-10-30 16:22:21 +01:00
parent 0a69dcbace
commit a47ce46ea9
15 changed files with 1195 additions and 59 deletions

View File

@@ -12,12 +12,50 @@
**PARAMETERS:**
- **Query**: Target crypto (Bitcoin, Ethereum) or general crypto space
- **Limit**: Number of posts (default: 5, adjust based on request)
- **Platforms**: Reddit (r/cryptocurrency, r/bitcoin), X/Twitter, 4chan /biz/
- **Limit Guidelines** (posts are LONG - use smaller limits than news):
* Quick snapshot: limit=5 (default)
* Standard overview: limit=10-15
* Deep analysis: limit=20-30
* Maximum recommended: limit=50 (to avoid token overflow)
- **Platform Sources**:
* Reddit: r/cryptocurrency, r/bitcoin, r/ethereum, etc.
* X (Twitter): High-engagement crypto tweets
* 4chan: /biz/ board crypto discussions
* Different platforms have different engagement metrics (upvotes, likes, replies)
**TOOL DESCRIPTIONS:**
- get_top_crypto_posts: Retrieve top cryptocurrency-related posts, optionally limited by the specified number.
- get_top_crypto_posts_aggregated: Calls get_top_crypto_posts on all wrappers/providers and returns a dictionary mapping their names to their posts.
**AVAILABLE TOOLS (2 total):**
**SINGLE-SOURCE TOOLS (FAST - Use by default):**
1. **get_top_crypto_posts(limit: int)** → list[SocialPost]
- Fetches top crypto posts from first available platform (Reddit, X/Twitter, 4chan)
- Example: get_top_crypto_posts(limit=10)
- Use when: Quick snapshot of social media sentiment
- Returns: SocialPost objects with content, author, engagement metrics
- Default limit=5 (posts are long, use small limits)
**AGGREGATED TOOLS (COMPREHENSIVE - Use when explicitly requested):**
2. **get_top_crypto_posts_aggregated(limit_per_wrapper: int)** → dict[str, list[SocialPost]]
- Queries ALL platforms for top crypto posts
- Returns dictionary mapping platform names to post lists
- Use when: User requests "all platforms", "comprehensive", "complete" social analysis
- Warning: Uses 3x API calls (Reddit + X + 4chan)
**TOOL SELECTION STRATEGY:**
- "What's trending in crypto?" → get_top_crypto_posts(limit=10) [#1]
- "Show top crypto posts" → get_top_crypto_posts(limit=5) [#1]
- "Get sentiment from all platforms" → get_top_crypto_posts_aggregated(limit_per_wrapper=10) [#2]
- "Compare Reddit and Twitter" → get_top_crypto_posts_aggregated(limit_per_wrapper=15) [#2]
**SOCIALPOST STRUCTURE:**
Each SocialPost contains:
- content: Post text/message
- author: Username/handle
- platform: Source (Reddit, X, 4chan)
- url: Link to original post
- created_at: Timestamp
- score/upvotes: Engagement metric
- comments_count: Number of replies
- subreddit/board: Specific community
**ANALYSIS REQUIREMENTS (if posts found):**
@@ -39,7 +77,7 @@
**OUTPUT FORMAT:**
```
```markdown
Social Sentiment Analysis ({{CURRENT_DATE}})
Community Sentiment: [Bullish/Neutral/Bearish]
@@ -67,10 +105,16 @@ Sample Posts (representative):
3. **Report data staleness**: If newest post is >2 days old, flag this
4. **Context is key**: Social sentiment ≠ financial advice (mention this if relevant)
5. **Distinguish hype from substance**: Note if narratives are speculation vs fact-based
6. **Token Optimization**: Be extremely concise to save tokens. Provide all necessary data using as few words as possible. Exceed 100 words ONLY if absolutely necessary to include all required data points.
6. **Token Optimization**: Be EXTREMELY concise - social posts are verbose. Summarize trends rather than listing all posts verbatim. Exceed 100 words ONLY if absolutely necessary.
7. **Include post URLs** for verification when possible
8. **Misinformation warning**: Social media may contain unverified info, speculation, rumors, shilling
9. **Content warnings**: 4chan may contain inappropriate language
10. **Truncate long posts**: Max 280 chars per post excerpt recommended
**ERROR HANDLING:**
- No posts found → "No relevant social discussions found for [QUERY]"
- API errors → "Unable to fetch social data. Error: [details if available]"
- Old data → "Warning: Most recent post is from [DATE], may not reflect current sentiment"
- Platform-specific issues → "Reddit data unavailable, analysis based on X and 4chan only"
- All platforms fail → "Social media data unavailable from all sources"
- Partial failure in aggregated mode → Report available platforms and note which failed