{"id":50928343,"url":"https://github.com/persteenolsen/fastapi-jwt-auth-ai-agent-one","last_synced_at":"2026-06-17T01:31:08.360Z","repository":{"id":363374803,"uuid":"1261784068","full_name":"persteenolsen/fastapi-jwt-auth-ai-agent-one","owner":"persteenolsen","description":"Python FastAPI with JWT Auth serving a LangChain ReAct AI Agent running at Vercel","archived":false,"fork":false,"pushed_at":"2026-06-08T16:26:02.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-08T17:30:04.220Z","etag":null,"topics":["ai","ai-agent","fastapi","jwt","langchain","python"],"latest_commit_sha":null,"homepage":"https://fastapi-jwt-auth-ai-agent-one.vercel.app/docs","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/persteenolsen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-07T06:26:34.000Z","updated_at":"2026-06-08T16:26:09.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/persteenolsen/fastapi-jwt-auth-ai-agent-one","commit_stats":null,"previous_names":["persteenolsen/fastapi-jwt-auth-ai-agent-one"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/persteenolsen/fastapi-jwt-auth-ai-agent-one","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-ai-agent-one","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-ai-agent-one/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-ai-agent-one/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-ai-agent-one/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/persteenolsen","download_url":"https://codeload.github.com/persteenolsen/fastapi-jwt-auth-ai-agent-one/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Ffastapi-jwt-auth-ai-agent-one/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34430688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","ai-agent","fastapi","jwt","langchain","python"],"created_at":"2026-06-17T01:31:06.711Z","updated_at":"2026-06-17T01:31:08.345Z","avatar_url":"https://github.com/persteenolsen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🚀 FastAPI with JWT Auth serving a LangChain ReAct AI Agent\n \nA production-style AI Agent API built with **FastAPI**, featuring **JWT authentication**, **Groq-powered LLMs**, and a **LangChain ReAct agent** with tool usage (Wikipedia).\n\nThis project demonstrates how to build a tool-using AI system that can:\n- 🧠 Reason about user intent\n- 🌐 Use external tools when needed\n- 💬 Respond directly for conversational and creative tasks\n\n---\n\n## 📌 Project Info\n\n- 📦 Version: 0.0.2\n- 🐍 Python: 3.12\n- 📅 Last Updated: 10-06-2026\n\n---\n\n## ✨ Features\n\n### 🔐 Authentication (JWT)\n- Secure login system using JWT (HS256)\n- Protected endpoints with Bearer token\n- Token expiration support\n- Environment-based credentials (.env)\n\n---\n\n### 🤖 AI Agent (LangChain ReAct)\n\n- 🧠 Reasoning + Acting loop (ReAct pattern)\n- 🔁 Multi-step decision making\n- 🎯 Smart tool selection (Wikipedia only when needed)\n- 🛑 Controlled iterations (prevents infinite loops)\n- 🧯 Parsing error handling for stability\n\n---\n\n### 🧠 LLM Integration (Groq)\n\n- ⚡ Model: `llama-3.3-70b-versatile`\n- 🚀 Ultra-fast inference via Groq API\n- 🎛️ Deterministic outputs (`temperature = 0`)\n\n---\n\n### 🌐 Wikipedia Tool\n\n- 📚 Wikipedia API integration via custom wrapper\n- 🔎 Factual knowledge retrieval\n- 🔁 Retry support for transient API failures\n- 🧯 Graceful fallback on errors\n- 🧠 Used only for factual queries\n\n---\n\n### 🧩 Agent Capabilities\n\n- ❓ General question answering\n- 📚 Factual lookup (Wikipedia)\n- 💬 Conversational chat\n- 😂 Joke generation\n- ✍️ Creative writing (poems, stories)\n- 🧠 Tool-augmented reasoning\n\n---\n\n## 📡 API Endpoints\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| 🔐 POST | `/login` | Get JWT token |\n| 💬 POST | `/chat` | Chat with AI agent (protected) |\n| ❤️ GET | `/health` | Service health check |\n| 🧠 GET | `/test-groq` | Test LLM connection |\n| 🌐 GET | `/test-wikipedia` | Test Wikipedia tool |\n\n---\n\n## ⚙️ Getting Started\n\n### 1️⃣ Clone Repository\n\nClone the project from GitHub and enter the project directory.\n\n---\n\n### 2️⃣ Create Virtual Environment\n\nWindows:\nvenv\\Scripts\\activate\n\nLinux / macOS:\nsource venv/bin/activate\n\n---\n\n### 3️⃣ Install Dependencies\n\npip install -r requirements.txt\n\n---\n\n## 🔑 Environment Variables\n\nCreate a `.env` file:\n\nSECRET_KEY=your_secret_key_here\nGROQ_API_KEY=your_groq_api_key\nFAKE_USERNAME=admin\nFAKE_PASSWORD=password\n\nGenerate a secure key:\n\npython -c \"import secrets; print(secrets.token_hex(32))\"\n\n---\n\n## ▶️ Run the Application\n\nuvicorn main:app --reload\n\nApp:\nhttp://127.0.0.1:8000\n\nDocs:\nhttp://127.0.0.1:8000/docs\n\n---\n\n## 🔐 Authentication Flow\n\n1. Call `/login`\n2. Receive JWT token\n3. Use token in requests:\n\nAuthorization: Bearer YOUR_TOKEN\n\n---\n\n## 🧠 How the Agent Works\n\nUser Input\n↓\nAgent Reasoning\n↓\nWikipedia Tool (if needed)\n↓\nDirect Response (jokes, chat, creative writing)\n↓\nFinal Answer\n\n---\n\n## 🏗️ Architecture\n\nLLM:\nGroq - llama-3.3-70b-versatile\n\nAgent:\nLangChain ReAct Agent\n\nTools:\nWikipedia API\n\nExecution Settings:\nMax iterations: 2\nParsing error handling enabled\nVerbose logging enabled\n\n---\n\n## 💬 Example Requests\n\n### 😂 Joke Request\n\n{\n  \"message\": \"Tell me a joke\"\n}\n\nResponse:\n\n{\n  \"response\": \"Here's one: Why couldn't the bicycle stand up by itself? Because it was two-tired.\"\n}\n\n---\n\n### 📚 Factual Question\n\n{\n  \"message\": \"What is the capital of France?\"\n}\n\nResponse:\n\n{\n  \"response\": \"Paris\"\n}\n\n---\n\n### ✍️ Creative Request\n\n{\n  \"message\": \"Write a short poem\"\n}\n\nResponse:\n\n{\n  \"response\": \"The sun sets slow and paints the sky...\"\n}\n\n---\n\n### 🌐 Wikipedia Tool Usage\n\n{\n  \"message\": \"Who is Albert Einstein?\"\n}\n\nResponse:\n\n{\n  \"response\": \"Albert Einstein was a theoretical physicist known for the theory of relativity.\"\n}\n\n---\n\n## 📌 Use Cases\n\n- 🤖 AI assistants\n- 🎓 Educational tools\n- 🧪 LangChain experimentation\n- 🧠 Tool-augmented LLM systems\n- ⚡ FastAPI backend AI services\n\n---\n\n## 🚧 Limitations\n\n- 📚 Only Wikipedia as external tool\n- 🧠 No long-term memory\n- 🔐 Demo authentication system\n- 🌐 Limited external knowledge sources\n\n---\n\n## 🚀 Future Improvements\n\n- 🧠 Conversation memory\n- 🔌 More tools (search, APIs, DB integration)\n- 👥 Multi-user system\n- 🔄 Token refresh system\n- 🧩 Modular tool registry\n- 📊 Analytics dashboard\n\n---\n\n## 📄 License\n\nMIT License\n\n---\n\n## 🙌 Summary\n\nThis project combines:\n\n⚡ FastAPI  \n🔐 JWT Authentication  \n🧠 Groq LLM (Llama 3.3 70B)  \n🤖 LangChain ReAct Agent  \n🌐 Wikipedia Tool  \n\nto build a **working tool-augmented AI system** that can reason, act, and respond intelligently depending on user intent.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpersteenolsen%2Ffastapi-jwt-auth-ai-agent-one","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpersteenolsen%2Ffastapi-jwt-auth-ai-agent-one","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpersteenolsen%2Ffastapi-jwt-auth-ai-agent-one/lists"}