AIニュース最前線
最新ニュースAI日報Hacker日報週報動画AIツールトレンド企業

AIニュース最前線

世界中のAI最新情報を日本語で毎時更新

最新ニュース日報トレンド企業プレミアムRSS
© 2026 ainew.jp特定商取引法に基づく表記
ニュース一覧元記事を開く
OpenAI News·2026年4月22日 19:00·約10分で読める

Responses APIにおけるWebSockets活用によるエージェントワークフローの高速化

#OpenAI#Responses API#エージェントワークフロー#WebSockets#レイテンシ最適化
TL;DR

OpenAIはResponses APIにおいてWebSocketsと接続スコープのキャッシュを活用し、CodexエージェントループのAPIオーバーヘッドを削減してモデルレイテンシを大幅に改善する技術的アプローチを公開した。

AI深層分析2026年4月23日 02:11
4
重要/ 5段階
深度40%
4
関連度30%
5
実用性20%
4
革新性10%
3

キーポイント

1

WebSocketsによるリアルタイム通信

従来のHTTP方式に代わり双方向のWebSockets接続を採用し、エージェントとモデル間の通信効率を最大化する。

2

接続スコープのキャッシュ活用

セッション単位で中間結果やコンテキストをキャッシュし、繰り返しのAPI呼び出しによるオーバーヘッドとコストを削減する。

3

Codexエージェントループの最適化

自律型エージェントが複雑なタスクを処理する際、レイテンシを低下させつつ安定した応答速度を実現する具体的な実装パターンを示す。

影響分析・編集コメントを表示

影響分析

本記事は、OpenAIのResponses APIをエージェント開発に活用する際の実装ベストプラクティスを明確にした。WebSocketsとキャッシュ戦略の組み合わせにより、従来のストリーミング方式よりも高速で安定したエージェント応答が可能になり、リアルタイム性が求められる自律型AIアプリケーションの普及を後押しする。開発者は通信プロトコルの見直しだけでパフォーマンスを大幅に改善できるため、実務への適用価値が高い。

編集コメント

公式技術ブログとして公開された実装ガイドであり、エージェント開発現場ですぐに適用可能な具体的な最適化手法を示している点が高く評価できる。WebSocketsとキャッシュの組み合わせは、今後エージェント基盤の標準アーキテクチャに組み込まれていく可能性が高い。

Codexにバグ修正を依頼すると、関連するファイルをコードベース内からスキャンし、コンテキスト構築のためにそれらを読み取り、編集を行い、修正が機能したことを確認するためにテストを実行します。裏側では、これは数十回にわたるResponses API(Responses API)のリクエストの往復を意味します。モデルの次のアクションを決定し、コンピュータ上でツールを実行し、その出力をAPIに送信し、これを繰り返します。これらのリクエストすべてが積み重なり、Codexが複雑なタスクを完了するまでユーザーが待つ時間が数分になることがあります。レイテンシ(latency)の観点から、Codexエージェントループ(agentic loop)は主に3つのステージで時間を費やしています。それはAPIサービス内での作業(リクエストの検証と処理)、モデル推論(model inference)、そしてクライアント側の時間(ツールの実行とモデルコンテキストの構築)です。推論とは、GPU上でモデルが動作して新しいトークンを生成するステージです。過去には、GPU上でのLLM(大規模言語モデル)推論がエージェントループの最も遅い部分だったため、APIサービスのオーバーヘッドは簡単に隠れていました。しかし、推論が高速化するにつれ、エージェントロールアウト(agentic rollout)に伴う累積的なAPIオーバーヘッドはより顕著になっています。この投稿では、APIを使用したエージェントループをエンドツーエンドで40%高速化した方法、およびユーザーが推論速度の65からほぼ1,000トークン/秒(tokens per second / TPS)への跳躍を体験できるようにした取り組みについて説明します。私たちは、キャッシング(caching)、不要なネットワークホップ(network hops)の排除、問題を迅速にフラグ付けする安全スタック(safety stack)の改善、そして何より重要なのは、一連の同期API呼び出し(synchronous API calls)を行う代わりにResponses APIへの永続的な接続を作成する方法を構築することで、この課題に取り組みました。

Responses APIにおいて、GPT-5やGPT-5.2などの以前のフラッグシップモデル(flagship models)は、およそ65トークン/秒(TPS)で動作していました。高速なコーディングモデルであるGPT-5.3-Codex-Sparkのリリースにあたり、私たちの目標は1桁高速化すること、つまり1,000 TPSを超える速度でした。これはLLM推論に最適化された専用Cerebrasハードウェアによって可能になりました。ユーザーがこの新モデルの真の速度を体験できるようにするためには、APIオーバーヘッドを削減する必要がありました。2025年11月頃、私たちはResponses APIのパフォーマンススプリントを開始し、単一リクエストのクリティカルパスレイテンシ(critical-path latency)に対する多くの最適化を実現しました。マルチターンレスポンス(multi-turn responses)に対して高コストなトークン化やネットワーク呼び出しをスキップするために、レンダリングされたトークンとモデル設定をメモリにキャッシングすること。中間サービス(例えば画像処理の解像度など)への呼び出しを排除し推論サービス自体に直接呼び出すことで、ネットワークホップレイテンシを削減すること。特定の分類器を実行して会話をより迅速にフラグ付けられるよう安全スタックを改善すること。これらの改善により、APIのレスポンス性を示す最初のトークン到達時間(time to first token / TTFT)で約45%の改善が見られましたが、GPT-5.3-Codex-Sparkにはまだ十分高速ではありませんでした。これらの改善があったにもかかわらず、モデルの速度に対してResponses APIのオーバーヘッドが大きすぎました。つまり、ユーザーはGPUでモデルを提供する前に、APIを実行しているCPUを待たなければならなかったのです。

根本的な問題は構造的なものでした。私たちは各Codexリクエストを独立して扱い、フォローアップリクエスト(follow-up request)ごとに会話状態(conversation state)や他の再利用可能なコンテキスト(reusable context)を処理していました。会話の大部分が変更されていない場合でも、完全な履歴(full history)に関連する作業のコストを支払っていました。会話が長くなるにつれて、その繰り返される処理はより高コストになりました。設計を緊密にするため、トランスポートプロトコル(transport protocol)を見直しました。HTTP上で新しい接続を確立して各フォローアップリクエストに完全な会話履歴を送信するのではなく、永続的な接続(persistent connection)を維持し状態をキャッシングすることはできないでしょうか?このアイデアは、検証と処理が必要な新しい情報のみを送信し、接続の存続期間中は再利用可能な状態をメモリにキャッシングすることでした。これにより、冗長な作業によるオーバーヘッドを削減できます。私たちはWebSocketsやgRPC双方向ストリーミング(gRPC bidirectional streaming)など、いくつかの異なるアプローチを検討しました。シンプルなメッセージトランスポートプロトコル(message transport protocol)であるWebSocketsを採用したのは、ユーザーがResponses APIの入力と出力の形状(API input and output shapes)を変更する必要がないためでした。これは開発者フレンドリーであり、既存のアーキテクチャにほとんど混乱をもたらさずに適合しました。最初のWebSocketプロトタイプは、Responses APIレイテンシに対して可能だと考えていたことを変えました。APIスタック全体に深い専門知識を持つCodexチームのエンジニアが、1晩Codexエージェントを実行することでプロトタイプを組み立てました。そのプロトタイプでは、エージェントロールアウトが単一の長時間実行されるResponse(long-running Response)としてモデル化されました。asyncioの機能を使用して、Responses APIはツール呼び出し(tool call)がサンプリングされた後にサンプリングループ(sampling loop)で非同期にブロックし、Responses APIはresponse.doneイベントをクライアントに戻して送信しました。ツール呼び出しを実行した後、クライアントはツール結果を含むresponse.appendイベントを戻して送信し、これによりサンプリングループのブロックが解除され、モデルが続行できました。ここでのアナロジーは、ローカルツール呼び出し(local tool call)をホストされたツール呼び出し(hosted tool call)として扱うことです。モデルがウェブ検索サービス(web search service)を呼び出すと、推論ループ(inference loop)はブロックされ、ウェブ検索サービスに呼び出しを行い、そのサービス応答をモデルコンテキスト(model context)に配置します。私たちの設計でも同じことを行いました。ただし、リモートサービスに呼び出すのではなく、モデルのツール呼び出しをWebSocket経由でクライアントに戻して送信しました。クライアントが応答すると、クライアントのツール呼び出し応答をコンテキストに配置し、サンプリングを続行しました。この設計は極めて効果的でした。なぜなら、エージェントロールアウト全体にわたる繰り返されるAPI作業を排除したからです。推論前の作業(preinference work)を1回実行し、ツール実行で一時停止し、最後にポストインフレンス作業(postinference work)を1回実行することができました。残念ながら、これはより馴染みがなく複雑なAPI形状のコストを伴いました。私たちは開発者が新しいインタラクションモード围绕してAPI統合を書き直すことなく、WebSocketサポートを簡単に組み込めるようにしたかったので。

リリースしたバージョンでは、馴染みのある形状に戻しました。同じボディでresponse.create(response.create)を引き続き使用し、previous_response_id(previous_response_id)を使用して前のレスポンスの状態から会話コンテキストを継続します。WebSocket接続において、サーバーは接続スコープ(connection-scoped)のメモリ内キャッシュ(in-memory cache)に前のレスポンス状態を保持します。フォローアップresponse.createにprevious_response_idが含まれている場合、完全な会話を最初から再構築するのではなく、キャッシュからその状態を取得します。そのキャッシングされた状態には以下のものが含まれます。前のレスポンスオブジェクト、以前の入力および出力アイテム、ツール定義と名前空間(tool definitions and namespaces)、以前にレンダリングされたトークン(rendered tokens)などの再利用可能なサンプリングアーティファクト(reusable sampling artifacts)。メモリ内の前のレスポンス状態を再利用することで、以下の主要な最適化を実現できました。安全分類器(safety classifiers)とリクエストバリデーター(request validators)の一部が、毎回完全な履歴ではなく新しい入力のみを処理すること。不要なトークン化をスキップするために、追加していくレンダリングされたトークンのメモリ内キャッシュを保持すること。リクエスト全体で成功したモデル解決/ルーティングロジック(model resolution/routing logic)を再利用すること。請求などの非ブロッキングなポストインフレンス作業(non-blocking postinference work)を、後続のリクエストとオーバーラップすること。目標は、開発者がすでに理解し構築の基盤としていたAPI形状を保ちつつ、最小オーバーヘッドのプロトタイプに可能な限り近づけることでした。

WebSocketモードの構築に2ヶ月のスプリントを費やした後、主要なコーディングエージェントスタートアップ(coding agent startups)を対象にアルファ版(alpha)をリリースし、インフラストラクチャ(infrastructure)への統合と安全なトラフィックの増量が可能になるようにしました。アルファユーザーはこれを気に入り、エージェントワークフロー(agentic workflows)で最大40%の改善を報告しました。前向きなアルファフィードバックを受け、私たちはリリースの準備が整いました。リリース結果は即座に現れました。CodexはResponses APIトラフィックの大部分を迅速にWebSocketモードに移行し、顕著なレイテンシ改善を確認しました。GPT-5.3-Codex-Sparkについては、1,000 TPSの目標を達成し、最大4,000 TPSのバーストも見られ、リアルな本番トラフィック(production traffic)においてResponses APIがはるかに高速な推論に追いつけることが示されました。この影響は開発者コミュニティにもすぐに現れました。Codexはトラフィックの大部分をWebSocketsに迅速に移行しました。GPT-5.3-Codex、GPT-5.4などの最新モデルを実行するCodexユーザーはすべて、WebSocketモードの高速化から恩恵を受けます。VercelはAI SDKにWebSocketモードを統合し、レイテンシが最大40%減少することを確認しました。Clineのマルチファイルワークフローは39%高速化しました。Cursor内のOpenAIモデルが最大30%高速化しました。WebSocketモードは、2025年3月のResponses APIリリース以来、最も重要な新機能の一つです。OpenAIのAPIチームとCodexチームの密接な協力により、アイデアから本番環境での実行までわずか数週間で完了しました。これはエージェントロールアウトレイテンシを劇的に改善するだけでなく、ビルダーの増大するニーズにも応えています。モデル推論が高速化するにつれて、推論を取り巻くサービスやシステムも高速化し、これらの恩恵をユーザーに伝える必要があります。

