Pydantic AI、バウンの書き換えを可能にした動的ワークフロー機能を公開
本文の状態
日本語全文を表示中
詳細モードで約5分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
Pydantic Blog
Pydantic は、Bun の Rust 化を主導した Jarred Suggiss の成功事例に触発され、エージェントが他のエージェントの計画を立てる動的ワークフロー機能を公式に導入し、複雑なタスクのオーケストレーションを容易にした。
AI深層分析を開く2026年8月4日 01:21
AI深層分析
キーポイント
Bun リライト事例の分析
Jarred Suggiss は約 50 万行の Zig コードを Rust に移植し、11 日間で完了したが、その成功はエージェントが互いに計画を立てる動的ワークフローによるものだった。
DynamicWorkflow の新機能
Pydantic AI は従来の Code Mode を上位概念として拡張し、モデルにエージェントカタログを渡すことで、サブエージェントの呼び出しやループ処理を可能にする動的ワークフロー機能を正式に提供した。
実装メカニズム
オーケストレーターエージェントは単一のツール呼び出し内で Python スクリプトを記述し、非同期関数として定義されたサブエージェントを結合・ループさせることで複雑な処理を実行する。
スワーム型アーキテクチャの実現
この機能により、複数のエージェントが並列または連鎖的に動作し、結果は最終行のみがコンテキストに返されるため、大規模なコードレビューや分析タスクの自動化が可能になる。
動的なエージェントの公開とキャッシュ維持
実行中に新しいエージェント(例:potato)を workflow.reveal() で公開すると、モデルは次のステップで即座に呼び出せるようになる。この際、関数のシグネチャを示す短いノートを通じて発見されるため、ツールの説明が変更されずキャッシュが破綻しない。
重要な引用
Models are pretty good at orchestrating more of themselves.
DynamicWorkflow is Code Mode moved up a level.
You hand it a catalog of named agents. It hands the model a single tool.
The model finds out through a short note carrying the new function's signature, and the tool's own description never changes, so the reveal doesn't bust the cache.
編集コメントを表示
編集コメント
Bun の Rust リライト事例は、単なるコード変換ではなく、AI エージェントが自律的にタスクを分割・連携する能力の証明として注目される。Pydantic がこの知見を実装に落とし込み、開発者が容易にスワーム型システムを構築できる環境を提供した点は、実務における AI 活用アプローチの転換点となるだろう。
Source Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
要約:モデルは自分自身をオーケストレーションする能力が非常に高いです。Pydantic AI の DynamicWorkflows を使えば、エージェントの群れを簡単に構築できます。
Bun は Rust で書き直されました。Jarred 氏は「Rust で書き直せ」という要望を真に受けてくれました。
そして、皆が待ち望んでいたブログ記事が公開されました。私にとって特に印象的だったのは以下の点です。
Dynamic Workflows(動的ワークフロー)
Jarred は驚異的な開発者でした(誰が予想できたでしょうか)。
Jarred 氏が実際に行ったこと
数字は誇張されているかもしれませんが、敢えて引用します。Zig から Rust への移植で約 50 万行のコードを扱い、差分は 100 万行を超えました。既存のテストスイートは 100% 合格し、初回コミットからマージまでわずか 11 日でした。
Jarred 氏が「おい、メモリエラーが多すぎるぞ、Rust でやってくれないか?」とプロンプトした姿を想像したくなりますが、実際のワークフローはもっと複雑でした。
彼は、エージェントが他のエージェントの計画を書くようなワークフローを設定しました。あるワークフローでは各構造体のフィールドに対する Rust のライフタイムを特定し、別のワークフローではファイルの移植を行いました。11 日間で約 50 のワークフローが実行され、ピーク時には同時に 64 台の Claude が稼働していました。すべてのファイルは 2 つの敵対的なエージェントによってレビューされました。イメージは湧いたでしょうか。
これをループで回せば、Bun の Rust 版が完成します。
驚くべきことに、モデルは自分自身をオーケストレーションする能力に非常に優れていることが分かりました。
Pydantic AI でも同じことができるのか?
はい。もちろん可能です!
すでにかなり近いところまで到達していました。Code Mode は以前から存在しており、メニューからツールを一つずつ選択するのではなく、モデルがそれらを呼び出す Python スクリプトを書くことで実現しています。エージェントをツールとして連携させれば、その方向への道筋は得られます。
しかし、もうそのような下準備(プラムビング)をする必要はありません。Dynamic Workflows は、Pydantic AI Harness においてファーストクラス機能として実装されました。
#仕組みはどうなっているのか?
DynamicWorkflow は、Code Mode を一段階上位に引き上げたものです。Code Mode がモデルに対してツールのスクリプトを提供するのに対し、DynamicWorkflow はエージェントのスクリプトを提供します。
名前付きのエージェントカタログを手渡すと、モデルには単一のツールが提供されます。そのツール内部では、モデルは通常の Python コードを記述します。ここで各サブエージェントは、呼び出したりループさせたり組み合わせたりできる非同期関数となります。さらに、グラフ構造として構築することも可能です(ご存知の方ならお分かりいただけるでしょう)。スクリプト全体は一度のツール呼び出しで実行され、コンテキストに返されるのは最終行のみです。
実装例は以下のようになります:
import logfire
from pydantic_ai import Agent
from pydantic_ai_harness.experimental.dynamic_workflow import DynamicWorkflow
logfire.configure()
logfire.instrument_pydantic_ai()
reviewer = Agent('anthropic:claude-sonnet-5', name='reviewer', description='Reviews code for bugs.')
summarizer = Agent('anthropic:claude-sonnet-5', name='summarizer', description='Summarizes findings.')
orchestrator = Agent(
'anthropic:claude-opus-4-8',
capabilities=[DynamicWorkflow(agents=[reviewer, summarizer])],
)
ランタイムでオーケストレーターが生成するスクリプトは、以下のような形になります。結果を並列実行し、チェーン化して最終的な成果物だけを残す仕組みです。
import asyncio
reports = await asyncio.gather(
reviewer(task="Review auth.py for bugs:
"),
reviewer(task="Review parser.py for bugs:
"),
)
await summarizer(task="Summarize these findings:
" + "\n".join(reports))実行中にエージェントを可視化したい場合も安心してください。
workflow = DynamicWorkflow(agents=[reviewer])
orchestrator = Agent('anthropic:claude-opus-4-8', capabilities=[workflow])
# 後で、ポテトエージェントがプロビジョニングされたら:
workflow.reveal(potato)次のステップですぐに呼び出せるようになります。モデルは新しい関数のシグネチャを伝える短い通知を通じてその存在を知り、ツールの説明自体は変更されないため、キャッシュも破綻しません。
エージェントの動きを見守ろう
すべてのエージェント実行とモデル呼び出しは、同じ OpenTelemetry トレースに記録されます。run_workflow スパンにはモデルが生成したスクリプトが含まれているため、実際に何を実行したかを直接確認できます。
トレーシングなしで複数のエージェントを走らせるのは、単に高価な方法でノイズ(slop)を生み出すだけです。その方が好きなら構いませんが、私はデバッグ可能なシステムを選びます。
試してみよう
uv add "pydantic-ai-harness[dynamic-workflow]"オーケストレーターをいくつかのエージェント(あるいは数百個)に指向させ、単一のコンテキストでは処理しきれないタスクを与えてみてください。すると、オーケストレーターが自らワークフローを記述する様子が見られます。その後、Logfire でそれを開いて、群れがどのように連携して動くかを確認しましょう。
もし自分でオーケストレーションの接着剤を手作業で作る手間を省けるなら、GitHub でスターを獲得することは、他の人がこのプロジェクトを見つけやすくなる助けになります。
原文を表示
TL;DR: Models are pretty good at orchestrating more of themselves. With Pydantic AI DynamicWorkflows you can easily create your swarm of agents.
Bun got rewritten in Rust. Jarred took "Rewrite it in Rust bro" quite seriously.
Then he published the blog post everyone was waiting for. A couple of things stood out to me.
Dynamic Workflows
Jarred being a cracked dev (who would have guessed)
#What Jarred actually did
The numbers are silly, but I will cite them anyway. Half a million lines of Zig ported, a diff of just over a million lines. 100% of the existing test suite still passing Eleven days from first commit to merge.
I would love to imagine Jarred prompting, "Yo dawg too many memory errors, can we do this in Rust?".
The actual workflow however was more nuanced.
He set up workflows where agents wrote plans for other agents. One workflow figured out Rust lifetimes for every struct field, another ported files. About 50 of these workflows ran over the 11 days, 64 Claudes at a time at peak, every file reviewed by two adversarial agents, you get the picture.
Do this in a loop and there you have it, Bun in Rust.
Models, it turns out, are pretty damn good at orchestrating more of themselves.
#Can I get some of that in Pydantic AI?
Yes. Absolutely!
You could already get pretty close. We've had Code Mode for a while: instead of picking tools off a menu one call at a time, the model writes a Python script that calls them. Wire your agents in as tools, and you'd get part of the way there.
You don't have to do that plumbing anymore. Dynamic workflows are now a first-class capability in the Pydantic AI Harness.
#How does it work?
DynamicWorkflow is Code Mode moved up a level. Code Mode gives the model a script for its tools. DynamicWorkflow gives it a script for its agents.
You hand it a catalog of named agents. It hands the model a single tool. Inside that tool the model writes ordinary Python, where each sub-agent is an async function it can call, loop over, and combine or even graph(if you know you know). The whole script runs in one tool call, and only the last line finds its way back into context.
It looks something like this:
import logfire
from pydantic_ai import Agent
from pydantic_ai_harness.experimental.dynamic_workflow import DynamicWorkflow
logfire.configure()
logfire.instrument_pydantic_ai()
reviewer = Agent('anthropic:claude-sonnet-5', name='reviewer', description='Reviews code for bugs.')
summarizer = Agent('anthropic:claude-sonnet-5', name='summarizer', description='Summarizes findings.')
orchestrator = Agent(
'anthropic:claude-opus-4-8',
capabilities=[DynamicWorkflow(agents=[reviewer, summarizer])],
)
The script the orchestrator writes at runtime looks something like this. It fans out, chains the results, and only the result survives:
import asyncio
reports = await asyncio.gather(
reviewer(task="Review auth.py for bugs:\n<file contents>"),
reviewer(task="Review parser.py for bugs:\n<file contents>"),
)
await summarizer(task="Summarize these findings:\n" + "\n\n".join(reports))
#Need to reveal agents during the run?
We got you.
workflow = DynamicWorkflow(agents=[reviewer])
orchestrator = Agent('anthropic:claude-opus-4-8', capabilities=[workflow])
later, once a potato agent has been provisioned:
workflow.reveal(potato)
potato becomes callable on the very next step. The model finds out through a short note carrying the new function's signature, and the tool's own description never changes, so the reveal doesn't bust the cache.
#Watch your agents
Every agent run and model call lands on the same OpenTelemetry trace. The run_workflow span carries the script the model wrote, so you can read what actually ran.
Running multiple agents with no trace is just an expensive way to generate slop. No judgment if you prefer the heartache, but I would much rather have a system I can debug.
#Try it out
uv add "pydantic-ai-harness[dynamic-workflow]"
Point an orchestrator at a couple of agents (or a few hundred), hand it a task that's too big for one context, and watch it write its own workflow. Then open it up in Logfire and watch the swarm work.
If it saves you from hand-rolling your own orchestration glue, a star on GitHub helps other people find it.
関連記事
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み