How aayush-puri-01/content-optimization-agent works
Project Type and Purpose
• This is a backend API service (built on FastAPI) that orchestrates an intelligent “agent” to generate campaign content (hashtags, scripts, audio) by chaining multiple specialized tools and LLM calls.
• Its primary role is dynamic workflow orchestration: taking user prompts, decomposing them, invoking tool‐agents, and returning a formatted campaign.
File Structure
• Top‐level:
• Dockerfile/.dockerignore: containerization
• pyproject.toml / uv.lock: dependencies via uv package manager
• tests/, utils/: support code
• agentic_system/:
• main.py & app.py: FastAPI application entrypoint
• agent.py: glue Logic for orchestrating flows
• configs/: LLM and logging settings
• routes/agent_router.py: HTTP API endpoint for queries
• schemas/: Pydantic models for requests, agent state, workflow steps
• prompts/: prompt templates for LLM calls
• services/: each file is a tool‐agent (llm_node.py, trend_tool.py, search_tool.py, hashtag_gen.py, script_tool.py, tts_tool.py)
Extract Architectural Insights from README
• Central “LLM Router Node” (llm_node.py) as orchestrator
• Independent tool‐agents for trend analysis, web search, hashtag/script generation, TTS
• External dependencies: OpenAI GPT-4o-mini, SerpAPI, Tavily Search, PyTrends, Google Gemini TTS
a. Main Components
• Client (curl, UI, or SDK)
• FastAPI Server (main.py ➔ app.py ➔ agent_router)
• LLM Router Node (llm_node.py)
• Tool Agents (trend_tool, search_tool, hashtag_gen, script_tool, tts_tool)
• External Services (SerpAPI, Tavily Search API, PyTrends, OpenAI, Google Gemini TTS)
• Configuration Module (llm_config, logging_config)
b. Relationships & Interactions
1. Client sends POST /agent/query to FastAPI
2. agent_router receives request, validates via Pydantic schemas
3. Route invokes agent.py which calls LLM Router Node
4. LLM Router extracts campaign parameters, dynamically plans steps
5. For each step, LLM Router calls the appropriate Tool Agent
• Trend Analyzer ↔ PyTrends / SerpAPI
• Search Engine ↔ Tavily Search
• Hashtag Generator ↔ OpenAI LLM
• Script Generator ↔ OpenAI LLM
• TTS Generator ↔ Google Gemini TTS
6. Tool Agents return structured data to LLM Router
7. Once workflow completes, LLM Router formats final output
8. FastAPI returns JSON response to client
c. Architectural Patterns & Principles
• Orchestrator / Workflow Engine pattern (LLM Router)
• Tool‐oriented microservice modules (loosely coupled)
• Function‐calling / plugin pattern via OpenAI
• Configuration—code separation (configs/ folder)
• Schema validation (Pydantic)
d. Key Technologies & Libraries
• FastAPI for HTTP server and routing
• LangGraph / LangChain for orchestrating LLM workflows
• OpenAI GPT-4o-mini LLM for planning & content generation
• SerpAPI, PyTrends, Tavily Search, Google Gemini TTS as external data sources
• Pydantic for request/response schemas
Every Essential Element
• Tests/ and utils/ off to the side as “Support Modules”
• Steps in the workflow with numbered labels to show dynamic planning