Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en/docs/integrations/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ candidate_review permits listing and reading candidates only; it never grants de
| pi | Agent host | Master only | minimal, recommended, full | best_effort | session_before_compact | memory_read<br>memory_write<br>source_capture<br>context_injection<br>flush_or_checkpoint<br>work_contract<br>handoff<br>acknowledge<br>task_outcome<br>experience_read_or_generate<br>skill_read_or_generate<br>candidate_review<br>external_skill<br>topic_memory_read<br>pre_compaction_capture<br>slash_command |
| workbuddy | Agent host | Master only | minimal, recommended, full | unsupported | — | memory_read<br>memory_write<br>source_capture<br>context_injection<br>flush_or_checkpoint<br>work_contract<br>handoff<br>acknowledge<br>task_outcome<br>candidate_review<br>experience_read_or_generate<br>skill_read_or_generate<br>external_skill<br>scope_organization<br>artifact_publication<br>persistent_scope_binding |
| zcode | Agent host | Master only | minimal, recommended, full | unsupported | — | flush_or_checkpoint<br>memory_read<br>memory_write<br>source_capture<br>context_injection<br>work_contract<br>handoff<br>acknowledge<br>task_outcome<br>candidate_review<br>experience_read_or_generate<br>skill_read_or_generate<br>external_skill<br>scope_organization<br>artifact_publication<br>persistent_scope_binding |
| deepagents | Framework adapter | Master only | — | — | — | source_capture<br>context_injection |
| pydantic-ai | Framework adapter | Experimental | — | — | — | memory_read<br>memory_write<br>context_injection |
| langchain | Framework adapter | Master only | — | — | — | source_capture<br>context_injection |
| langgraph | Framework adapter | Master only | — | — | — | memory_read<br>memory_write<br>context_injection |
Expand Down
144 changes: 144 additions & 0 deletions docs/en/docs/integrations/deepagents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
---
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 the built-in `general-purpose` subagent and every declarative subagent receive 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 adapter package; it depends on `powercontext-langchain` and `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/deepagents
```

## Create the agent

```python
from powercontext_langchain import PowerContextScope
from powercontext_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.
- The built-in `general-purpose` subagent receives one `PowerContextMiddleware(auto_capture=False)`; Deep Agents
would create that subagent without recall otherwise. A harness profile that disables it
(`GeneralPurposeSubagentProfile(enabled=False)`) is respected, including when the agent relies on Deep Agents'
deprecated default model, so opting into PowerContext does not re-enable delegation the application turned off.
- Each declarative subagent receives one `PowerContextMiddleware(auto_capture=False)` appended to its own
`middleware` list. An existing `PowerContextMiddleware(auto_capture=True)` is replaced by an equivalent
recall-only copy, so a delegated turn is never captured. The adapter copies the specification and the middleware;
the objects you pass are 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 subagent, including the built-in `general-purpose` one, 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 (21) run against scripted models and an in-process PowerContext Server over SQLite: middleware
injection, recall on declarative subagents and on the built-in `general-purpose` subagent, capture normalization for a
subagent that arrives with `auto_capture=True`, 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.
1 change: 1 addition & 0 deletions docs/en/docs/integrations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ All 3 adapters are `community`. Install them in the application environment; do
| --- | --- | --- |
| [Pydantic AI](pydantic-ai.md) | Toolset for Memory read/write and context | `experimental` |
| [LangChain](langchain.md) | Middleware for context and optional Source capture | `master_only` |
| [Deep Agents](deepagents.md) | Thin adapter adding recall to the agent and its subagents | `master_only` |
| [LangGraph](langgraph.md) | Recall hook and Memory tools | `master_only` |

## Evaluation integrations
Expand Down
1 change: 1 addition & 0 deletions docs/en/docs/integrations/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"---Python Agent frameworks---",
"pydantic-ai",
"langchain",
"deepagents",
"langgraph",
"---Evaluation and capabilities---",
"evaluation",
Expand Down
1 change: 1 addition & 0 deletions docs/zh/docs/integrations/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ candidate_review 仅可列举和读取候选材料,不授予决策权限。
| pi | Agent 宿主 | 仅 master | minimal, recommended, full | best_effort | session_before_compact | memory_read<br>memory_write<br>source_capture<br>context_injection<br>flush_or_checkpoint<br>work_contract<br>handoff<br>acknowledge<br>task_outcome<br>experience_read_or_generate<br>skill_read_or_generate<br>candidate_review<br>external_skill<br>topic_memory_read<br>pre_compaction_capture<br>slash_command |
| workbuddy | Agent 宿主 | 仅 master | minimal, recommended, full | unsupported | — | memory_read<br>memory_write<br>source_capture<br>context_injection<br>flush_or_checkpoint<br>work_contract<br>handoff<br>acknowledge<br>task_outcome<br>candidate_review<br>experience_read_or_generate<br>skill_read_or_generate<br>external_skill<br>scope_organization<br>artifact_publication<br>persistent_scope_binding |
| zcode | Agent 宿主 | 仅 master | minimal, recommended, full | unsupported | — | flush_or_checkpoint<br>memory_read<br>memory_write<br>source_capture<br>context_injection<br>work_contract<br>handoff<br>acknowledge<br>task_outcome<br>candidate_review<br>experience_read_or_generate<br>skill_read_or_generate<br>external_skill<br>scope_organization<br>artifact_publication<br>persistent_scope_binding |
| deepagents | 框架适配器 | 仅 master | — | — | — | source_capture<br>context_injection |
| pydantic-ai | 框架适配器 | 实验性 | — | — | — | memory_read<br>memory_write<br>context_injection |
| langchain | 框架适配器 | 仅 master | — | — | — | source_capture<br>context_injection |
| langgraph | 框架适配器 | 仅 master | — | — | — | memory_read<br>memory_write<br>context_injection |
Expand Down
135 changes: 135 additions & 0 deletions docs/zh/docs/integrations/deepagents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
---
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 完成,适配层只负责让内置的 `general-purpose`
subagent 和每个声明式 subagent 也拿到它。

Deep Agents 会自行组装 middleware 栈,并把每个声明式 subagent 编译成独立图,因此传给 `create_deep_agent` 的
middleware 只包住主 agent 的模型调用。经由 `context=` 传入的 `PowerContextScope` 仍会到达 subagent,因为 Deep Agents
会把父级 runtime context 转发给 `task` 工具。

## 安装

安装适配层包;它依赖 `powercontext-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/deepagents
```

## 创建 agent

```python
from powercontext_langchain import PowerContextScope
from powercontext_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`,则复用该实例,不再重复添加。
- 内置的 `general-purpose` subagent 会获得一个 `PowerContextMiddleware(auto_capture=False)`;否则 Deep Agents 会
在不带召回的情况下创建该 subagent。若 harness profile 禁用了它(`GeneralPurposeSubagentProfile(enabled=False)`),
适配层会尊重该配置(包括使用 Deep Agents 已弃用默认模型的情况),不会因为接入 PowerContext 而重新开启应用已关闭的
委派能力。
- 每个声明式 subagent 的 `middleware` 列表末尾追加一个 `PowerContextMiddleware(auto_capture=False)`。已有的
`PowerContextMiddleware(auto_capture=True)` 会被替换为等价的 recall-only 副本,因此被委派的轮次绝不会被采集。
适配层会复制规格与 middleware,不会修改调用方传入的对象。
- `context_schema` 默认取 `PowerContextScope`。传入其他值时原样转发,此时该 agent 的 PowerContext 回退到环境变量
配置。

## Subagent

召回与采集刻意不对称:

- **召回**同时运行在主 agent 和每个 subagent(包括内置的 `general-purpose`)中,使用 `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 只依赖召回。

## 已验证版本

21 个确定性测试基于脚本模型和进程内 PowerContext Server(SQLite)运行,覆盖:中间件注入、声明式 subagent 与内置
`general-purpose` subagent 的召回、对自带 `auto_capture=True` 的 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 的托管部署。
1 change: 1 addition & 0 deletions docs/zh/docs/integrations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Cookie 属性和折行续接内容,再匹配普通赋值。这种保守处理
| --- | --- | --- |
| [Pydantic AI](pydantic-ai.md) | Toolset:Memory 读写和上下文 | `experimental` |
| [LangChain](langchain.md) | Middleware:上下文和可选 Source 采集 | `master_only` |
| [Deep Agents](deepagents.md) | 薄适配层:为主 agent 与 subagent 增加召回 | `master_only` |
| [LangGraph](langgraph.md) | Recall hook 和 Memory 工具 | `master_only` |

## 评测集成
Expand Down
1 change: 1 addition & 0 deletions docs/zh/docs/integrations/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"---Python Agent 框架---",
"pydantic-ai",
"langchain",
"deepagents",
"langgraph",
"---评测与能力---",
"evaluation",
Expand Down
Loading
Loading