原文を表示

When you ask Codex to fix a bug, it scans through your codebase for relevant files, reads them to build context, makes edits, and runs tests to verify the fix worked. Under the hood, that means dozens of back-and-forth Responses API requests: determine the model’s next action, run a tool on your computer, send the tool output back to the API, and repeat.All of these requests can add up to minutes that users spend waiting for Codex to complete complex tasks. From a latency perspective, the Codex agent loop spends most of its time in three main stages: working in the API services (to validate and process requests), model inference, and client-side time (running tools and building model context). Inference is the stage where the model runs on GPUs to generate new tokens. In the past, running LLM inference on GPUs was the slowest part of the agentic loop, so API service overhead was easy to hide. As inference gets faster, the cumulative API overhead from an agentic rollout is much more notable.In this post, we'll explain how we made agent loops using the API 40% faster end-to-end, letting users experience the jump in inference speed from 65 to nearly 1,000 tokens per second. We approached this through caching, eliminating unnecessary network hops, improving our safety stack to quickly flag issues, and—most importantly—building a way to create a persistent connection to the Responses API, instead of having to make a series of synchronous API calls.In the Responses API, previous flagship models like GPT‑5 and GPT‑5.2 ran at roughly 65 tokens per second (TPS). For the launch of GPT‑5.3‑Codex‑Spark, a fast coding model, our goal was an order of magnitude faster: over 1,000 TPS, enabled by specialized Cerebras hardware optimized for LLM inference. To make sure users could experience the true speed of this new model, we had to reduce API overhead. Around November of 2025, we launched a performance sprint on the Responses API, landing many optimizations to the critical-path latency for a single request: Caching rendered tokens and model configuration in memory to skip expensive tokenization and network calls for multi-turn responsesReducing network hop latency by eliminating calls to intermediate services (for example, image processing resolution) and directly calling the inference service itselfImproving our safety stack so we could run certain classifiers to flag conversations fasterWith these improvements, we saw close to a 45% improvement in time to first token (TTFT)—which reflects how responsive the API feels—but these improvements were still not fast enough for GPT‑5.3‑Codex‑Spark. Even with these improvements, Responses API overhead was too large relative to the speed of the model—that is, users had to wait for the CPUs running our API before they could use the GPUs serving the model.The deeper issue was structural: we treated each Codex request as independent, processing conversation state and other reusable context in every follow-up request. Even when most of the conversation hadn't changed, we still paid for work tied to the full history. As conversations got longer, that repeated processing became more expensive.To tighten up the design, we rethought the transport protocol: could we keep a persistent connection and cache state, rather than establishing a new connection over HTTP and sending the full conversation history for each follow-up request? The idea was to only send any new information requiring validation and processing and cache reusable state in memory for the lifetime of the connection. This would reduce overhead from redundant work.We considered a few different approaches, including WebSockets and gRPC bidirectional streaming. We landed on WebSockets because as a simple message transport protocol, users wouldn't have to change their Responses API input and output shapes. It was developer-friendly and fit our existing architecture with little disruption.The first WebSocket prototype changed what we thought was possible for Responses API latency. An engineer on the Codex team with deep expertise across the API stack pulled together a prototype by running a Codex agent overnight.In that prototype, agentic rollouts were modeled as a single long-running Response. Using asyncio features, the Responses API would asynchronously block in the sampling loop after a tool call was sampled, and the Responses API would send a response.done event back to the client. After executing the tool call, clients would send back a response.append event with the tool result, which unblocked the sampling loop and let the model continue.An analogy here is treating the local tool call as a hosted tool call. When the model calls web search, the inference loop blocks, calls a web search service, and puts the service response in the model context. In our design, we did the same thing; but instead of calling a remote service, we sent the model's tool call to the client back over the WebSocket. When the client responded, we put the client's tool call response into the context and continued to sample.This design was extremely effective because it eliminated repeated API work across an agent rollout. We could do preinference work once, pause for tool execution, and do postinference work once at the end.Unfortunately, this came at the cost of a less familiar and more complicated API shape. We wanted developers to be able to drop in WebSocket support without having to rewrite their API integration around a new interaction mode.For the version we launched, we switched back to a familiar shape: keep using response.create with the same body, and use previous_response_id to continue the conversation context from the previous response’s state.On a WebSocket connection, the server keeps a connection-scoped, in-memory cache of previous response state. When a follow-up response.create includes previous_response_id, we fetch that state from the cache instead of rebuilding the full conversation from scratch.That cached state includes:The previous response objectPrior input and output itemsTool definitions and namespacesReusable sampling artifacts, like previously rendered tokensBy reusing the in-memory previous response state, we were able to land several major optimizations:Making some of our safety classifiers and request validators process only new input, not the full history every timeKeeping an in-memory cache of rendered tokens that we append to so we can skip unnecessary tokenizationReusing our successful model resolution/routing logic across requests Overlapping non-blocking postinference work like billing with subsequent requestsThe goal was to get as close as possible to the minimal-overhead prototype but with an API shape developers already understood and built around.After a two-month sprint building WebSocket mode, we launched an alpha with key coding agent startups so they could integrate it into their infrastructure and safely ramp up traffic. Alpha users loved it, reporting up to 40% improvements⁠(opens in a new window) in their agentic workflows. Given the positive alpha feedback, we were ready to launch.The launch results were immediate. Codex quickly ramped up the majority of their Responses API traffic onto WebSocket mode, seeing significant latency improvements. For GPT‑5.3‑Codex‑Spark, we hit our 1,000 TPS target and saw bursts up to 4,000 TPS, showing that the Responses API could keep up with much faster inference in real production traffic. The impact showed up quickly in the developer community too:Codex quickly ramped the majority of their traffic onto WebSockets. Codex users running the latest models such as GPT‑5.3‑Codex⁠(opens in a new window), GPT‑5.4⁠(opens in a new window), and beyond all benefit from WebSocket mode’s speed up.Vercel integrated WebSocket mode into the AI SDK and saw latency decrease by up to 40%⁠(opens in a new window).Cline’s multi-file workflows are 39% faster⁠(opens in a new window).OpenAI models in Cursor became up to 30% faster⁠(opens in a new window).WebSocket mode is the one of the most significant new capabilities in the Responses API since its launch in March 2025. We went from idea to running in production in just a few weeks through close collaboration between OpenAI's API and Codex teams. It not only dramatically improves agent rollout latency but also supports a growing need for builders: as model inference gets faster, the services and systems that surround inference also need to speed up to transfer these gains to users.

この記事をシェア

関連記事

The Decoder★42026年4月22日 04:55

OpenAI「ChatGPT Images 2.0」は生成前に推論し、画像作成に思考機能とウェブ検索を追加

OpenAIは画像生成モデル「ChatGPT Images 2.0」に推論機能とウェブ検索を追加した。同モデルは単一プロンプトから最大8枚の画像を生成でき、非ラテン文字を含むテキスト処理能力が大幅に向上した。

The Batch★42026年5月29日 09:00

Gemini Flash の価格上昇、AI 法施行延期、エージェントがオンライントラフィックを牽引

The Batch は、シリコンバレーで注目される AI フォワードデプロイメントエンジニア(FDE)の役割について報じ、顧客組織に常駐してワークフローをカスタマイズする専門職の台頭を紹介した。

Simon Willison Blog★42026年6月6日 08:56

OpenAI ヘルプ:ロックダウンモード

OpenAI が、個人アカウントおよびビジネスアカウント向けにデータ漏洩防止を目的とした「ロックダウンモード」機能を正式に提供開始した。

ニュース一覧に戻る元記事を読む