ユースケース
Decisions API によるエージェントの次アクション
エージェントループは有限の決定の連続です:ツールを呼ぶか、ユーザーに聞くか、終了するか。デシジョン呼び出しは次のアクションを選び、全選択肢の確率を返します——フリーテキストの解析もツールスキーマの検証も不要。
更新日
エージェントループを choice 質問にする
ループの各反復で現在の状態をモデルに渡し、有限の質問をひとつ:次に何をすべきか。答えは定義済みアクションのひとつと confidence——ループランナーが必要とする契約そのものです。
選択肢は宣言されているので、モデルがループに実装されていないアクションを返すことはありません。無効な出力はプロンプトの努力ではなく構造上ありえません。
次アクションの決定
// Agent loop: decisions-1 picks the next action each step.
type Action = "search_docs" | "call_tool" | "ask_user" | "finish";
async function decideNext(state: unknown): Promise<{ action: Action; confidence: number }> {
const res = await fetch("https://decisions-api.net/api/v1/decisions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.DECISIONS_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "decisions-1",
state, // string, JSON object, or array of text
questions: {
next: {
type: "choice",
instructions: "What should the agent do next?",
criteria: {
search_docs: "Look up documentation before acting.",
call_tool: "Run the next planned tool call.",
ask_user: "Stop and ask the user for clarification.",
finish: "The task is complete; produce the final answer.",
},
},
done: { type: "noul", instructions: "Is the user's task fully complete?" },
},
}),
});
const { answers } = await res.json();
return { action: answers.next.choice, confidence: answers.next.confidence };
}
const MAX_STEPS = 8;
async function runAgent(agentState: unknown) {
for (let step = 0; step < MAX_STEPS; step++) {
const { action, confidence } = await decideNext(agentState);
// Illustrative response: { action: "call_tool", confidence: 0.83 }
if (confidence < 0.8) { await askUser(agentState); continue; }
switch (action) {
case "finish": return;
case "search_docs": await searchDocs(agentState); break;
case "call_tool": await runTool(agentState); break;
case "ask_user": await askUser(agentState); break;
}
}
// MAX_STEPS reached: hand off to a human instead of looping forever.
}エージェントに正直な出口を
criteria には必ず退避アクション——ask_user や finish——を入れてください。止まれないエージェントは仕事を捏造します;正直な出口は「完了」「手詰まり」を正式な回答に変えます。
同じ呼び出しに独立した noul 質問——「タスクは完全に完了したか」——を載せて、choice の答えを交差検証することもできます。
confidence で自律性をゲート
confidence が回答をポリシーに変えます。例えば 0.8 以上は無人で実行し、低いステップは ask_user か人のレビューへ。2位の選択肢の確率が、そのステップの拮抗度を教えてくれます。
勝者だけでなく分布を記録してください:0.51 対 0.49 で閾値を通過したステップは再確認に値します。
1ステップのコスト
成功した呼び出しは1問でも6問でも1クレジット——次アクションの choice と完了チェックを合わせても、ループ1歩あたり1クレジットです。
よくある質問
ツール呼び出しと何が違いますか?
ツール呼び出しは関数を選んで引数を生成します——形は開放的です。デシジョン呼び出しは定義済みアクションを確率付きで選び、自由形式の引数はありません。出力は構造上制約されています。
state には何を入れますか?
モデルが決めるのに必要なものすべて:進捗の要約、直前のツール結果、残りのステップ、制約。state は文字列、JSON オブジェクト、テキスト配列を受け取ります。
1回の呼び出しで次アクション以外も確認できますか?
はい——1呼び出しに最大6問入ります。次アクションの choice に noul「タスク完了か」チェックや、保留ステップの危険度 score を組み合わせられます。
confidence がいつも低い場合は?
たいていアクションが細かすぎるか、state にシグナルが足りません。似たアクションを統合し、state を充実させ、ask_user を正直に選べる逃げ道として残してください。
エージェントの1歩を動かす
新規訪問者は1回無料——ループの状態をプレイグラウンドに貼って、次アクションの分布を見てください。