{ "id": "build-small-hackathon/ContextForge", "slug": "ContextForge", "title": "ContextForge", "sdk": "gradio", "declared_models": [], "tags": [ "gradio", "region:us" ], "app_file": "app.py", "README": "# ContextForge / Agent Prompt Compiler ContextForge compiles messy software, app, and agent ideas into executable prompt architectures. It is a compiler pipeline, not a generic prompt generator. **GitHub:** https://github.com/rthgit/ContextForge **Competition Gradio Space:** https://huggingface.co/spaces/build-small-hackathon/ContextForge **Backup Gradio Space:** https://huggingface.co/spaces/RthItalia/ContextForge **Demo video:** https://raw.githubusercontent.com/rthgit/ContextForge/main/artifacts/contextforge-demo.mp4 **Tagline:** From fuzzy brief to build-ready agent blueprint. ## Backyard AI Fit - Built for real builders using AI coding agents. - Real problem: vague briefs make Codex and other agents produce wrong code, generic UI, or incomplete workflows. - Real use evidence: this architecture was used to coordinate Trollsona development, including UI refactor, model cascade, QA, packaging, and video automation. - Small-model fit: ContextForge decomposes a hard prompt-writing task into seven smaller calls so a small model can handle it. The backend always executes seven isolated modules sequentially: 1. intake analysis 2. topology decision 3. Vital Few / Vital Spot extraction 4. reasoning architecture selection 5. prompt pack generation 6. QA / repair 7. final assembly Every module attempts its own small-model call. If one call fails, only that stage uses a deterministic fallback and the pipeline continues. Runtime Details shows the source used by every stage. Each modul ...", "APP_FILE": "from __future__ import annotations\nfrom dataclasses import dataclass\nfrom functools import lru_cache\nfrom typing import Any, Callable\nfrom transformers import AutoModelForCausalLM, AutoTokenizer\n\nfrom __future__ import annotations\n\nimport json\nimport os\nimport re\nimport time\nfrom dataclasses import dataclass\nfrom functools import lru_cache\nfrom typing import Any, Callable\n\n\nAPP_TITLE = \"ContextForge\"\nAPP_SUBTITLE = \"From fuzzy brief to build-ready agent blueprint.\"\nDEFAULT_MODEL_ID = \"Qwen/Qwen2.5-0.5B-Instruct\"\nDEFAULT_MID_MODEL_ID = \"RthItalia/nano_compact_3b_qkvfp16\"\nDEFAULT_HIGH_MODEL_ID = \"Qwen/Qwen3-32B\"\nREQUIRED_PROMPT_TAGS = [\n \"ROLE\",\n \"COGNITIVE_LAYERS\",\n \"KAHNEMAN_SYSTEM2\",\n \"PARETO_80_20\",\n \"VITAL_SPOT\",\n \"REASONING_PROTOCOL\",\n \"AGENTIC_LOOP\",\n \"ACTION\",\n \"FORMAT_AND_TARGET\",\n \"QA_CHECKS\",\n]\nTOPOLOGIES = [\"Auto\", \"Single Prompt\", \"Cascade\", \"Context Pack\", \"Agent Workflow\"]\nREASONING_LAYERS = [\n \"CRAFT\",\n \"Kahneman System 2\",\n \"Pareto 80/20\",\n \"Agentic Loop\",\n \"Tree of Thought controlled\",\n \"Private CoT\",\n \"Self-Correction\",\n \"Sentinel Recovery\",\n]\nSTAGE_NAMES = [\n \"intake_analysis\",\n \"topology_decision\",\n \"vital_structure\",\n \"reasoning_architecture\",\n \"prompt_pack_generation\",\n \"qa_repair\",\n \"final_assembly\",\n]\nSTAGE_TOKEN_BUDGETS = {\n \"intake_analysis\": 180,\n \"topology_decision\": 140,\n \"vital_structure\": 180,\n \"reasoning_architecture\": 240,\n \"prompt_pack_generation\": 520,\n \"qa_repair\": 260,\n \"final_assembly\": 260,\n}\n\n\ndef parse_bool_env(name: str, default: bool = False) -> bool:\n raw = os.getenv(name)\n if raw is None:\n return default\n return raw.strip().lower() in {\"1\", \"true\", \"yes\", \"on\"}\n\n\ndef parse_int_env(name: str, default: int, minimum: int, maximum: int) -> int:\n try:\n value = int(os.getenv(name, str(default)))\n except Valu ..." }