Skip to content

A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.

audit: fix competitive_intelligence_agent - fix load_dotenv bug, ANSI codes, clean reasoning log, collapse reasoning panel, add demo, fix pyproject description, fix README checkboxes

Tiioluwaniaf176efc3040
diff --git a/ai_agents/competitive_intelligence_agent/.env.example b/ai_agents/competitive_intelligence_agent/.env.example
index 61a33ac..3ddf94a 100644
--- a/ai_agents/competitive_intelligence_agent/.env.example
+++ b/ai_agents/competitive_intelligence_agent/.env.example
@@ -1,2 +1,4 @@
+# Google AI Studio API key used to access Gemma 4 via the Gemini API. Get yours free at https://aistudio.google.com
GEMINI_API_KEY=your_gemini_api_key_here
+# Tavily Search API key used for real-time web research by the CrewAI agents. Get yours free at https://tavily.com
TAVILY_API_KEY=tvly-your_tavily_key_here
\ No newline at end of file
diff --git a/ai_agents/competitive_intelligence_agent/README.md b/ai_agents/competitive_intelligence_agent/README.md
index b42974d..3b9c89a 100644
--- a/ai_agents/competitive_intelligence_agent/README.md
+++ b/ai_agents/competitive_intelligence_agent/README.md
@@ -1,12 +1,18 @@
# Competitive Intelligence Agent
+> Generate strategic sales battlecards by analyzing competitors through the unique lens of your own business context.
+
A multi-agent AI system that generates strategic sales battlecards by analyzing competitors through the unique lens of your own business context.
+## Demo
+
+![Demo](assets/demo.png)
+
## Overview
The **Competitive Intelligence Agent** solves the "generic research" problem by moving away from broad, impersonal reports. Instead of searching the web for everything about a competitor, this system uses specialized AI agents to analyze a competitor specifically in relation to *your* company's value proposition, your customers' specific pain points, and your strategic sales goals.
-It uses **CrewAI** to orchestrate specialized agents—a Market Scout, a Product Strategist, and a Battlecard Author—to research, compare, and synthesize actionable sales intelligence.
+It uses **CrewAI** to orchestrate three specialized agents that research, compare, and synthesize actionable sales intelligence: a Market Scout, a Product Strategist, and a Battlecard Author.
This tool is designed for:
- **Sales Teams:** Who need immediate, punchy arguments to win against specific competitors.
@@ -40,8 +46,8 @@ Before you begin, ensure you have:
- Python 3.12 or higher
- [uv](https://github.com/astral-sh/uv) (Recommended for dependency management)
- API keys for:
- - [ ] Google AI Studio (for Gemini/Gemma)
- - [ ] Tavily Search API
+ - [Google AI Studio](https://aistudio.google.com) for Gemini/Gemma (free tier available)
+ - [Tavily Search API](https://tavily.com) (free tier available)
## Installation
@@ -95,6 +101,8 @@ competitive_intelligence_agent/
├── .env.example # Template for API keys
├── pyproject.toml # uv project configuration
├── uv.lock # Locked dependencies for consistency
+├── assets/
+│ └── demo.png # Demo screenshot
└── .venv/ # Virtual environment (auto-generated)
```
diff --git a/ai_agents/competitive_intelligence_agent/agents_logic.py b/ai_agents/competitive_intelligence_agent/agents_logic.py
index 879e551..e6beb79 100644
--- a/ai_agents/competitive_intelligence_agent/agents_logic.py
+++ b/ai_agents/competitive_intelligence_agent/agents_logic.py
@@ -1,7 +1,11 @@
+"""CrewAI agent and task definitions for the Competitive Intelligence Agent."""
import os
+from dotenv import load_dotenv
from crewai import Agent, Task, Crew, Process, LLM
from crewai_tools import TavilySearchTool
+load_dotenv()
+
# Gemma 4 via LiteLLM/Gemini API
gemma_llm = LLM(
model="gemini/gemma-4-26b-a4b-it",
@@ -9,6 +13,7 @@ gemma_llm = LLM(
)
def get_research_crew(my_company, competitor, pain_point, goal):
+ """Build and return a sequential CrewAI crew configured for the given company context and competitor."""
# Specialized Tools
search_tool = TavilySearchTool(api_key=os.getenv("TAVILY_API_KEY"), max_results=3)
diff --git a/ai_agents/competitive_intelligence_agent/assets/demo.png b/ai_agents/competitive_intelligence_agent/assets/demo.png
new file mode 100644
index 0000000..7c4a2be
Binary files /dev/null and b/ai_agents/competitive_intelligence_agent/assets/demo.png differ
diff --git a/ai_agents/competitive_intelligence_agent/main.py b/ai_agents/competitive_intelligence_agent/main.py
index 8852d41..6f543e7 100644
--- a/ai_agents/competitive_intelligence_agent/main.py
+++ b/ai_agents/competitive_intelligence_agent/main.py
@@ -1,25 +1,44 @@
+"""Gradio UI for the Competitive Intelligence Agent, which generates AI-powered sales battlecards using a CrewAI multi-agent pipeline."""
+import re
import gradio as gr
import io
from contextlib import redirect_stdout
from agents_logic import get_research_crew
+
+def strip_ansi(text: str) -> str:
+ """Remove ANSI color and formatting escape sequences from a string."""
+ return re.sub(r'\x1b\[[0-9;]*m', '', text)
+
+
+def clean_log(raw: str) -> str:
+ """Remove blank lines and decorative separator lines from captured CrewAI stdout."""
+ kept = []
+ for line in raw.splitlines():
+ stripped = line.strip()
+ if stripped and re.search(r'[A-Za-z0-9]', stripped):
+ kept.append(stripped)
+ return '\n'.join(kept)
+
+
def run_analysis(my_company, competitor, pain_point, goal):
+ """Run the three-agent CrewAI pipeline and return the reasoning log and final battlecard."""
# Progress logging
f = io.StringIO()
with redirect_stdout(f):
try:
crew = get_research_crew(my_company, competitor, pain_point, goal)
result = crew.kickoff(inputs={
- "my_company": my_company,
- "competitor": competitor,
- "pain_point": pain_point,
+ "my_company": my_company,
+ "competitor": competitor,
+ "pain_point": pain_point,
"goal": goal
})
final_output = result.raw
except Exception as e:
final_output = f"Error: {str(e)}"
-
- return f.getvalue(), final_output
+
+ return clean_log(strip_ansi(f.getvalue())), final_output
with gr.Blocks(title="Strategic Intel System") as demo:
gr.Markdown("# ⚔️ Competitive Intelligence Engine")
@@ -34,7 +53,8 @@ with gr.Blocks(title="Strategic Intel System") as demo:
submit_btn = gr.Button("Generate Battlecard", variant="primary")
with gr.Column():
- logs = gr.Textbox(label="Agent Reasoning Process", lines=10)
+ with gr.Accordion("Agent Reasoning Process", open=False):
+ logs = gr.Textbox(label="Agent Reasoning Process", lines=10)
output = gr.Markdown(label="Final Battlecard")
submit_btn.click(
diff --git a/ai_agents/competitive_intelligence_agent/pyproject.toml b/ai_agents/competitive_intelligence_agent/pyproject.toml
index 9c81729..5850245 100644
--- a/ai_agents/competitive_intelligence_agent/pyproject.toml
+++ b/ai_agents/competitive_intelligence_agent/pyproject.toml
@@ -1,7 +1,7 @@
[project]
name = "competitive-intelligence-agent"
version = "0.1.0"
-description = "Add your description here"
+description = "Multi-agent CrewAI system that generates strategic sales battlecards by analyzing competitors against your own business context"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [