Skip to content

Conversation

@3rd-Son
Copy link
Contributor

@3rd-Son 3rd-Son commented Dec 15, 2025

πŸ”— Linked Issue

Closes #

βœ… Type of Change

  • ✨ New Project/Feature
  • 🐞 Bug Fix
  • πŸ“š Documentation Update
  • πŸ”¨ Refactor or Other

πŸ“ Summary

πŸ“– README Checklist

  • I have created a README.md file for my project.
  • My README.md follows the official .github/README_TEMPLATE.md.
  • I have included clear installation and usage instructions in my README.md.
  • I have added a GIF or screenshot to the assets folder and included it in my README.md.

βœ”οΈ Contributor Checklist

  • I have read the CONTRIBUTING.md document.
  • My code follows the project's coding standards.
  • I have placed my project in the correct directory (e.g., advance_ai_agents, rag_apps).
  • I have included a requirements.txt or pyproject.toml for dependencies.
  • I have added a .env.example file if environment variables are needed and ensured no secrets are committed.
  • My pull request is focused on a single project or change.

πŸ’¬ Additional Comments


EntelligenceAI PR Summary

This PR adds a new YouTube Trend Analysis Agent feature that combines yt-dlp, Memori v3, OpenAI, and Exa AI to help content creators analyze channel performance and discover trending topics.

  • Implemented core module with functions for Memori initialization, YouTube channel scraping (up to 20 videos), Exa trend fetching, and metadata ingestion
  • Created Streamlit web application with chat interface, API key configuration sidebar, and agent-based content recommendation system
  • Added project configuration with Python 3.11+ requirement and dependencies: agno, memori, streamlit, python-dotenv, openai, sqlalchemy, exa-py, yt-dlp
  • Included comprehensive README with setup instructions, environment variable configuration, and usage guidelines
  • Added Streamlit theme configuration and Memori logo asset for UI branding

@entelligence-ai-pr-reviews
Copy link

Entelligence AI Vulnerability Scanner

Status: No security vulnerabilities found

Your code passed our comprehensive security analysis.

Analyzed 2 files in total

@entelligence-ai-pr-reviews
Copy link

Review Summary

🏷️ Draft Comments (6)

Skipped posting 6 draft comments that were valid but scored below your review threshold (>=13/15). Feel free to update them here.

memory_agents/youtube_trend_agent/app.py (3)

38-258: main function is excessively large and complex (89+ statements, 23+ branches), making it hard to maintain and optimize for performance as the app grows.

πŸ“Š Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 3/5
  • Urgency Impact: 2/5
  • Total Score: 7/15

πŸ€– AI Agent Prompt (Copy & Paste Ready):

Refactor memory_agents/youtube_trend_agent/app.py, lines 38-258. The `main` function is excessively large and complex (89+ statements, 23+ branches), making it hard to maintain and optimize. Break `main` into smaller, well-named helper functions (e.g., _render_title, _init_session_state, _render_sidebar, _require_api_key, _render_chat_history, _handle_chat_input), each encapsulating a logical section. Replace the body of `main` with calls to these helpers in order. Ensure code formatting and logic are preserved.

174-191: Repeatedly fetching and joining video summaries in a loop (for v in videos[:10]) can be slow for large lists; should precompute or cache summaries to avoid redundant computation.

πŸ“Š Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 5/5
  • Urgency Impact: 2/5
  • Total Score: 9/15

πŸ€– AI Agent Prompt (Copy & Paste Ready):

Optimize memory_agents/youtube_trend_agent/app.py, lines 174-191. The code repeatedly computes video summaries in a loop for every prompt, which is inefficient for large lists. Refactor to precompute and cache the video summaries in st.session_state["video_summaries"] the first time videos are loaded, and reuse the cached value for subsequent prompts. Preserve formatting and logic.

96-101: openai_api_key_input, exa_api_key_input, and memori_api_key_input are set directly to os.environ at runtime, allowing user-supplied values to overwrite environment variables for the entire process, enabling session-wide API key hijacking or privilege escalation if a malicious user submits a crafted key.

πŸ“Š Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 3/5
  • Urgency Impact: 4/5
  • Total Score: 11/15

πŸ€– AI Agent Prompt (Copy & Paste Ready):

In memory_agents/youtube_trend_agent/app.py, lines 96-101, user-supplied API keys are written directly to os.environ, which can allow a malicious user to overwrite environment variables for the entire process, leading to session-wide API key hijacking or privilege escalation. Change these assignments to use st.session_state instead of os.environ, so that API keys are only stored per user session and not globally.

memory_agents/youtube_trend_agent/core.py (3)

122-123: fetch_channel_videos will crash with AttributeError if yt_dlp.extract_info returns None or a non-dict (e.g., on invalid/removed channel), since info.get("entries") is called unconditionally.

πŸ“Š Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 5/5
  • Urgency Impact: 3/5
  • Total Score: 12/15

πŸ€– AI Agent Prompt (Copy & Paste Ready):

