記事一覧へ
本番ディープエージェントを支えるランタイム
優れたエージェントを構築するには優れたハーネスが必要だ。そのエージェントをデプロイするには優れたランタイムが必要だ。
ハーネスとは、エージェントがそのドメインで成功できるようにモデルの周囲に構築するシステムだ。プロンプト、ツール、スキル、エージェントを定義するモデルとツール呼び出しループをサポートするその他すべてが含まれる。ランタイムはその下にあるすべてだ: 耐久性のある実行、メモリ、マルチテナンシー、オブザーバビリティ、チームが一から作り直すことなくエージェントを本番で動かし続けるための機械。
このガイドでは、エージェントをデプロイすると浮上する本番要件、それを満たすランタイム機能、そしてdeepagents deployがそれらの機能を出荷可能なものにパッケージ化する方法を説明する。
## 本番エージェントのランタイム機能
このセクションを通して「ランタイム」はLangSmith Deployment (LSD)とそのAgent Serverを指す: LSDは本番でエージェントを実行し、Agent Serverはアシスタント、スレッド、実行、メモリ、スケジュールジョブのインターフェースだ。
## 耐久性のある実行
エージェントはループを実行することで動作する: プロンプトが与えられると、モデルは推論し、ツールを呼び出し、結果を観察し、タスクが完了したと判断するまで繰り返す。
ミリ秒で返される典型的なウェブリクエストとは異なり、このループは分または時間にわたる場合がある。1回の実行で数十回のモデル呼び出しが発生したり、サブエージェントを生成したり、人間が下書きを承認するまで無期限に待機することもある。
実際には2つの場面で痛感する:
- 長い実行はインフラ障害を生き残る必要がある。
- エージェントは停止して待機できる必要がある。
エージェントは自動チェックポイントを備えた管理されたタスクキューで実行されるため、任意の実行を中断ポイントから正確に再試行、再生、再開できる。
グラフ実行の各スーパーステップは永続化レイヤー(デフォルトではPostgreSQL)にチェックポイントを書き込み、実行へのカーソルとして機能するthread_idでキー管理される。
## メモリ
エージェントには2種類のメモリが必要だ:
短期メモリは、エージェントが単一の会話内で蓄積するものだ。交わされたメッセージ、行われたツール呼び出し、実行全体で構築された中間状態。これはスレッドのチェックポイントに存在し、thread_idにスコープされる。
長期メモリは、エージェントが会話をまたいで持ち歩くものだ。会話を通じて学んだユーザーの好み、プロジェクトの慣習とベストプラクティス、新しいクエリごとに拡張されるナレッジベースが含まれる。メモリはネームスペースタプル(例: (user_id, "memories"))で整理され、スレッドをまたいで永続化されるキーバリューインターフェースだ。
## マルチテナンシー
エージェントが複数のユーザーにサービスを提供する瞬間、問題が現れる。これらは3つの異なる懸念事項に分かれる:
1. あるユーザーのデータを別のユーザーから隔離する。カスタム認証はすべてのリクエストのミドルウェアとして実行される。
2. エージェントがユーザーの代わりに行動できるようにする。Agent AuthはOAuthフローとトークンストレージを処理する。
3. 誰がシステム自体を操作できるかを制御する。RBACがこのオペレーターレベルのアクセス制御を処理する。
## ヒューマンインザループ (HITL)
エージェントはループを実行することで動作する。ほとんどの場合はそのループを中断なく実行させたい。しかし時には、重要な意思決定ポイントで人間がループの途中に介入する必要がある。
よくある2つの状況:
- 提案されたツール呼び出しのレビュー。エージェントが重大なアクション(メール送信、金融取引実行、ファイル削除)を実行する前。
- エージェントが明確化の質問をする場面。
Agent Serverはこれを2つのプリミティブで処理する: interrupt()は実行を一時停止して呼び出し元にペイロードを表示する; Command(resume=...)は人間の応答で実行を継続する。
## リアルタイムインタラクション
### ストリーミング
30秒かけて応答を生成するエージェントは、ユーザーをスピナーを見つめながら待たせる。ストリーミングはこれを解決する: エージェントが生成するにつれて部分的な出力がクライアントに流れる。
ストリーミングAPIは複数のモードをサポートする: グラフの各ステップ後の完全な状態スナップショット、状態更新のみ、トークンバイトークンのLLM出力、またはカスタムアプリケーションイベント。
スレッドストリーミングはLast-Event-IDヘッダーを介した再開をサポートする: クライアントは受信した最後のイベントのIDで再接続し、サーバーはギャップなしにそこから再生する。
### ダブルテキスト
ユーザーがエージェントがまだ前のメッセージに取り組んでいる間に新しいメッセージを送る場合。4つの戦略がある:
- enqueue(デフォルト): 新しい入力は現在の実行が終了するまで待機する。
- reject: 現在の実行が終了するまで新しい入力を拒否する。
- interrupt: 現在の実行を停止し、進捗を保存し、その状態から新しい入力を処理する。
- rollback: 現在の実行を停止し、すべての進捗を元に戻し、新しいメッセージをフレッシュな実行として処理する。
## ガードレール
すべての本番上の懸念事項が「ループを耐久的に実行する」として表現できるわけではない。一部はループ自体を形作る必要がある: モデル入力の傍受、ツール出力のフィルタリング、高コスト操作の制限。
これらはミドルウェアによって処理される。ミドルウェアは定義されたフック(before_model, wrap_model_call, wrap_tool_call, after_model)でエージェントループをラップする。
LangChainは一般的なケースをカバーする組み込みミドルウェアを提供する: PIIRedactionMiddleware, ModelRetryMiddleware, ModelFallbackMiddleware, ToolCallLimitMiddleware, SummarizationMiddleware, HumanInTheLoopMiddleware, OpenAIModerationMiddleware。
## オブザーバビリティ
エージェントが本番でどう動くかは、実際に動かすまでわからない。何かが間違ったとき、実際に何が起きたかを見る必要がある。
すべてのLangSmith Deploymentはトレーシングプロジェクトに自動的に接続される。モデル呼び出し、ツール呼び出し、サブエージェント実行、ミドルウェアフックを含む完全な実行ツリーがすぐに利用できる。
トレースはデバッグツールだけではない; 改善ループの基盤だ:
- LangSmith AIアシスタントPollyがトレースを分析し、一般的な失敗モード、遅いツール呼び出し、繰り返しパターンを浮き彫りにする。
- オンラインEvalsはLLM-as-judgeまたはカスタムスコアラーを本番トレースに対して自動実行し、リグレッションが起きたときに検知する。
## タイムトラベル
オブザーバビリティは何が起きたかを教えてくれる。タイムトラベルは、何か違うことが起きていたらどうなっていたかを問うことができる。
すべてのスーパーステップがチェックポイントを書き込むため、実行履歴のすべてのポイントはすでに戻ることができるスナップショットだ。タイムトラベルはこれを明示的にする: スレッドの履歴からチェックポイントを選び、状態を変更して、そこから再開する。
## コード実行
あらかじめ設定したツールしか呼び出せないエージェントは想定内のことしかできない。任意のコードを実行できるエージェントは汎用だ。
任意のコード実行には隔離が必要だ。Deep Agentsでは、サンドボックスバックエンドを通じて隔離が行われる。サポートされているプロバイダーはDaytona, Modal, Runloop, LangSmith Sandboxesだ。
LangSmith Sandboxes(現在プライベートプレビュー中)の特徴: ウォームプールがコールドスタートのレイテンシをなくし、認証プロキシがアウトバウンドリクエストを傍受してワークスペースシークレットからクレデンシャルを自動的に注入する(サンドボックスコードやログにAPIキーが現れない)。
## インテグレーション
Agent Serverは3つのインテグレーションサーフェスを自動的に提供する:
MCP: すべてのLangSmith DeploymentはMCPエンドポイントを自動的に公開し、MCPに対応したクライアント(Claude Desktop、IDE、他のエージェント)からあなたのエージェントを発見可能にする。
A2A: すべてのデプロイメントはA2A(エージェント間通信)エンドポイントを自動的に公開する。これにより、複数のデプロイメントにまたがるマルチエージェントアーキテクチャが扱いやすくなる。
Webhooks: 実行を作成するときにwebhook URLを渡すと、サーバーは完了時にそのURLに実行ペイロードをPOSTする。
## Cron
Agent Serverにはcronジョブが組み込まれているため、スケジュールされた実行は他のすべての実行と同じ耐久性、トレーシング、認証の保証を受ける。
2つのフレーバー:
- ステートフルcron(client.crons.create_for_thread): スケジュールを特定のthread_idに結びつける。
- ステートレスcron(client.crons.create): 各実行のために新しいスレッドを起動する。
## deepagents deploy
deepagents deployは上記のランタイムにエージェントをデプロイするパッケージングステップだ。deepagents.tomlにエージェントを定義し、CLIが設定をバンドルしてLangSmith Deploymentとしてデプロイする。
## オープンハーネス
deepagents deployはベンダーロックインを避けるよう構築されている。ハーネスはMITライセンスで完全にオープンソース、エージェント指示はAGENTS.md(オープンスタンダード)を使用し、エージェントはオープンプロトコル(MCP, A2A, Agent Protocol)で公開される。
このガイドで概説した機能—耐久性のある実行、メモリ、マルチテナンシー、ガードレール、ヒューマンインザループ、オブザーバビリティ、サンドボックスコード実行、スケジュール実行—は本番エージェントが機能するために不可欠なインフラ要件だ。deepagents deployはそれをすべてパッケージ化して、チームが一から組み立てる必要をなくす。

agent-opsharness-designlangsmithproduction-agents
本番ディープエージェントを支えるランタイム設計——LangSmith Deployment完全解説
♥ 28↻ 4
原文を表示 / Show original
The runtime behind production deep agents
To build a good agent, you need a good harness. To deploy that agent, you need a good runtime.
The harness is the system you build around the model to help your agent be successful in its domain. That includes prompts, tools, skills, and anything else supporting the model and tool calling loop that defines an agent. The runtime is everything underneath: durable execution, memory, multi-tenancy, observability, the machinery that keeps an agent running in production without your team reinventing it.
This guide walks through the production requirements that surface once you deploy agents, the runtime capabilities that meet them, and how deepagents deploy packages those capabilities into something you can ship.
## Runtime capabilities for production agents
Throughout this section, "the runtime" refers to LangSmith Deployment (LSD) and its Agent Server: LSD runs agents in production, and Agent Server is the interface for assistants, threads, runs, memory, and scheduled jobs.
## Durable execution
Agents work by running a loop: Given a prompt, the model reasons, calls tools, observes the results, and repeats until it decides the task is complete.
Unlike a typical web request that returns in milliseconds, this loop can span minutes or hours. A single run might make dozens of model calls, spawn subagents, or wait indefinitely for a human to approve a draft.
In practice, you feel it in two places:
- Long runs need to survive infrastructure failures.
- Agents need to be able to stop and wait.
Agents run on a managed task queue with automatic checkpointing, so any run can be retried, replayed, or resumed from the exact point of interruption.
Each super-step of graph execution writes a checkpoint to the persistence layer (PostgreSQL by default), keyed by a thread_id that acts as a persistent cursor into the run.
## Memory
Agents need two different kinds of memory:
Short-term memory is what the agent accumulates within a single conversation. The messages exchanged, the tool calls made, the intermediate state built up across a run. This lives in the checkpoint for the thread, scoped to a thread_id.
Long-term memory is what the agent carries across conversations. This can include user preferences learned across conversations, project conventions and best practices, or a knowledge base enhanced with each new query. It's a key-value interface where memories are organized by namespace tuples (for example, (user_id, "memories")) and persisted across threads.
## Multi-tenancy
The moment your agent serves more than one user, a set of problems appears. These break down into three distinct concerns:
1. Isolating one user's data from another. Custom authentication runs as middleware on every request.
2. Letting the agent act on behalf of a user. Agent Auth handles the OAuth dance and token storage.
3. Controlling who can operate the system itself. RBAC handles this operator-level access control.
## Human-in-the-loop (HITL)
Agents work by running a loop. Most of the time you want that loop to run uninterrupted. But sometimes you need a human in the middle at key decision points.
There are two common situations:
- Reviewing a proposed tool call. Before the agent executes a consequential action.
- An agent asking a clarifying question.
The Agent Server handles this with two primitives: interrupt() pauses execution and surfaces a payload to the caller; Command(resume=...) continues it with the human's response.
## Real-time interaction
### Streaming
An agent that takes thirty seconds to produce a response leaves the user staring at a spinner. Streaming solves this: partial output flows to the client as the agent produces it.
The Streaming API supports several modes: full state snapshots after each graph step, state updates only, token-by-token LLM output, or custom application events.
Thread streaming supports resumption via the Last-Event-ID header: the client reconnects with the ID of the last event it received, and the server replays from there with no gaps.
### Double-texting
A user sends a new message while the agent is still working on the previous one. There are four strategies:
- enqueue (the default): The new input waits for the current run to finish.
- reject: Refuse any new input until the current run finishes.
- interrupt: Halt the current run, preserve progress, and process the new input from that state.
- rollback: Halt the current run, revert all progress, and process the new message as a fresh run.
## Guardrails
Not every production concern can be expressed as 'run the loop durably.' Some have to shape the loop itself: intercepting model inputs, filtering tool outputs, enforcing limits on expensive operations.
Both are handled by middleware, which wraps the agent loop at defined hooks—before_model, wrap_model_call, wrap_tool_call, after_model.
LangChain ships built-in middleware covering the common cases: PIIRedactionMiddleware, ModelRetryMiddleware, ModelFallbackMiddleware, ToolCallLimitMiddleware, SummarizationMiddleware, HumanInTheLoopMiddleware, OpenAIModerationMiddleware.
## Observability
You don't know what an agent will do in production until you run it. When something goes wrong, you need to see what actually happened.
Every LangSmith Deployment is automatically wired to a tracing project. You get the full execution tree out of the box—model calls, tool calls, subagent runs, middleware hooks.
Traces aren't just a debugging tool; they're the foundation of the improvement loop:
- Polly, the LangSmith AI assistant, analyzes traces and surfaces insights—common failure modes, slow tool calls, repeated patterns.
- Online Evals run LLM-as-judge or custom scorers against production traces automatically.
## Time travel
Observability tells you what happened. Time travel lets you ask what would have happened if something had gone differently.
Because every super-step writes a checkpoint, every point in a run's history is already a snapshot you can return to. Time travel makes this explicit: pick a checkpoint from a thread's history, optionally modify its state, and resume from there.
## Code execution
An agent that can only call the tools you pre-wired is limited to what you anticipated. An agent that can run arbitrary code is general-purpose.
Arbitrary code execution requires isolation. In Deep Agents, isolation happens through sandbox backends. Supported providers include Daytona, Modal, Runloop, and LangSmith Sandboxes.
LangSmith Sandboxes (currently in private preview) feature: warm pools that pre-provision sandboxes with automatic replenishment eliminating cold start latency, and the auth proxy that intercepts outbound requests and injects credentials from workspace secrets automatically.
## Integrations
The Agent Server provisions three integration surfaces automatically:
MCP: Every LangSmith Deployment automatically exposes an MCP endpoint, making your agent discoverable by any MCP-compliant client—Claude Desktop, IDEs, other agents.
A2A: Every deployment exposes an A2A (Agent-to-Agent) endpoint automatically. This makes multi-agent architectures across deployments tractable.
Webhooks: Pass a webhook URL when creating a run, and the server POSTs the run payload to that URL on completion.
## Cron
The Agent Server has cron jobs built in, so scheduled runs get the same durability, tracing, and auth guarantees as any other run.
Two flavors:
- Stateful cron (client.crons.create_for_thread): ties the schedule to a specific thread_id.
- Stateless cron (client.crons.create): spins up a fresh thread for each execution.
## deepagents deploy
deepagents deploy is the packaging step that deploys your agent on the runtime described above. You define your agent in deepagents.toml, and the CLI bundles your configuration and deploys it as a LangSmith Deployment.
## Open Harness
deepagents deploy is built to avoid vendor lock-in. The harness is MIT licensed and fully open source, agent instructions use AGENTS.md (an open standard), and agents are exposed via open protocols—MCP, A2A, Agent Protocol.
The capabilities this guide outlines—durable execution, memory, multi-tenancy, guardrails, human-in-the-loop, observability, sandboxed code execution, scheduled runs—are the infrastructure requirements production agents can't function without. deepagents deploy packages all of it so teams don't have to assemble it from scratch.