Skip to content

Latest commit

 

History

History
326 lines (252 loc) · 9.84 KB

File metadata and controls

326 lines (252 loc) · 9.84 KB

RAG Memecoin Edit Analysis Workflow

📋 Document Summary

What This Document Covers:

  • AI-powered feedback analysis for memecoin editing
  • Intelligent field detection from natural language
  • Targeted regeneration of affected metadata only
  • Edit proposal caching for approval workflow
  • MemeStorageOrchestrator integration

Sections in This Document:

Related Documentation:

Context Tags: #workflow #editing #ai-analysis #proposal-system #metadata-generation


AI-powered memecoin editing workflow that analyzes user feedback and generates intelligent edit proposals using LLM-based field analysis.

Overview

The RAG Memecoin Edit Analysis Workflow provides intelligent memecoin editing through:

  • LLM-powered feedback analysis - Understands user intent from natural language
  • Targeted field regeneration - Updates only affected metadata fields
  • Proposal-based editing - Generates editable proposals for user review
  • No executor needed - Returns edited data directly for orchestrator integration

File: src/workflows/rag_memecoin_edit_analysis_workflow.py

Architecture

Workflow Pattern: InputSource → Processor → Return (No Executor)

MemoryMemecoinInputSource → RAGMemecoinEditProcessor → Edited MemecoinEntry
        ↓                           ↓                          ↓
Single memecoin          Feedback analysis         Proposal data
  from memory            + LLM regeneration         (cached 5 min)

Unique Design: This workflow does NOT use an executor. It processes the memecoin and returns the edited entry directly to the orchestrator for caching and proposal generation.

Processing Pipeline

RAGMemecoinEditProcessor - Single-stage intelligent analysis:

  1. FeedbackAnalysisAndRegenerationStage:
    • Analyzes user feedback to determine affected fields
    • Regenerates only the fields mentioned in feedback
    • Preserves unchanged fields from original data
    • Returns updated MemecoinEntry

LLM Analysis Logic:

  • "incorrect entity/characters" → Regenerate caption_entity
  • "wrong context/meme reference" → Regenerate caption_context
  • "incorrect visual style" → Regenerate caption_visual
  • "wrong emotions/tone" → Regenerate caption_emotions
  • "change tags" → Update tags array
  • "rename to X" → Update token_name/ticker/description

Usage

As Orchestrator Integration

from src.workflows.rag_memecoin_edit_analysis_workflow import RAGMemecoinEditAnalysisWorkflow

# Initialize workflow
workflow = RAGMemecoinEditAnalysisWorkflow()
await workflow.initialize()

# Run with user feedback
memecoin_data = {
    "token_name": "CryptoDog",
    "ticker": "CDOG",
    "description": "A memecoin featuring a dog",
    "token_address": "ABC123...",
    "tags": ["animal", "meme"],
    "caption_structured": {
        "entity": "A cartoon dog",
        "context": "Internet meme culture",
        "visual": "Cartoon style",
        "emotions": "Happy and playful"
    }
}

user_feedback = "The entity should be a cat, not a dog"

# Get edited memecoin
edited_entry = await workflow.run(memecoin_data, user_feedback)

# Cleanup
await workflow.cleanup()

Feedback Examples

Entity Correction:

"The entity should be a cat, not a dog"
→ Regenerates: caption_entity

Multiple Fields:

"The context is wrong - should reference Nyan Cat meme. Also add rainbow tags."
→ Regenerates: caption_context
→ Updates: tags

Data Models

Input: Memecoin Data Dictionary

{
    "token_name": str,              # Memecoin name
    "ticker": str,                  # Ticker symbol
    "description": str,             # Description
    "token_address": str,           # Blockchain address
    "tags": List[str],              # Classification tags
    "image_base64": str,            # Base64 image (unchanged)
    "image_mime_type": str,         # Image MIME type
    "caption_structured": {         # 4-part caption structure
        "entity": str,              # What is shown
        "context": str,             # Meme references
        "visual": str,              # Art style
        "emotions": str             # Mood/tone
    }
}

Output: Returns MemecoinEntry with updated fields based on feedback analysis.

LLM Prompt Structure

The processor uses a targeted prompt for intelligent analysis:

CURRENT MEMECOIN DATA:
- Token Name: {name}
- Ticker: {ticker}
- Description: {description}
- Tags: {tags}

CURRENT CAPTION:
- Entity: {entity}
- Context: {context}
- Visual: {visual}
- Emotions: {emotions}