In memory_agents/youtube_trend_agent/core.py, lines 122-123, the code assumes that `info` is always a dict, but `yt_dlp.extract_info` can return None or a non-dict, causing an AttributeError. Add a type check for `info` before calling `info.get(...)`, and return an empty list if it's not a dict.

133-137: fetch_channel_videos may generate invalid YouTube URLs if entry.get("url") is present but not a full watch URL, since it doesn't always build the correct full_url.

πŸ“Š Impact Scores:

  • Production Impact: 3/5
  • Fix Specificity: 4/5
  • Urgency Impact: 2/5
  • Total Score: 9/15

πŸ€– AI Agent Prompt (Copy & Paste Ready):

In memory_agents/youtube_trend_agent/core.py, lines 133-137, the logic for constructing `full_url` can result in invalid or partial URLs if `url` is present but not a full YouTube watch URL. Always construct the full YouTube watch URL using `video_id` if available; otherwise, fall back to `url` or `channel_url`.

265-307: ingest_channel_into_memori performs a separate OpenAI API call for every video, causing high latency and API cost for large channels (O(n) network calls, no batching or caching).

πŸ“Š Impact Scores:

  • Production Impact: 3/5
  • Fix Specificity: 4/5
  • Urgency Impact: 2/5
  • Total Score: 9/15

πŸ€– AI Agent Prompt (Copy & Paste Ready):

In memory_agents/youtube_trend_agent/core.py, lines 265-307, the function `ingest_channel_into_memori` makes a separate OpenAI API call for every video, causing high latency and API cost for large channels. Refactor this loop to batch video metadata (e.g., 5 at a time) and send them in a single API call per batch, reducing the number of network requests and improving performance. Preserve all original logic and error handling.

@entelligence-ai-pr-reviews
Copy link

Walkthrough

This PR introduces a new YouTube Trend Analysis Agent feature that enables content creators to analyze their channel performance and discover trending topics. The implementation includes a Streamlit-based web application that integrates multiple services: yt-dlp for scraping YouTube channel data, Memori v3 for semantic search and storage of video metadata, OpenAI for LLM-powered reasoning, and Exa AI for fetching web trend context. The agent allows users to ingest their YouTube content, chat with an AI advisor, and receive data-driven video content recommendations based on their existing videos and current market trends. The feature is packaged as a standalone module with comprehensive documentation and configuration.

Changes

File(s) Summary
memory_agents/youtube_trend_agent/README.md Added comprehensive documentation describing the YouTube Trend Analysis Agent, including setup instructions using uv package manager, required/optional environment variables (OPENAI_API_KEY, EXA_API_KEY, MEMORI_API_KEY, SQLITE_DB_PATH), and usage instructions for the Streamlit UI.
memory_agents/youtube_trend_agent/pyproject.toml Added Python project configuration defining metadata, Python 3.11+ requirement, and seven core dependencies: agno, memori, streamlit, python-dotenv, openai, sqlalchemy, exa-py, and yt-dlp.
memory_agents/youtube_trend_agent/core.py Implemented core module with four main functions: init_memori_with_openai() for Memori initialization with SQLite persistence, fetch_channel_videos() for scraping up to 20 recent videos using yt-dlp, fetch_exa_trends() for querying trending topics via Exa AI, and ingest_channel_into_memori() for orchestrating video metadata ingestion. Includes error handling and silent logger for yt-dlp output suppression.
memory_agents/youtube_trend_agent/app.py Created Streamlit application implementing chat interface for YouTube trend analysis with sidebar for API key configuration and channel ingestion, main chat interface querying Memori for video history, and agent-based system providing content suggestions based on channel performance and external trends.
memory_agents/youtube_trend_agent/.streamlit/config.toml Added Streamlit configuration file setting base theme to 'light' mode with commented-out optional theme customization properties for UI theming.
memory_agents/youtube_trend_agent/assets/Memori_Logo.png Added binary image asset for UI branding.

Sequence Diagram

This diagram shows the interactions between components:

sequenceDiagram
    actor User
    participant Streamlit as Streamlit App
    participant Core as Core Functions
    participant YouTube as YouTube (yt-dlp)
    participant Memori as Memori Service
    participant Exa as Exa API
    participant Agent as Agno Agent
    participant OpenAI as OpenAI

    Note over User,OpenAI: Channel Ingestion Flow
    
    User->>Streamlit: Enter API keys & channel URL
    User->>Streamlit: Click "Ingest channel into Memori"
    Streamlit->>Core: ingest_channel_into_memori(channel_url)
    Core->>YouTube: Scrape channel videos (yt-dlp)
    YouTube-->>Core: Video metadata (titles, views, descriptions)
    Core->>Memori: Store video data
    Memori-->>Core: Confirmation
    Core-->>Streamlit: Return video count
    Streamlit-->>User: Display success message

    Note over User,OpenAI: Chat/Analysis Flow
    
    User->>Streamlit: Ask question about trends
    Streamlit->>Streamlit: Append to messages
    
    alt Memori available
        Streamlit->>Memori: search(prompt, limit=5)
        Memori-->>Streamlit: Relevant video snippets
    end
    
    Streamlit->>Streamlit: Build video summaries from session
    
    alt Exa API configured
        alt Exa trends not cached
            Streamlit->>Core: fetch_exa_trends(channel_name, videos)
            Core->>Exa: Search web trends for niche
            Exa-->>Core: External trend data
            Core-->>Streamlit: Formatted trends
            Streamlit->>Streamlit: Cache trends in session
        else Exa trends cached
            Streamlit->>Streamlit: Reuse cached trends
        end
    end
    
    Streamlit->>Streamlit: Build full_prompt with context
    Note over Streamlit: Combines: user question, Memori results,<br/>video summaries, Exa trends
    
    Streamlit->>Agent: Create Agent with OpenAIChat model
    Streamlit->>Agent: run(full_prompt)
    Agent->>OpenAI: Generate response
    OpenAI-->>Agent: AI-generated analysis
    Agent-->>Streamlit: result.content
    
    Streamlit->>Streamlit: Append to messages
    Streamlit-->>User: Display response
Loading

πŸ”— Cross-Repository Impact Analysis

Enable automatic detection of breaking changes across your dependent repositories. β†’ Set up now

Learn more about Cross-Repository Analysis

What It Does

  • Automatically identifies repositories that depend on this code
  • Analyzes potential breaking changes across your entire codebase
  • Provides risk assessment before merging to prevent cross-repo issues

How to Enable

  1. Visit Settings β†’ Code Management
  2. Configure repository dependencies
  3. Future PRs will automatically include cross-repo impact analysis!

Benefits

  • πŸ›‘οΈ Prevent breaking changes across repositories
  • πŸ” Catch integration issues before they reach production
  • πŸ“Š Better visibility into your multi-repo architecture

▢️ ⚑ AI Code Reviews for VS Code, Cursor, Windsurf
Install the extension

Note for Windsurf Please change the default marketplace provider to the following in the windsurf settings:

Marketplace Extension Gallery Service URL: https://marketplace.visualstudio.com/_apis/public/gallery

Marketplace Gallery Item URL: https://marketplace.visualstudio.com/items

Entelligence.ai can learn from your feedback. Simply add πŸ‘ / πŸ‘Ž emojis to teach it your preferences. More shortcuts below

Emoji Descriptions:

  • ⚠️ Potential Issue - May require further investigation.
  • πŸ”’ Security Vulnerability - Fix to ensure system safety.
  • πŸ’» Code Improvement - Suggestions to enhance code quality.
  • πŸ”¨ Refactor Suggestion - Recommendations for restructuring code.
  • ℹ️ Others - General comments and information.

Interact with the Bot:

  • Send a message or request using the format:
    @entelligenceai + *your message*
Example: @entelligenceai Can you suggest improvements for this code?
  • Help the Bot learn by providing feedback on its responses.
    @entelligenceai + *feedback*
Example: @entelligenceai Do not comment on `save_auth` function !

Also you can trigger various commands with the bot by doing
@entelligenceai command

The current supported commands are

  1. config - shows the current config
  2. retrigger_review - retriggers the review

More commands to be added soon.

Comment on lines +112 to +117
else:
with st.spinner(
"πŸ“₯ Scraping channel and ingesting videos into Memori…"
):
count = ingest_channel_into_memori(channel_url_input.strip())
st.success(f"βœ… Ingested {count} video(s) into Memori.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security: User-supplied channel_url_input is passed directly to ingest_channel_into_memori without validation, allowing SSRF or command injection if the downstream function is vulnerable, leading to potential remote code execution or data exfiltration.

πŸ€– AI Agent Prompt for Cursor/Windsurf

πŸ“‹ Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In memory_agents/youtube_trend_agent/app.py, lines 112-117, the user-supplied channel_url_input is passed directly to ingest_channel_into_memori without validation, which could allow SSRF or command injection if the downstream function is vulnerable. Add a check to ensure the URL starts with 'https://www.youtube.com/' or 'https://youtube.com/' before calling the ingestion function, and show a warning if the URL is invalid.
πŸ“ Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
else:
with st.spinner(
"πŸ“₯ Scraping channel and ingesting videos into Memori…"
):
count = ingest_channel_into_memori(channel_url_input.strip())
st.success(f"βœ… Ingested {count} video(s) into Memori.")
else:
url = channel_url_input.strip()
if not (url.startswith("https://www.youtube.com/") or url.startswith("https://youtube.com/")):
st.warning("Invalid YouTube channel or playlist URL.")
else:
with st.spinner(
"πŸ“₯ Scraping channel and ingesting videos into Memori…"
):
count = ingest_channel_into_memori(url)
st.success(f"βœ… Ingested {count} video(s) into Memori.")

@Arindam200 Arindam200 merged commit aad69e8 into Arindam200:main Dec 21, 2025
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants