Repository navigation
feat(integrations): add a Deep Agents adapter #2684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hidb4ai
merged 8 commits into
oceanbase:master
from
Lumea-art:feat/deepagents-integration
Nov 21, 2026
+1,900
−32
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
eafbda4
feat(integrations): add Deep Agents adapter
Lumea-art 9330ff1
test(integrations): cover streaming, interrupt and scope isolation fo…
Lumea-art 8214788
docs(integrations): record real-model streaming, interrupt and extrac…
Lumea-art 7468ec5
docs(integrations): record successful extraction and semantic recall …
Lumea-art e6bc3d4
docs(integrations): add a runnable capture, extraction and recall exa…
Lumea-art bd245a2
fix(deepagents): install recall on the built-in subagent and normaliz…
Lumea-art aae2e71
fix(deepagents): respect a profile that disables the default subagent
Lumea-art 1969426
fix(deepagents): resolve the default model before honoring a disabled…
Lumea-art File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| --- | ||
| title: Deep Agents | ||
| description: Add bounded PowerContext recall to a Deep Agents agent and its declarative subagents. | ||
| status: community | ||
| --- | ||
|
|
||
| # Deep Agents | ||
|
|
||
| `community` | ||
|
|
||
| `create_powercontext_deep_agent` connects a [Deep Agents](https://github.com/langchain-ai/deepagents) | ||
| `create_deep_agent` agent to a separately running PowerContext Server. It is a thin adapter over | ||
| `PowerContextMiddleware` from `powercontext-langchain`: the middleware still performs recall and optional capture, and | ||
| the adapter only ensures every declarative subagent receives it too. | ||
|
|
||
| Deep Agents composes its own middleware stack and compiles each declarative subagent as a separate graph, so a | ||
| middleware passed to `create_deep_agent` wraps only the main agent's model calls. Passing `PowerContextScope` through | ||
| `context=` still reaches subagents, because Deep Agents forwards the parent runtime context to the `task` tool. | ||
|
|
||
| ## Install | ||
|
|
||
| Install the LangChain integration first; the adapter ships in the same package and imports `deepagents` lazily. | ||
|
|
||
| ```bash | ||
| uv tool install --force "powercontext[cli,server] @ git+https://github.com/oceanbase/powercontext.git@master" | ||
| powercontext server run | ||
| ``` | ||
|
|
||
| ```bash | ||
| uv pip install ./integrations/langchain | ||
| uv pip install "deepagents>=0.7,<0.8" | ||
| ``` | ||
|
|
||
| ## Create the agent | ||
|
|
||
| ```python | ||
| from powercontext_langchain import PowerContextScope | ||
| from powercontext_langchain.deepagents import create_powercontext_deep_agent | ||
|
|
||
| agent = create_powercontext_deep_agent( | ||
| model, | ||
| tools=application_tools, | ||
| system_prompt="You are a deployment assistant.", | ||
| subagents=[ | ||
| { | ||
| "name": "researcher", | ||
| "description": "Reads the repository and reports deployment steps.", | ||
| "system_prompt": "You research deployment steps.", | ||
| } | ||
| ], | ||
| auto_capture=True, | ||
| ) | ||
|
|
||
| result = await agent.ainvoke( | ||
| {"messages": [{"role": "user", "content": "How should we deploy this service?"}]}, | ||
| context=PowerContextScope(), | ||
| ) | ||
| ``` | ||
|
|
||
| `create_powercontext_deep_agent` forwards every other keyword argument to `create_deep_agent`, including `backend`, | ||
| `checkpointer`, `store`, `interrupt_on`, and `response_format`. | ||
|
|
||
| ## What the adapter changes | ||
|
|
||
| - The main agent receives one `PowerContextMiddleware(auto_capture=...)`. An existing `PowerContextMiddleware` in | ||
| `middleware=` is reused instead of duplicated. | ||
| - Each declarative subagent receives one `PowerContextMiddleware(auto_capture=False)` appended to its own | ||
| `middleware` list. The adapter copies the specification; the mapping you pass is not mutated. | ||
| - `context_schema` defaults to `PowerContextScope`. Any other value you pass is forwarded unchanged, and PowerContext | ||
| then falls back to its environment settings for that agent. | ||
|
|
||
| ## Subagents | ||
|
|
||
| Recall and capture are deliberately asymmetric: | ||
|
|
||
| - **Recall** runs in the main agent and in every declarative subagent, using the scope from `context=`. A delegated | ||
| task therefore sees the same bounded history as its parent. | ||
| - **Capture** stays on the main agent. Subagents run with `auto_capture=False`, so a delegated turn is stored once, | ||
| by the parent, even when several subagents run during the same turn. | ||
|
|
||
| Compiled subagents (`{"name": ..., "runnable": ...}`) and remote `AsyncSubAgent` specifications own their graph and | ||
| are returned unchanged. Add `PowerContextMiddleware` inside those graphs explicitly; the adapter does not reach into | ||
| them. | ||
|
|
||
| Recalled context still modifies only the current `ModelRequest`. It never enters agent state, the checkpointer, or a | ||
| subagent's transcript, and it cannot accumulate across repeated model calls or context compaction. | ||
|
|
||
| ## Configure connection and scope | ||
|
|
||
| The adapter reuses the LangChain integration's client, settings, and Scope. See | ||
| [LangChain](langchain.md#configure-connection-and-scope) for `POWERCONTEXT_LANGCHAIN_*` variables, token handling, | ||
| remote-Server consent, and the rule that an explicit `PowerContextScope` wins over environment configuration. | ||
|
|
||
| ## Capture | ||
|
|
||
| `auto_capture` defaults to `False`. When enabled, a successful main-agent run captures the latest user message and | ||
| final non-empty assistant response through `/v1/sources/content`; the normal Source-to-Memory extraction happens later. | ||
| Failed, cancelled, interrupted, or resumed runs are not captured, and retries do not create a second Source for the | ||
| same turn because the Source identity is derived from the scope and the turn text. | ||
|
|
||
| ## Failure behavior | ||
|
|
||
| Recall and capture are best-effort. An unavailable Server, an invalid response, or request validation failure does not | ||
| replace the model response or stop the agent. HTTP 401 and 403 are logged once at error level without content or token | ||
| values; other failures are logged at debug level. | ||
|
|
||
| ## Runnable examples | ||
|
|
||
| `integrations/deepagents/examples/quickstart.py` runs one captured turn against a Server and an OpenAI-compatible | ||
| model endpoint. `integrations/deepagents/examples/full_flow.py` also flushes the captured turn into Memory, waits for | ||
| the extracted entry to become searchable, and asks a paraphrased question in a new session. The full flow needs a | ||
| generation model and an embedding model configured on the Server; the quickstart only needs recall. | ||
|
|
||
| ## Validated versions | ||
|
|
||
| Deterministic tests (14) run against scripted models and an in-process PowerContext Server over SQLite: middleware | ||
| injection, subagent recall, single-capture ownership, streaming (`astream`), interrupt/resume, repeated model calls | ||
| without context accumulation, and Scope isolation between runs. | ||
|
|
||
| A real-model run used PowerContext Server 0.1.dev1 (HTTP + SQLite), `deepagents` 0.7.39, `langchain` 1.5.0, | ||
| `langchain-core` 1.8.1, `langchain-openai` 1.8.0, and vLLM 0.29.0 serving Qwen2.5-0.5B-Instruct: | ||
|
|
||
| - recall reached the system prompt and the answer followed the stored rule; | ||
| - `auto_capture=True` added one Source for the completed turn; | ||
| - a later turn in the same Scope recalled the rule again. | ||
|
|
||
| Streaming and interrupt/resume were also exercised with that real model: `astream` delivered 17 chunks and stored one | ||
| Source, and an `interrupt_on` run paused before the tool, then stored exactly one Source after | ||
| `Command(resume={"decisions": [{"type": "approve"}]})`. | ||
|
|
||
| Automatic Source-to-Memory extraction and semantic recall were validated with two vLLM-served models: Qwen3-4B for | ||
| generation and bge-small-en-v1.5 (`--runner pooling`) for embeddings. A captured turn was flushed into Memory, and a | ||
| paraphrased query ("What deployment command should we use?") returned a non-empty prepared context that the agent | ||
| recalled in a new session. With only Qwen2.5-0.5B or Qwen3-0.6B the extraction produced an unusable or empty result, | ||
| so these models are too small for the extraction schema. | ||
|
|
||
| JavaScript and Managed Deep Agents were not exercised: the JavaScript `deepagents` package exists (1.16.5) but | ||
| PowerContext ships no JavaScript adapter, and Managed Deep Agents is a hosted LangSmith deployment. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| --- | ||
| title: Deep Agents | ||
| description: 为 Deep Agents agent 及其声明式 subagent 增加有界 PowerContext 召回。 | ||
| status: community | ||
| --- | ||
|
|
||
| # Deep Agents | ||
|
|
||
| `community` | ||
|
|
||
| `create_powercontext_deep_agent` 把 [Deep Agents](https://github.com/langchain-ai/deepagents) 的 | ||
| `create_deep_agent` agent 连接到单独运行的 PowerContext Server。它只是 `powercontext-langchain` 中 | ||
| `PowerContextMiddleware` 的薄适配层:召回和可选采集仍由 middleware 完成,适配层只负责让每个声明式 subagent 也拿到它。 | ||
|
|
||
| Deep Agents 会自行组装 middleware 栈,并把每个声明式 subagent 编译成独立图,因此传给 `create_deep_agent` 的 | ||
| middleware 只包住主 agent 的模型调用。经由 `context=` 传入的 `PowerContextScope` 仍会到达 subagent,因为 Deep Agents | ||
| 会把父级 runtime context 转发给 `task` 工具。 | ||
|
|
||
| ## 安装 | ||
|
|
||
| 先安装 LangChain 集成;适配层位于同一个包中,并以延迟导入的方式使用 `deepagents`。 | ||
|
|
||
| ```bash | ||
| uv tool install --force "powercontext[cli,server] @ git+https://github.com/oceanbase/powercontext.git@master" | ||
| powercontext server run | ||
| ``` | ||
|
|
||
| ```bash | ||
| uv pip install ./integrations/langchain | ||
| uv pip install "deepagents>=0.7,<0.8" | ||
| ``` | ||
|
|
||
| ## 创建 agent | ||
|
|
||
| ```python | ||
| from powercontext_langchain import PowerContextScope | ||
| from powercontext_langchain.deepagents import create_powercontext_deep_agent | ||
|
|
||
| agent = create_powercontext_deep_agent( | ||
| model, | ||
| tools=application_tools, | ||
| system_prompt="You are a deployment assistant.", | ||
| subagents=[ | ||
| { | ||
| "name": "researcher", | ||
| "description": "Reads the repository and reports deployment steps.", | ||
| "system_prompt": "You research deployment steps.", | ||
| } | ||
| ], | ||
| auto_capture=True, | ||
| ) | ||
|
|
||
| result = await agent.ainvoke( | ||
| {"messages": [{"role": "user", "content": "How should we deploy this service?"}]}, | ||
| context=PowerContextScope(), | ||
| ) | ||
| ``` | ||
|
|
||
| 其余关键字参数会原样转发给 `create_deep_agent`,包括 `backend`、`checkpointer`、`store`、`interrupt_on` 和 | ||
| `response_format`。 | ||
|
|
||
| ## 适配层做了什么 | ||
|
|
||
| - 主 agent 获得一个 `PowerContextMiddleware(auto_capture=...)`。如果 `middleware=` 中已有 | ||
| `PowerContextMiddleware`,则复用该实例,不再重复添加。 | ||
| - 每个声明式 subagent 的 `middleware` 列表末尾追加一个 `PowerContextMiddleware(auto_capture=False)`。适配层会复制 | ||
| 规格,不会修改调用方传入的映射。 | ||
| - `context_schema` 默认取 `PowerContextScope`。传入其他值时原样转发,此时该 agent 的 PowerContext 回退到环境变量 | ||
| 配置。 | ||
|
|
||
| ## Subagent | ||
|
|
||
| 召回与采集刻意不对称: | ||
|
|
||
| - **召回**同时运行在主 agent 和每个声明式 subagent 中,使用 `context=` 中的 scope。被委派的任务因此能看到与父级 | ||
| 相同的有界历史。 | ||
| - **采集**只保留在主 agent。subagent 以 `auto_capture=False` 运行,因此一轮委派只会由父级记录一次,即使同一轮 | ||
| 中运行了多个 subagent。 | ||
|
|
||
| 编译型 subagent(`{"name": ..., "runnable": ...}`)和远程 `AsyncSubAgent` 规格自己持有图,适配层原样返回,不 | ||
| 会介入。需要时请在这些图中显式加入 `PowerContextMiddleware`。 | ||
|
|
||
| 召回内容仍然只修改当前 `ModelRequest`,不会进入 agent state、checkpointer 或 subagent 的对话记录,也不会在重复 | ||
| 模型调用或上下文压缩之间累积。 | ||
|
|
||
| ## 配置连接与 scope | ||
|
|
||
| 适配层复用 LangChain 集成的 Client、Settings 和 Scope。`POWERCONTEXT_LANGCHAIN_*` 变量、token 处理、远程 Server | ||
| 授权,以及“显式 `PowerContextScope` 优先于环境配置”的规则,见 [LangChain](langchain.md#配置连接与-scope)。 | ||
|
|
||
| ## 采集 | ||
|
|
||
| `auto_capture` 默认为 `False`。开启后,主 agent 成功结束时会通过 `/v1/sources/content` 采集最新用户消息和最终 | ||
| 非空回答;正常的 Source 到 Memory 提取稍后由调度器执行。失败、取消、中断或恢复的运行不会被采集;重试也不会为 | ||
| 同一轮生成第二个 Source,因为 Source 标识由 scope 与该轮文本派生。 | ||
|
|
||
| ## 失败行为 | ||
|
|
||
| 召回和采集都是尽力而为。Server 不可用、响应非法或请求校验失败都不会替换模型响应,也不会中断 agent。HTTP 401 | ||
| 和 403 会以 error 级别记录一次,且不包含内容或 token 值;其他失败以 debug 级别记录。 | ||
|
|
||
| ## 可运行示例 | ||
|
|
||
| `integrations/deepagents/examples/quickstart.py` 针对一个 Server 和 OpenAI 兼容的模型端点跑一轮采集。 | ||
| `integrations/deepagents/examples/full_flow.py` 会进一步把采集到的轮次 flush 成 Memory,等待提取结果可检索,再在新 | ||
| 会话里提出一个改写后的问题。完整流程要求 Server 配置生成模型与 embedding 模型;quickstart 只依赖召回。 | ||
|
|
||
| ## 已验证版本 | ||
|
|
||
| 14 个确定性测试基于脚本模型和进程内 PowerContext Server(SQLite)运行,覆盖:中间件注入、subagent 召回、单次采集 | ||
| 归属、流式 `astream`、中断/恢复、重复模型调用不累积上下文,以及不同运行之间的 Scope 隔离。 | ||
|
|
||
| 真实模型验证使用 PowerContext Server 0.1.dev1(HTTP + SQLite)、`deepagents` 0.7.39、`langchain` 1.5.0、 | ||
| `langchain-core` 1.8.1、`langchain-openai` 1.8.0,以及 vLLM 0.29.0 上的 Qwen2.5-0.5B-Instruct: | ||
|
|
||
| - 召回内容进入 system prompt,回答遵循了已存储的规则; | ||
| - `auto_capture=True` 为该轮新增了一个 Source; | ||
| - 同一 Scope 下的后续轮次再次召回了该规则。 | ||
|
|
||
| 流式与中断/恢复也用同一真实模型验证:`astream` 产出 17 个 chunk 并写入 1 个 Source;`interrupt_on` 的运行在工具 | ||
| 执行前暂停,`Command(resume={"decisions": [{"type": "approve"}]})` 之后恰好写入 1 个 Source。 | ||
|
|
||
| 自动的 Source 到 Memory 提取与语义召回用两个 vLLM 服务的模型完成了验证:生成用 Qwen3-4B,embedding 用 | ||
| bge-small-en-v1.5(`--runner pooling`)。被采集的轮次经 flush 提取为 Memory,改写后的查询("What deployment command | ||
| should we use?")返回了非空的 prepared context,agent 在新会话中召回了它。只用 Qwen2.5-0.5B 或 Qwen3-0.6B 时提取 | ||
| 结果为不可用或为空,说明这两个模型不足以满足提取 schema。 | ||
|
|
||
| JavaScript 与 Managed Deep Agents 未验证:JavaScript 的 `deepagents` 包存在(1.16.5),但 PowerContext 没有 | ||
| JavaScript 适配层;Managed Deep Agents 是 LangSmith 的托管部署。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.