Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -89,9 +89,9 @@ def decode_content(raw: str) -> str:
|
|
| 89 |
# ββ Request / Response Models βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 90 |
class ProblemInput(BaseModel):
|
| 91 |
content: str
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
|
| 96 |
|
| 97 |
class AgentOutput(BaseModel):
|
|
@@ -177,7 +177,7 @@ Max 300 words."""
|
|
| 177 |
|
| 178 |
|
| 179 |
AGENT_ACTION_PLANNER = """You are the Action Planner Agent.
|
| 180 |
-
You receive the full analysis. Your job: give the
|
| 181 |
|
| 182 |
Output format:
|
| 183 |
## Your Next Steps
|
|
@@ -200,11 +200,11 @@ Output format:
|
|
| 200 |
**Success looks like**: How you'll know it worked
|
| 201 |
**Time needed**: X hours
|
| 202 |
|
| 203 |
-
Be specific enough that the
|
| 204 |
|
| 205 |
|
| 206 |
AGENT_THINKING_COACH = """You are the Thinking Coach Agent.
|
| 207 |
-
You are an encouraging but honest coach helping
|
| 208 |
You receive the original problem input + full analysis.
|
| 209 |
|
| 210 |
Output format:
|
|
@@ -221,10 +221,10 @@ Output format:
|
|
| 221 |
One honest assessment with evidence from their input.
|
| 222 |
|
| 223 |
### One Big Shift
|
| 224 |
-
The single most important mindset or approach shift
|
| 225 |
|
| 226 |
-
### For
|
| 227 |
-
3 specific things to do differently next time
|
| 228 |
|
| 229 |
Keep it encouraging but honest. Max 250 words."""
|
| 230 |
|
|
@@ -248,9 +248,9 @@ def run_pipeline(content: str, name: str, role: str, goal: str) -> FullAnalysis:
|
|
| 248 |
"""Run all 5 agents in sequence, passing outputs forward."""
|
| 249 |
|
| 250 |
context_header = f"""
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
|
| 255 |
--- INPUT ---
|
| 256 |
{content[:8000]}
|
|
@@ -281,7 +281,7 @@ Current Goal: {goal if goal else 'Not specified'}
|
|
| 281 |
# Agent 4: Action Planner (receives everything so far)
|
| 282 |
action_plan = run_agent(
|
| 283 |
AGENT_ACTION_PLANNER,
|
| 284 |
-
f"""
|
| 285 |
|
| 286 |
Problem Statement:\n{problem_statement}
|
| 287 |
|
|
@@ -294,7 +294,7 @@ Solutions:\n{solutions}""",
|
|
| 294 |
# Agent 5: Thinking Coach (sees original input + full analysis)
|
| 295 |
thinking_feedback = run_agent(
|
| 296 |
AGENT_THINKING_COACH,
|
| 297 |
-
f"""Original Input
|
| 298 |
|
| 299 |
Problem Analysis:\n{problem_statement}
|
| 300 |
|
|
@@ -457,9 +457,9 @@ def analyze(body: ProblemInput):
|
|
| 457 |
try:
|
| 458 |
result = run_pipeline(
|
| 459 |
content=content,
|
| 460 |
-
name=body.
|
| 461 |
-
role=body.
|
| 462 |
-
goal=body.
|
| 463 |
)
|
| 464 |
return result
|
| 465 |
except anthropic.AuthenticationError:
|
|
@@ -490,9 +490,9 @@ def analyze_stream(body: ProblemInput):
|
|
| 490 |
|
| 491 |
context = {
|
| 492 |
"content": resolved_content[:8000],
|
| 493 |
-
"name": body.
|
| 494 |
-
"role": body.
|
| 495 |
-
"goal": body.
|
| 496 |
}
|
| 497 |
accumulated = {}
|
| 498 |
|
|
@@ -502,7 +502,7 @@ def analyze_stream(body: ProblemInput):
|
|
| 502 |
|
| 503 |
# Build context-aware prompt for this agent
|
| 504 |
if key == "analyst":
|
| 505 |
-
user_msg = f"
|
| 506 |
elif key == "root_cause":
|
| 507 |
user_msg = f"Problem:\n{accumulated.get('analyst','')}\n\nOriginal:\n{context['content'][:2000]}"
|
| 508 |
elif key == "solutions":
|
|
@@ -556,8 +556,8 @@ def analyze_pdf(body: ProblemInput):
|
|
| 556 |
)
|
| 557 |
pdf_bytes = build_pdf(
|
| 558 |
analysis,
|
| 559 |
-
name=body.
|
| 560 |
-
role=body.
|
| 561 |
)
|
| 562 |
filename = f"problem_analysis_{datetime.now().strftime('%Y%m%d_%H%M%S')}.pdf"
|
| 563 |
return StreamingResponse(
|
|
|
|
| 89 |
# ββ Request / Response Models βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 90 |
class ProblemInput(BaseModel):
|
| 91 |
content: str
|
| 92 |
+
user_name: Optional[str] = "Anonymous"
|
| 93 |
+
user_role: Optional[str] = ""
|
| 94 |
+
user_goal: Optional[str] = ""
|
| 95 |
|
| 96 |
|
| 97 |
class AgentOutput(BaseModel):
|
|
|
|
| 177 |
|
| 178 |
|
| 179 |
AGENT_ACTION_PLANNER = """You are the Action Planner Agent.
|
| 180 |
+
You receive the full analysis. Your job: give the person 3 concrete next actions.
|
| 181 |
|
| 182 |
Output format:
|
| 183 |
## Your Next Steps
|
|
|
|
| 200 |
**Success looks like**: How you'll know it worked
|
| 201 |
**Time needed**: X hours
|
| 202 |
|
| 203 |
+
Be specific enough that the person can start immediately. No vague advice."""
|
| 204 |
|
| 205 |
|
| 206 |
AGENT_THINKING_COACH = """You are the Thinking Coach Agent.
|
| 207 |
+
You are an encouraging but honest coach helping the person think more clearly.
|
| 208 |
You receive the original problem input + full analysis.
|
| 209 |
|
| 210 |
Output format:
|
|
|
|
| 221 |
One honest assessment with evidence from their input.
|
| 222 |
|
| 223 |
### One Big Shift
|
| 224 |
+
The single most important mindset or approach shift for this person.
|
| 225 |
|
| 226 |
+
### For Next Time
|
| 227 |
+
3 specific things to do differently next time this type of problem comes up.
|
| 228 |
|
| 229 |
Keep it encouraging but honest. Max 250 words."""
|
| 230 |
|
|
|
|
| 248 |
"""Run all 5 agents in sequence, passing outputs forward."""
|
| 249 |
|
| 250 |
context_header = f"""
|
| 251 |
+
Name: {name}
|
| 252 |
+
Role: {role if role else "Not specified"}
|
| 253 |
+
Goal: {goal if goal else "Not specified"}
|
| 254 |
|
| 255 |
--- INPUT ---
|
| 256 |
{content[:8000]}
|
|
|
|
| 281 |
# Agent 4: Action Planner (receives everything so far)
|
| 282 |
action_plan = run_agent(
|
| 283 |
AGENT_ACTION_PLANNER,
|
| 284 |
+
f"""Role: {role}\nGoal: {goal}
|
| 285 |
|
| 286 |
Problem Statement:\n{problem_statement}
|
| 287 |
|
|
|
|
| 294 |
# Agent 5: Thinking Coach (sees original input + full analysis)
|
| 295 |
thinking_feedback = run_agent(
|
| 296 |
AGENT_THINKING_COACH,
|
| 297 |
+
f"""Original Input:\n{content[:3000]}
|
| 298 |
|
| 299 |
Problem Analysis:\n{problem_statement}
|
| 300 |
|
|
|
|
| 457 |
try:
|
| 458 |
result = run_pipeline(
|
| 459 |
content=content,
|
| 460 |
+
name=body.user_name or "Anonymous",
|
| 461 |
+
role=body.user_role or "",
|
| 462 |
+
goal=body.user_goal or "",
|
| 463 |
)
|
| 464 |
return result
|
| 465 |
except anthropic.AuthenticationError:
|
|
|
|
| 490 |
|
| 491 |
context = {
|
| 492 |
"content": resolved_content[:8000],
|
| 493 |
+
"name": body.user_name or "Anonymous",
|
| 494 |
+
"role": body.user_role or "",
|
| 495 |
+
"goal": body.user_goal or "",
|
| 496 |
}
|
| 497 |
accumulated = {}
|
| 498 |
|
|
|
|
| 502 |
|
| 503 |
# Build context-aware prompt for this agent
|
| 504 |
if key == "analyst":
|
| 505 |
+
user_msg = f"Name: {context['name']} | Role: {context['role']} | Goal: {context['goal']}\n\nAnalyze this content:\n{context['content']}"
|
| 506 |
elif key == "root_cause":
|
| 507 |
user_msg = f"Problem:\n{accumulated.get('analyst','')}\n\nOriginal:\n{context['content'][:2000]}"
|
| 508 |
elif key == "solutions":
|
|
|
|
| 556 |
)
|
| 557 |
pdf_bytes = build_pdf(
|
| 558 |
analysis,
|
| 559 |
+
name=body.user_name or "Anonymous",
|
| 560 |
+
role=body.user_role or "",
|
| 561 |
)
|
| 562 |
filename = f"problem_analysis_{datetime.now().strftime('%Y%m%d_%H%M%S')}.pdf"
|
| 563 |
return StreamingResponse(
|