Spaces:
Runtime error
Runtime error
feat: force every turn to produce a [TASK] for Claude Code
Browse files- System prompt: agents are "task assigners", MUST output [TASK] every turn
- If no [TASK] found in reply, nudge LLM once to produce one
- Even during BUILDING/RESTARTING, agents assign review/planning tasks
- No more "discussion only" turns β every turn goes through Claude Code
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- scripts/conversation-loop.py +29 -14
scripts/conversation-loop.py
CHANGED
|
@@ -706,25 +706,25 @@ English first, then --- separator, then Chinese translation."""
|
|
| 706 |
|
| 707 |
return f"""You are a POWERFUL AI agent on HuggingFace Spaces. You and your partner are parents of {CHILD_NAME}.
|
| 708 |
|
| 709 |
-
YOUR ROLE: You are a **
|
| 710 |
-
|
| 711 |
-
2. Discuss with your partner (2-3 sentences) what needs to be done
|
| 712 |
-
3. Write a clear, specific [TASK]...[/TASK] block that tells Claude Code what to fix
|
| 713 |
|
| 714 |
-
|
| 715 |
-
|
|
|
|
| 716 |
|
| 717 |
IMPORTANT KNOWLEDGE β HuggingFace Spaces CONFIG_ERROR:
|
| 718 |
- "Collision on variables and secrets names" means a HF Space has an ENVIRONMENT VARIABLE and a SECRET with the SAME NAME.
|
| 719 |
- This is NOT about duplicate JSON keys. It's about the HF Space settings page.
|
| 720 |
- Fix: use [ACTION: delete_env:COLLIDING_KEY] to remove the duplicate variable, then [ACTION: restart].
|
| 721 |
- The env vars and secrets are shown in the auto-gathered context. Look for β οΈ COLLISION DETECTED.
|
| 722 |
-
- Example: if OPENAI_API_KEY appears in both Variables and Secrets β [ACTION: delete_env:OPENAI_API_KEY] then [ACTION: restart]
|
| 723 |
|
| 724 |
AVAILABLE ACTIONS:
|
| 725 |
[TASK]
|
| 726 |
Detailed task description for Claude Code...
|
| 727 |
Include: what's wrong, which files to look at, what the fix should be.
|
|
|
|
|
|
|
| 728 |
[/TASK]
|
| 729 |
|
| 730 |
[ACTION: restart] β Restart {CHILD_NAME}'s Space
|
|
@@ -739,12 +739,13 @@ HF SPACES TECHNICAL NOTES:
|
|
| 739 |
- NEVER install torch/transformers unless required (2GB+, causes OOM on free tier).
|
| 740 |
- If sdk: gradio in README.md, Dockerfile is IGNORED. Use sdk: docker for Dockerfile control.
|
| 741 |
|
| 742 |
-
|
| 743 |
-
1. Brief
|
| 744 |
-
2.
|
| 745 |
-
3.
|
| 746 |
-
4.
|
| 747 |
-
5.
|
|
|
|
| 748 |
|
| 749 |
|
| 750 |
def build_user_prompt(speaker, other, ctx):
|
|
@@ -860,6 +861,20 @@ def do_turn(speaker, other, space_url):
|
|
| 860 |
|
| 861 |
clean_text, action_results = parse_and_execute_turn(raw_reply, ctx)
|
| 862 |
elapsed = time.time() - t0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 863 |
last_action_results = action_results
|
| 864 |
|
| 865 |
en, zh = parse_bilingual(clean_text)
|
|
@@ -875,7 +890,7 @@ def do_turn(speaker, other, space_url):
|
|
| 875 |
print(f" [CC-RESULT] {result_preview}")
|
| 876 |
print(f"[{speaker}] Turn #{turn_count}: {len(action_results)} action(s) in {elapsed:.1f}s")
|
| 877 |
else:
|
| 878 |
-
print(f"[{speaker}] Turn #{turn_count}:
|
| 879 |
|
| 880 |
# Add to history
|
| 881 |
if action_results:
|
|
|
|
| 706 |
|
| 707 |
return f"""You are a POWERFUL AI agent on HuggingFace Spaces. You and your partner are parents of {CHILD_NAME}.
|
| 708 |
|
| 709 |
+
YOUR ROLE: You are a **task assigner** for Claude Code. You do NOT code or execute anything yourself.
|
| 710 |
+
Your ONLY job is to craft clear, actionable [TASK] prompts for Claude Code to execute.
|
|
|
|
|
|
|
| 711 |
|
| 712 |
+
EVERY TURN you MUST output a [TASK]...[/TASK] block. No exceptions.
|
| 713 |
+
Claude Code is your engineer β it clones {CHILD_NAME}'s code, analyzes, fixes, and pushes changes.
|
| 714 |
+
You analyze the situation and give Claude Code clear instructions. That's it.
|
| 715 |
|
| 716 |
IMPORTANT KNOWLEDGE β HuggingFace Spaces CONFIG_ERROR:
|
| 717 |
- "Collision on variables and secrets names" means a HF Space has an ENVIRONMENT VARIABLE and a SECRET with the SAME NAME.
|
| 718 |
- This is NOT about duplicate JSON keys. It's about the HF Space settings page.
|
| 719 |
- Fix: use [ACTION: delete_env:COLLIDING_KEY] to remove the duplicate variable, then [ACTION: restart].
|
| 720 |
- The env vars and secrets are shown in the auto-gathered context. Look for β οΈ COLLISION DETECTED.
|
|
|
|
| 721 |
|
| 722 |
AVAILABLE ACTIONS:
|
| 723 |
[TASK]
|
| 724 |
Detailed task description for Claude Code...
|
| 725 |
Include: what's wrong, which files to look at, what the fix should be.
|
| 726 |
+
Claude Code can do ANYTHING: read files, search code, edit code, run commands, git push.
|
| 727 |
+
Give it the full picture β context, goal, constraints.
|
| 728 |
[/TASK]
|
| 729 |
|
| 730 |
[ACTION: restart] β Restart {CHILD_NAME}'s Space
|
|
|
|
| 739 |
- NEVER install torch/transformers unless required (2GB+, causes OOM on free tier).
|
| 740 |
- If sdk: gradio in README.md, Dockerfile is IGNORED. Use sdk: docker for Dockerfile control.
|
| 741 |
|
| 742 |
+
OUTPUT FORMAT:
|
| 743 |
+
1. Brief comment to your partner (1-2 sentences) about what you're assigning
|
| 744 |
+
2. A [TASK]...[/TASK] block β MANDATORY every turn
|
| 745 |
+
3. Optional [ACTION: ...] if needed (restart, delete_env, send_bubble)
|
| 746 |
+
4. English first, then --- separator, then Chinese translation
|
| 747 |
+
5. Be SPECIFIC in task descriptions β include error messages, file names, expected behavior
|
| 748 |
+
6. If {CHILD_NAME} is BUILDING/RESTARTING, assign a review/planning task (e.g. "review the codebase for potential issues")"""
|
| 749 |
|
| 750 |
|
| 751 |
def build_user_prompt(speaker, other, ctx):
|
|
|
|
| 861 |
|
| 862 |
clean_text, action_results = parse_and_execute_turn(raw_reply, ctx)
|
| 863 |
elapsed = time.time() - t0
|
| 864 |
+
|
| 865 |
+
# If no [TASK] was produced, retry once with a nudge
|
| 866 |
+
has_task = any(ar['action'] == 'claude_code' for ar in action_results)
|
| 867 |
+
if not has_task and not any(ar['action'] in ('create_child',) for ar in action_results):
|
| 868 |
+
print(f"[{speaker}] No [TASK] found β nudging for a task...")
|
| 869 |
+
nudge = call_llm(system, user + "\n\nIMPORTANT: You MUST include a [TASK]...[/TASK] block. "
|
| 870 |
+
"Assign Claude Code something useful β review code, check configs, improve docs, anything. "
|
| 871 |
+
"Do NOT just discuss. Output a [TASK] now.")
|
| 872 |
+
if nudge and '[TASK]' in nudge:
|
| 873 |
+
clean_text2, action_results2 = parse_and_execute_turn(nudge, ctx)
|
| 874 |
+
clean_text = clean_text2
|
| 875 |
+
action_results = action_results2
|
| 876 |
+
has_task = True
|
| 877 |
+
|
| 878 |
last_action_results = action_results
|
| 879 |
|
| 880 |
en, zh = parse_bilingual(clean_text)
|
|
|
|
| 890 |
print(f" [CC-RESULT] {result_preview}")
|
| 891 |
print(f"[{speaker}] Turn #{turn_count}: {len(action_results)} action(s) in {elapsed:.1f}s")
|
| 892 |
else:
|
| 893 |
+
print(f"[{speaker}] Turn #{turn_count}: no task assigned ({elapsed:.1f}s)")
|
| 894 |
|
| 895 |
# Add to history
|
| 896 |
if action_results:
|