What You’ll Build
- A FastAPI service that wraps an Agno agent with Product Hunt tools.
- Tooling for Algolia search, GraphQL leaderboards, natural timeframe parsing, and confetti payloads.
/api/chatand/streamendpoints that share CometChat-compatible newline-delimited JSON payloads.- Optional Product Hunt GraphQL integration (falls back gracefully when no token is provided).
Prerequisites
- Python 3.10 or newer.
OPENAI_API_KEYwith GPT-4o (or similar) access.- Optional
PRODUCTHUNT_API_TOKENfor live leaderboard queries. - curl or an API client to verify endpoints.
Quick links
- Repo root: ai-agent-agno-examples
- Project folder:
product_hunt_agent/ - Server entrypoint:
product_hunt_agent/main.py - Agent builder:
product_hunt_agent/agent_builder.py - Services & queries:
product_hunt_agent/services.py
How it works
- Agent —
create_product_hunt_agentconfigures anOpenAIChatmodel, system prompt, and five tools (getTopProducts,getTopProductsThisWeek,getTopProductsByTimeframe,searchProducts,triggerConfetti). - Data —
services.pywraps Product Hunt’s GraphQL API (with token), Algolia search, timezone-aware timeframe parsing, and safe fallbacks when the API token is missing. - API — FastAPI routes in
main.pyexpose REST endpoints for ranked lists and search, plus/api/chatand/streamfor conversations and newline-delimited event streaming. - Parity — The streaming payload mirrors CometChat’s Bring Your Own Agent format (
text_delta,tool_*,text_done,done,error), so existing UI logic can be reused.
Setup
1
Clone & install
From your workspace:
git clone https://github.com/cometchat/ai-agent-agno-examples.git. Inside the repo: python3 -m venv .venv && source .venv/bin/activate && pip install -e .2
Configure environment
Create
.env with OPENAI_API_KEY. Add PRODUCTHUNT_API_TOKEN for GraphQL access. Optional knobs: PRODUCTHUNT_DEFAULT_TIMEZONE, OPENAI_BASE_URL, PRODUCT_OPENAI_MODEL.3
Run the server
Start FastAPI:
uvicorn product_hunt_agent.main:app —host 0.0.0.0 —port 8001 —reload. Health check: GET /healthz; streaming lives at POST /stream.Project Structure
- FastAPI routes & schemas
- Agent behavior
- Product Hunt services
Step 1 - Configure Settings
ProductHuntSettings centralizes configuration (API keys, timeouts, default timezone). The FastAPI app loads it once and injects it via Depends, so each route reuses the same validated settings.
Step 2 - Understand the Agent Tools
agent_builder.py clamps incoming arguments, calls service helpers, and returns structured dictionaries the UI can render. Highlights:
getTopProducts— All-time votes.getTopProductsThisWeek— Rolling window controlled bydays.getTopProductsByTimeframe— Natural language inputs such asyesterday,last-week, or ISO dates.searchProducts— Uses Product Hunt’s public Algolia index (no token required).triggerConfetti— Returns payloads that UI Kit Builder variants can pass to your frontend celebration handler.
Step 3 - Product Hunt Data Services
services.py wraps the external APIs with resilient defaults:
parse_timeframetranslates natural strings into UTC ranges usingpendulum.fetch_graphqlonly runs whenPRODUCTHUNT_API_TOKENis present; otherwise, helper functions return empty lists so the agent can respond gracefully.search_productshits the public Algolia index (Post_production) with rate-limit friendly defaults.
Step 4 - Test the API
List top launches from the past week:type (e.g., text_delta, tool_call_start, tool_result, text_done, done) plus the echoed thread_id and run_id.
Step 5 - Connect to CometChat
- Deploy the service behind HTTPS and protect it with auth headers (use the agent’s Headers field when registering in CometChat).
- Point the Agno agent variant at your
/streamendpoint; reuse the same Agent ID from UI Kit Builder. - When the agent triggers
triggerConfetti, listen for the tool event in your frontend to launch celebratory animations. - Echo
thread_idandrun_idin every streamed line so CometChat can correlate partial tool events and message chunks.