ツール呼び出し
すべてのプロトコルで使える関数ツールと、数百のツールを使うエージェント向けのゲートウェイ実行型ツール検索。
関数ツール
標準のOpenAIのtools / tool_choiceを使います。モデルがtool_callsを返すので、それを実行し、結果をrole: "tool"のメッセージとして送り返します。ツール呼び出しに対応したルートがないモデルは400 unsupported_capabilityを返します。GET /api/models/{slug}のsupported_paramsで確認してください。
| 制限 | 値 |
|---|---|
ツールと関数のdescription | 65,536文字(超えると上限を示す400) |
| ツール呼び出しID | 65,536文字。署名付きIDは変更されずに往復 |
| 1つのアシスタントターン内での呼び出しIDの重複 | 400(履歴の修正が必要) |
/v1/chat/completionsGET/api/models/{slug}from openai import OpenAI
import json
client = OpenAI(base_url="https://api.experientiallabs.ai/v1", api_key="<YOUR_API_KEY>")
tools = [{"type": "function", "function": {
"name": "get_weather", "description": "Current weather for a city",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
}}]
messages = [{"role": "user", "content": "Weather in Paris?"}]
r = client.chat.completions.create(model="gpt-6-luna", messages=messages, tools=tools)
call = r.choices[0].message.tool_calls[0]
messages += [r.choices[0].message, {"role": "tool", "tool_call_id": call.id,
"content": json.dumps({"temp_c": 18})}]
final = client.chat.completions.create(model="gpt-6-luna", messages=messages, tools=tools)
print(final.choices[0].message.content)ツール検索
MCPを多用するエージェントは、ツール定義だけで1ターンに10万トークン以上を消費することがあります。使用頻度の低いツールにdefer_loading: trueを付け、ツール検索ツールを宣言してください。ゲートウェイは遅延指定された定義を送らずに1つのtool_search関数だけを公開し、モデルがそれを呼び出すとBM25(または正規表現)で検索して一致したツールを読み込み、同じリクエストの中でモデルを再度呼び出します。お客様に届くのは最終的なツール呼び出しだけです。検索は1リクエストあたり最大3回で、ディスパッチのたびにリクエストの試行回数の枠を消費します。
| プロトコル | 宣言 |
|---|---|
| Chat Completions | {"type": "openrouter:tool_search", "max_results": 5} |
| Responses | {"type": "tool_search"} |
| Messages | {"type": "tool_search_tool_bm25_20251119", "name": "tool_search"}(正規表現:tool_search_tool_regex_20251119) |
tool_choiceの"auto"と"required"は使えます。tool_searchを名指しするtool_choiceはまだ使えません。遅延指定されたツールがない場合は、tool_search->dropped(no_deferred_tools)として破棄されます。
tools = [
{"type": "openrouter:tool_search", "max_results": 5},
*[{"type": "function", "defer_loading": True, "function": t} for t in my_mcp_tools],
]
r = client.chat.completions.create(
model="gpt-6-luna", tools=tools, tool_choice="auto",
messages=[{"role": "user", "content": "Book a flight from SFO to JFK."}],
)
print(r.choices[0].message.tool_calls) # the search round stays inside the gatewayカスタムツールと名前空間付きツール(Responses)
OpenAIのネイティブなルートでは、custom、namespace、tool_searchのツールタイプがそのまま渡されます。それ以外では、カスタムツールは文字列のinputを1つだけ受け取る関数として処理され(文法は強制されず、指示として扱われます)、呼び出しはcustom_tool_callアイテムとして返り、tools.custom->translated(custom_as_function_input)として通知されます。Chat Completionsでは、同じツールを{"type": "custom", "custom": {"name", "description", "format"}}として受け付け、呼び出しは"type": "custom"とcustom.inputを含むtool_callsのエントリとして返ります。
/v1/responses{
"model": "gpt-6-luna",
"input": "Patch the bug in utils.py",
"tools": [{"type": "custom", "name": "apply_patch", "description": "Apply a unified diff"}]
}