建構 AI 系統,無需寫死模型選擇。
每個請求附帶一條策略。unhardcoded 篩選即時模型目錄,挑選符合規則、成本最低的候選模型,透過您自己的供應商金鑰執行,並回傳決策的追蹤紀錄。
fp 301140696-1054914287
模型路由迴圈
一條策略決定一次呼叫。相同輸入、相同目錄、相同決策。每次皆然,且有書面紀錄。
top_k 備援串接。工作流程模式
工作流程是由路由步驟組成的有界無環圖。每個節點攜帶自己的策略並獨立路由;整個圖產生一條統一的追蹤紀錄。這正是 unhardcoded 從「帶規則的路由」演變為完整系統的地方。
低成本分類,依品質下限起草回覆,最後由一個強力 no-log 守衛在送出前決定是否拒絕。
關鍵:最後一步是由策略強制執行的閘門,可以中止送出,而不只是寄望它能發揮作用。
查看 flow_ir
["flow", {
"u": {"kind": "input"},
"t": {"kind": "llm", "system": "Classify the ticket and extract the account id as JSON.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["has_cap", "supports_json_mode"]],
["neg", ["normalize", ["field", "price_out"]]], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["u"]},
"d": {"kind": "llm", "system": "Write a reply using the ticket and the triage.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["cmp", "bench_intelligence", "ge", 0.55]],
["neg", ["normalize", ["field", "price_out"]]], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["u", "t"], "template": "Ticket:\n$1\n\nTriage:\n$2"},
"g": {"kind": "llm", "system": "Check brand voice, PII, refund limits. Refuse if any fail.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["is", "no_log"]],
["field", "bench_intelligence"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["d"]},
"out": {"kind": "output", "inputs": ["g"]}
}]先由低成本模型生成初稿,再由強力批評者列出缺陷,最後重寫並修正每個問題。
關鍵:在預算範圍內實現品質跨越——大部分權杖消耗在低成本模型上。
查看 flow_ir
["flow", {
"u": {"kind": "input"},
"d": {"kind": "llm", "system": "Draft an answer.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["neg", ["normalize", ["field", "price_out"]]], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["u"]},
"c": {"kind": "llm", "system": "Critique the draft: list concrete flaws and gaps.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["field", "bench_intelligence"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["d"]},
"r": {"kind": "llm", "system": "Rewrite the answer, fixing every point in the critique.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["field", "bench_intelligence"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["u", "d", "c"], "template": "Question:\n$1\n\nDraft:\n$2\n\nCritique:\n$3"},
"out": {"kind": "output", "inputs": ["r"]}
}]以同一強力策略進行 N 次種子採樣,再由評判者從中擇優選出勝出結果。
關鍵:sample 以確定性方式在排名靠前的候選模型中分散採樣——可重現的多樣性,而非隨機。
查看 flow_ir
["flow", {
"u": {"kind": "input"},
"n1": {"kind": "llm", "system": "Answer the question.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["field", "bench_intelligence"], ["sample", 0.5], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["u"]},
// n2, n3: the same policy, two more seeded draws
"j": {"kind": "llm", "system": "Pick the single best candidate; return it verbatim.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["field", "bench_intelligence"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["n1", "n2", "n3"], "template": "A:\n$1\n\nB:\n$2\n\nC:\n$3"},
"out": {"kind": "output", "inputs": ["j"]}
}]三個依族系固定的模型並行起草,第四個模型將它們合成為一個更優的單一答案。
關鍵:family_eq 鎖定確切的模型系列,使評審團可重現——而非「今天最便宜的那個」。
查看 flow_ir
["flow", {
"u": {"kind": "input"},
"a": {"kind": "llm", "system": "Draft an answer.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["family_eq", "gemini-3.1-pro-preview"]],
["zero"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]], "inputs": ["u"]},
// b: family_eq "claude-opus-4-8" · c: family_eq "deepseek-v4-flash"
"f": {"kind": "llm", "system": "Synthesize the single best answer from the drafts.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["field", "bench_intelligence"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["a", "b", "c"]},
"out": {"kind": "output", "inputs": ["f"]}
}]推論器與程式碼產生器在不同篩選條件下並行執行,再由合併步驟整合。
關鍵:每個分支為其任務(推論 vs 程式設計)挑選最合適的模型,而非讓單一模型包辦所有工作。
查看 flow_ir
["flow", {
"u": {"kind": "input"},
"rz": {"kind": "llm", "system": "Reason through the problem step by step.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["is", "cap_reasoning"]],
["field", "bench_intelligence"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]], "inputs": ["u"]},
"cd": {"kind": "llm", "system": "Produce any code the problem needs.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["cmp", "bench_coding_rank", "le", 5]],
["field", "bench_coding"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]], "inputs": ["u"]},
"m": {"kind": "llm", "system": "Merge the reasoning and the code into one answer.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["field", "bench_intelligence"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["rz", "cd"], "template": "Reasoning:\n$1\n\nCode:\n$2"},
"out": {"kind": "output", "inputs": ["m"]}
}]快速入門
unhardcoded 相容 OpenAI 介面。相比一般呼叫,僅需三處變更。
-
將 SDK 指向託管位址。修改
baseURL;SDK 的其餘部分維持不變。const client = new OpenAI({ baseURL: "https://<your-host>/v1", apiKey: process.env.UNHARDCODED_KEY, }); -
在呼叫中附加策略。在後端建構
policy_ir,與messages一同傳送。路由來自策略,因此model只是追蹤紀錄標籤。const res = await client.chat.completions.create({ model: "policy:support", policy_ir: ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["cmp", "bench_intelligence", "ge", 0.5]], // filter ["neg", ["normalize", ["field", "price_out"]]], // rank: cheapest ["argmax"], ["id"], ["always", {"action": "next_candidate"}]], messages, }); -
讀取追蹤紀錄。回應中包含決策內容:所選模型、經過排序和拒絕的候選模型,以及策略指紋(fingerprint)。
{ "chosen": { "model_family": "deepseek-v4-pro", "price_out": 1.5 }, "trace": { "policy_fingerprint": "301140696-1054914287", "rejected": [{ "model_family": "deepseek-v4-flash", "reason": "cmp bench_intelligence ge 0.5" }], "total_latency_ms": 425 } }
策略預設
以卡片形式呈現的常用路由模式。閱讀規則,複製策略,調整下限與上限。
bench_intelligence ge 0.5price_out查看 JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]],
["cmp", "bench_intelligence", "ge", 0.5]],
["neg", ["normalize", ["field", "price_out"]]],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]查看 JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["add",
["scale", 0.6, ["normalize", ["field", "bench_intelligence"]]],
["scale", 0.4, ["neg", ["normalize", ["field", "price_out"]]]]],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]bench_intelligence查看 JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["field", "bench_intelligence"],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]is cap_reasoning查看 JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["is", "cap_reasoning"]],
["field", "bench_intelligence"],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]is in_imageprice_out查看 JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["is", "in_image"]],
["neg", ["normalize", ["field", "price_out"]]],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]context ge 200000price_out查看 JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["cmp", "context", "ge", 200000]],
["neg", ["normalize", ["field", "price_out"]]],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]bench_agentic_rank le 5bench_agentic查看 JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]],
["has_cap", "supports_tools"], ["cmp", "bench_agentic_rank", "le", 5]],
["field", "bench_agentic"],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]is has_tee · is no_log查看 JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]],
["is", "has_tee"], ["is", "no_log"]],
["field", "bench_intelligence"],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]每次決策都留下憑證
追蹤紀錄是模型選擇過程的結構化、可重播記錄:哪些模型被納入考量、每個模型為何通過或遭拒、執行了什麼,以及如何重現。
sha256 計算。工作流程還包含 flow_fingerprint。參考文件
完整規格,獨立於閱讀路徑之外。
GitHub 原始碼:unhardcoded(託管服務)· unhardcoded-engine(策略引擎)