Update README.md
Browse files
README.md
CHANGED
|
@@ -12,9 +12,131 @@ short_description: Educational Agent
|
|
| 12 |
license: cc
|
| 13 |
---
|
| 14 |
|
| 15 |
-
#
|
| 16 |
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
license: cc
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# π EduAgent β Educational AI Agent
|
| 16 |
|
| 17 |
+
A minimal but complete **agentic AI tutor** built with Groq + Streamlit.
|
| 18 |
+
Demonstrates: tool calling, multi-step agent loops, multi-turn memory, and clean UI.
|
| 19 |
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
## What it does
|
| 23 |
+
|
| 24 |
+
| Tool | Triggered when you ask⦠|
|
| 25 |
+
|------|--------------------------|
|
| 26 |
+
| `explain_concept` | "What is X?", "Explain Y for a beginner" |
|
| 27 |
+
| `generate_quiz` | "Quiz me on Z", "Give me 3 questions aboutβ¦" |
|
| 28 |
+
| `solve_problem` | "Solve:", "Calculate:", "Find the derivativeβ¦" |
|
| 29 |
+
| `create_study_plan` | "Make a study plan forβ¦", "How to learn X in 4 weeks" |
|
| 30 |
+
|
| 31 |
+
You can chain them: *"Explain recursion, then quiz me on it"* calls two tools in one turn.
|
| 32 |
+
|
| 33 |
+
---
|
| 34 |
+
|
| 35 |
+
## Groq API β why Groq?
|
| 36 |
+
|
| 37 |
+
- **Free tier** at [console.groq.com](https://console.groq.com) β no credit card needed
|
| 38 |
+
- Extremely fast inference (useful for agentic loops with multiple LLM calls)
|
| 39 |
+
- Supports Llama 3.3 70B, Gemma 2, Mixtral, and more
|
| 40 |
+
|
| 41 |
+
Get your key: **console.groq.com β API Keys β Create**
|
| 42 |
+
|
| 43 |
+
---
|
| 44 |
+
|
| 45 |
+
## π Platform setup
|
| 46 |
+
|
| 47 |
+
### Streamlit Cloud (recommended)
|
| 48 |
+
1. Fork / push this repo to GitHub
|
| 49 |
+
2. Go to [share.streamlit.io](https://share.streamlit.io) β New app
|
| 50 |
+
3. Set **main file** to `app.py`
|
| 51 |
+
4. Under **Secrets**, add:
|
| 52 |
+
```toml
|
| 53 |
+
GROQ_API_KEY = "gsk_your_key_here"
|
| 54 |
+
```
|
| 55 |
+
5. Deploy β
|
| 56 |
+
|
| 57 |
+
### Hugging Face Spaces
|
| 58 |
+
1. Create a new Space β SDK: **Streamlit**
|
| 59 |
+
2. Upload `app.py` and `requirements.txt`
|
| 60 |
+
3. Go to **Settings β Repository secrets** β Add `GROQ_API_KEY`
|
| 61 |
+
4. The app reads `st.secrets["GROQ_API_KEY"]` automatically β
|
| 62 |
+
|
| 63 |
+
### Kaggle Notebook
|
| 64 |
+
```python
|
| 65 |
+
# Cell 1 β install
|
| 66 |
+
!pip install streamlit groq pyngrok -q
|
| 67 |
+
|
| 68 |
+
# Cell 2 β set key (use Kaggle Secrets: Add-ons β Secrets)
|
| 69 |
+
import os
|
| 70 |
+
from kaggle_secrets import UserSecretsClient
|
| 71 |
+
os.environ["GROQ_API_KEY"] = UserSecretsClient().get_secret("GROQ_API_KEY")
|
| 72 |
+
|
| 73 |
+
# Cell 3 β run with tunnel
|
| 74 |
+
from pyngrok import ngrok
|
| 75 |
+
ngrok.set_auth_token("YOUR_NGROK_TOKEN") # free at ngrok.com
|
| 76 |
+
public_url = ngrok.connect(8501)
|
| 77 |
+
print("App URL:", public_url)
|
| 78 |
+
!streamlit run app.py --server.port 8501 --server.headless true
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
### Local
|
| 82 |
+
```bash
|
| 83 |
+
pip install -r requirements.txt
|
| 84 |
+
export GROQ_API_KEY="gsk_..." # or set in .env
|
| 85 |
+
streamlit run app.py
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
+
|
| 90 |
+
## Architecture
|
| 91 |
+
|
| 92 |
+
```
|
| 93 |
+
User input
|
| 94 |
+
β
|
| 95 |
+
βΌ
|
| 96 |
+
βββββββββββββββββββββββββββββββββββ
|
| 97 |
+
β System prompt + chat history β
|
| 98 |
+
β + TOOLS schema (4 tools) β
|
| 99 |
+
ββββββββββββββββ¬βββββββββββββββββββ
|
| 100 |
+
β
|
| 101 |
+
βΌ
|
| 102 |
+
Groq LLM call
|
| 103 |
+
β
|
| 104 |
+
βββββββββ΄βββββββββ
|
| 105 |
+
β tool_calls? β No β final answer
|
| 106 |
+
β Yes β
|
| 107 |
+
βΌ β
|
| 108 |
+
execute_tool() β
|
| 109 |
+
(second LLM call β
|
| 110 |
+
with focused prompt) β
|
| 111 |
+
β β
|
| 112 |
+
ββββΊ feed result back to LLM
|
| 113 |
+
(loop up to 5 iterations)
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
---
|
| 117 |
+
|
| 118 |
+
## Extending the agent
|
| 119 |
+
|
| 120 |
+
**Add a real calculator tool** (no LLM needed):
|
| 121 |
+
```python
|
| 122 |
+
# In execute_tool(), add:
|
| 123 |
+
if tool_name == "calculate":
|
| 124 |
+
import math
|
| 125 |
+
return str(eval(tool_args["expression"])) # use safer eval in prod
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
**Add web search** (using DuckDuckGo, free):
|
| 129 |
+
```python
|
| 130 |
+
from duckduckgo_search import DDGS
|
| 131 |
+
def web_search(query):
|
| 132 |
+
with DDGS() as ddgs:
|
| 133 |
+
return "\n".join(r["body"] for r in ddgs.text(query, max_results=3))
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
**Swap Groq for OpenAI-compatible APIs** (same code, change base_url):
|
| 137 |
+
```python
|
| 138 |
+
client = Groq(api_key=key) # Groq (default)
|
| 139 |
+
# client = OpenAI(api_key=key) # OpenAI
|
| 140 |
+
# client = OpenAI(api_key=key, # Together.ai / any OpenAI-compatible
|
| 141 |
+
# base_url="https://api.together.xyz/v1")
|
| 142 |
+
```
|