File size: 3,862 Bytes
8336a48
f8d7cd2
 
 
8336a48
f8d7cd2
8336a48
f8d7cd2
8336a48
 
f8d7cd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
---
title: Intern Problem Solver API
emoji: 🧠
colorFrom: blue
colorTo: indigo
sdk: docker
pinned: false
app_port: 7860
---

# Intern Problem-Solving API

A multi-agent FastAPI backend that helps interns understand real-world problems and build structured thinking. Five specialized agents run in sequence β€” each feeding context to the next β€” to deliver a complete analysis with actionable next steps.

## Agent Pipeline

```
Input β†’ [1] Problem Analyst β†’ [2] Root Cause β†’ [3] Solutions β†’ [4] Action Plan β†’ [5] Thinking Coach
```

| Agent | Job |
|-------|-----|
| Problem Analyst | Identifies core problem, stakeholders, known vs unknown |
| Root Cause Analyst | Breaks down WHY the problem exists across technical, process, and people dimensions |
| Solution Brainstorm | Generates 7 diverse ideas β€” quick wins, medium-term, strategic, and unconventional |
| Action Planner | 3 concrete next steps the intern can start immediately |
| Thinking Coach | Honest feedback on the intern's framing β€” are they a problem solver or task executor? |

---

## Endpoints

| Method | Endpoint | Returns |
|--------|----------|---------|
| `GET` | `/` | API info and endpoint list |
| `GET` | `/health` | Health check |
| `POST` | `/analyze` | Full analysis as JSON |
| `POST` | `/analyze/stream` | Server-sent events β€” streams each agent live |
| `POST` | `/analyze/pdf` | Downloadable PDF report |

---

## Request Body

All three `POST` endpoints accept the same JSON body:

```json
{
  "content": "Paste your problem, transcript, or blocker here",
  "intern_name": "Your Name",
  "intern_role": "AI Developer Intern",
  "intern_goal": "What you are trying to achieve this week"
}
```

| Field | Required | Default |
|-------|----------|---------|
| `content` | βœ… Yes | β€” |
| `intern_name` | No | `"Intern"` |
| `intern_role` | No | `"AI Developer Intern"` |
| `intern_goal` | No | `""` |

---

## Response β€” `/analyze`

```json
{
  "problem_statement": "## Core Problem\n...",
  "root_causes": "## Root Cause Analysis\n...",
  "solutions": "## Solution Ideas\n...",
  "action_plan": "## Your Next Steps\n...",
  "thinking_feedback": "## Thinking Feedback\n..."
}
```

---

## Response β€” `/analyze/stream`

Server-sent events. Each event is a JSON object on a `data:` line:

```
data: {"event": "agent_start", "agent": "analyst", "label": "Problem Analyst"}

data: {"event": "token", "agent": "analyst", "text": "## Core Problem\n"}

data: {"event": "agent_done", "agent": "analyst"}

data: {"event": "done"}
```

Event types:

| Event | Fields | Meaning |
|-------|--------|---------|
| `agent_start` | `agent`, `label` | Agent has started running |
| `token` | `agent`, `text` | Next streamed token from this agent |
| `agent_done` | `agent` | Agent finished |
| `done` | β€” | All 5 agents complete |

---

## Setup

### Environment Variable

Set this as a **Secret** in your HuggingFace Space settings:

```
ANTHROPIC_API_KEY=sk-ant-...
```

Do not put it in the Dockerfile or commit it to the repo.

### Files Required

```
main.py
requirements.txt
Dockerfile
README.md
```

---

## Local Development

```bash
# Install dependencies
pip install -r requirements.txt

# Run with your API key
ANTHROPIC_API_KEY=sk-ant-... uvicorn main:app --reload --port 7860
```

API docs available at `http://localhost:7860/docs` once running.

---

## Client

The frontend (`client.html`) is a standalone HTML file β€” no build step, no framework. Host it anywhere: a second HF Space (static SDK), GitHub Pages, or just open it locally in a browser.

Point the **Backend API URL** field in the client to this Space's URL:
```
https://your-username-intern-problem-solver.hf.space
```

---

## Stack

- **FastAPI** β€” API framework
- **Anthropic SDK** β€” claude-sonnet-4-6 for all agents
- **ReportLab** β€” PDF generation
- **Uvicorn** β€” ASGI server