USER FEEDBACK:
"{user_feedback}"

TASK: Analyze feedback and regenerate ONLY affected fields

RESPONSE FORMAT (JSON):
{
    "token_name": "...",
    "ticker": "...",
    "description": "...",
    "tags": [...],
    "caption_entity": "...",
    "caption_context": "...",
    "caption_visual": "...",
    "caption_emotions": "..."
}

Key Features:

  • Lower temperature (0.3) for focused edits
  • JSON response for structured updates
  • Preserves unchanged fields
  • Maintains caption structure consistency

Integration with MemeStorageOrchestrator

Orchestrator Method: generate_edit_proposal()

success, message, result = await orchestrator.generate_edit_proposal(
    token_address="ABC123...",
    user_feedback="The entity should be a cat, not a dog"
)

if success:
    proposal_uuid = result["proposal_uuid"]
    proposal_data = result["proposal"]

    # Proposal cached for 5 minutes
    # User can review and accept/reject

Proposal Flow

  1. Fetch from Vector DB: Orchestrator retrieves memecoin
  2. Run Workflow: Calls RAGMemecoinEditAnalysisWorkflow.run()
  3. Generate UUID: Creates unique proposal identifier
  4. Cache Proposal: Stores in orchestrator with 5-minute TTL
  5. Return to API: Frontend displays proposal for review

Proposal Cache Structure

# In MemeStorageOrchestrator
self._edit_proposals: Dict[str, Tuple[datetime, Dict[str, Any]]] = {}

# Entry format:
{
    "proposal_uuid_here": (
        datetime.now(),  # Timestamp
        {
            "token_name": "...",
            "ticker": "...",
            "description": "...",
            "tags": [...],
            "caption_structured": {...}
        }
    )
}

# TTL: 5 minutes (300 seconds)

Error Handling

The workflow handles validation errors (empty data/feedback), LLM response parsing failures (markdown code blocks), and processing errors (stage failures). See implementation for details.

Web UI Integration

API Endpoint: POST /api/database/memecoins/{token_address}/ai-edit

Request:

{
    "feedback": "The entity should be a cat, not a dog"
}

Response:

{
    "status": 200,
    "success": true,
    "message": "Edit proposal generated successfully",
    "proposal_uuid": "550e8400-e29b-41d4-a716-446655440000",
    "proposal": {
        "token_name": "CryptoCat",
        "ticker": "CCAT",
        "description": "A memecoin featuring a cat",
        "tags": ["animal", "meme", "cat"],
        "caption_structured": {
            "entity": "A cartoon cat",  // UPDATED
            "context": "Internet meme culture",
            "visual": "Cartoon style",
            "emotions": "Happy and playful"
        }
    }
}

Frontend Flow

  1. User selects memecoin in database browser
  2. Clicks "Edit" button (keyboard shortcut: E)
  3. Enters feedback in modal: "The entity should be a cat"
  4. Frontend POSTs to edit endpoint
  5. Receives proposal with UUID
  6. Displays proposal for review
  7. User can:
    • Accept: PATCH to base endpoint with proposal UUID
    • Edit manually: Modify proposal fields
    • Reject: Cancel operation

Testing

See tests/workflows/test_rag_memecoin_edit_analysis_workflow.py for unit tests and tests/integration/orchestrator/test_meme_storage_orchestrator.py for integration tests.

Troubleshooting

Issue: LLM returns invalid JSON

Solution: Processor handles markdown code blocks with JSON extraction

Issue: Unchanged fields are modified

Solution: Lower temperature (0.3) with explicit instructions to preserve unchanged fields

Issue: Proposal expired

Solution: Frontend warns user at 4 minutes, auto-refreshes proposal

Issue: Caption structure inconsistent

Solution: Processor creates empty structure if missing from original data

Related Documentation

Key Takeaways

LLM-Powered Analysis - Intelligent field detection from natural language ✅ Targeted Regeneration - Updates only affected fields ✅ No Executor Needed - Returns data directly for caching ✅ 5-Minute Proposal Cache - TTL-based cleanup ✅ JSON Response Parsing - Handles markdown code blocks ✅ Low Temperature - Focused edits (0.3) ✅ Orchestrator Integration - Seamless proposal workflow ✅ Web UI Support - Complete edit interface


For the complete update pipeline (re-embedding + vector DB update), see RAG Memecoin Update Workflow