Skip to content

feat(integrations): add a Deep Agents adapter - #2684

Merged
hidb4ai merged 8 commits into
oceanbase:masterfrom
Lumea-art:feat/deepagents-integration
Nov 21, 2026
Merged

hidb4ai merged 8 commits into
oceanbase:masterfrom
Lumea-art:feat/deepagents-integration

Conversation

@Lumea-art

Copy link
Copy Markdown
Contributor

Which issue or RFC does this PR close?

Closes #2680. The JavaScript and Managed Deep Agents assessment stays out of this PR, as the issue requests.

Rationale for this change

create_deep_agent compiles every declarative subagent as a separate graph, so a middleware passed to
create_deep_agent wraps only the main agent's model calls: subagents would silently run without recall. Deep Agents
does forward the parent runtime context to the task tool, so PowerContextScope reaches subagents unchanged — no
scope plumbing is needed, only middleware.

A thin adapter is enough. It installs PowerContextMiddleware on the main agent and a recall-only copy on each
declarative subagent, which keeps capture on the main agent so a delegated turn is stored once.

What changes are included in this PR?

  • New powercontext-deepagents package under integrations/deepagents:
    • create_powercontext_deep_agent: create_deep_agent plus PowerContext middleware and a default
      context_schema=PowerContextScope;
    • powercontext_deep_agent_middleware: reuses an existing PowerContextMiddleware, otherwise appends one with the
      requested auto_capture;
    • powercontext_subagents: copies declarative specs and appends a recall-only middleware; compiled (runnable)
      and remote (graph_id) subagents are returned unchanged.
  • English and Chinese guides, the integration index, meta.json, the capability inventory, and the manifest probe.
  • dev dependency group, [tool.uv.sources], and uv.lock entries for the new package.
  • 14 tests and two runnable examples (quickstart.py, full_flow.py).

Are there any user-facing changes?

Additive only. The new package is optional, existing LangChain and LangGraph integrations are unchanged, and no Server
API changes are required. Deep Agents users gain bounded recall on the main agent and on declarative subagents, plus
opt-in completed-turn capture with a single Source per delegated turn.

How was this change tested?

  • Deterministic tests (14) over scripted models and an in-process PowerContext Server with SQLite: middleware
    injection and de-duplication, subagent recall, capture ownership, astream, interrupt/resume capture, repeated
    model calls without context accumulation, and Scope isolation between runs.
  • Real-model validation with vLLM 0.29.0, deepagents 0.7.39, langchain 1.5.0, langchain-core 1.8.1, and
    langchain-openai 1.8.0 against a standalone PowerContext Server 0.1.dev1 (HTTP + SQLite):
    • Qwen2.5-0.5B: recall reached the system prompt, capture stored one Source, a later turn recalled it; astream
      delivered 17 chunks with one Source; interrupt_on paused before the tool and stored one Source after resume.
    • Qwen3-4B with bge-small-en-v1.5 (--runner pooling): a captured turn was flushed into Memory and a paraphrased
      query returned a non-empty prepared context that the agent recalled. Qwen2.5-0.5B and Qwen3-0.6B returned an
      unusable or empty extraction result, so the docs record that a 4B-class model is required for extraction.
  • Commands: pytest tests/deepagents_adapter tests/langchain_middleware tests/test_integration_manifest.py
    (86 passed, 1 skipped), ruff check, ruff format --check,
    python scripts/generate_integration_manifest_docs.py --check.

AI usage statement

Built with an AI coding assistant (DeepSeek Harness). Every change was reviewed and executed locally against real
vLLM and PowerContext servers; the observed results, including the small-model extraction failures, are recorded in
the integration guides.

create_deep_agent compiles every declarative subagent as a separate graph, so a
middleware passed to it wraps only the main agent's model calls. The new
powercontext-deepagents package installs PowerContextMiddleware on the main
agent and a recall-only copy on each declarative subagent, and keeps
auto_capture on the main agent so a delegated turn is stored once.
PowerContextScope reaches subagents through the parent runtime context, so
recall uses the same scope everywhere.

Compiled and remote subagents own their graph; the adapter returns them
unchanged and documents that their middleware must be added inside the graph.

Tests cover middleware injection, subagent recall, single-capture ownership,
an in-process Server recall for both the main agent and a delegated subagent,
and the capability manifest entry.
…r Deep Agents

Add regression coverage for the acceptance paths the adapter contract depends
on: astream recall with a single capture, interrupt/resume capture ownership,
repeated model calls without context accumulation, and Scope isolation between
runs.

Add a runnable example that connects to a real Server and an OpenAI-compatible
endpoint, and record the real-model validation results (Deep Agents 0.7.39,
LangChain 1.5.0, PowerContext Server 0.1.dev1, vLLM 0.29 serving
Qwen2.5-0.5B) in both documentation locales.
…tion results for Deep Agents

Streaming and interrupt/resume now have real-model evidence (astream: 17 chunks,
one Source; interrupt_on: paused, resumed, one Source). Automatic Source-to-Memory
extraction was attempted against local 0.5B/0.6B models and produced no Memory:
the 0.5B model returned a structured result the Server rejected and the 0.6B model
returned an empty candidate list, so extraction and semantic ranking remain
unvalidated without a larger generation model and an embedding model.
…for Deep Agents

Validation used vLLM-served Qwen3-4B for generation and bge-small-en-v1.5 for
embeddings: a captured turn flushed into Memory and a paraphrased query returned
a non-empty prepared context that the agent recalled in a new session. Record
that 0.5B/0.6B models are too small for the extraction schema.
…mple for Deep Agents

full_flow.py captures one turn, flushes it into Memory, waits for the extracted
entry, and asks a paraphrased question in a new session; the guide and package
README explain when the Server also needs an embedding model.
@CLAassistant

CLAassistant commented Nov 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@AlexStocks AlexStocks added the 1.6.0 v1.6.0 release tracking label Nov 17, 2026

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The adapter leaves the default delegated agent without recall, does not enforce its parent-only capture contract for existing subagent middleware, and the published setup instructions import a nonexistent module. Please address the three inline findings before merging.

Comment thread docs/en/docs/integrations/deepagents.md Resolved
…e capture

Three review findings:

- Deep Agents creates a general-purpose subagent when no spec uses that name,
  and the adapter returned None, so default delegation ran without recall. Always
  supply that spec (built-in description and prompt; parent model, tools and
  interrupt_on stay inherited) with recall-only middleware; a caller-supplied or
  compiled spec with that name is kept instead of duplicated.
- A declarative subagent that arrived with PowerContextMiddleware(auto_capture=True)
  was left untouched, so the delegated turn was captured too. Replace it with an
  equivalent recall-only copy that keeps trace_content, without mutating the
  caller's middleware or spec.
- The guides installed only the LangChain adapter and imported a nonexistent
  powercontext_langchain.deepagents module. Install integrations/deepagents and
  import powercontext_deepagents in both locales.

Cover the built-in subagent's recall through a real compiled graph (delegation to
general-purpose), plus the normalization and duplicate-suppression cases.
@Lumea-art

Copy link
Copy Markdown
Contributor Author

All three findings are addressed in bd245a2 (18 deterministic tests now).

  1. Built-in general-purpose subagent — powercontext_subagents() always returns that spec when the caller does not supply one. It reuses Deep Agents' built-in description and system prompt and adds recall-only middleware, leaving model/tools/interrupt_on unset so Deep Agents inherits them exactly as for its own default. A caller-supplied or compiled spec with that name is kept instead of duplicated. Covered by a real compiled graph where the scripted model delegates through task(subagent_type="general-purpose") and the delegated model call is asserted to carry the recalled context.
  2. Capture on a declarative subagent — a spec arriving with PowerContextMiddleware(auto_capture=True) is rewritten to an equivalent recall-only copy (trace_content preserved), so the delegated turn is never captured; the caller-owned middleware and spec are not mutated.
  3. Guides — both locales now install ./integrations/deepagents and import from powercontext_deepagents import create_powercontext_deep_agent.

Verification: pytest tests/deepagents_adapter tests/langchain_middleware tests/test_integration_manifest.py → 90 passed, 1 skipped; ruff check / ruff format --check clean; the integration manifest docs check passes. The three new behavior tests fail on the previous head (verified by reverting only the adapter file).

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked bd245a2: the three original reproductions are fixed. The new default-subagent insertion introduces one configuration regression: it re-enables delegation when the active harness profile explicitly disables the default subagent. See the inline finding.

The adapter always supplied an explicit general-purpose spec, and Deep Agents
only honours GeneralPurposeSubagentProfile(enabled=False) when it auto-adds the
default, so opting into PowerContext re-enabled delegation the application had
disabled. Resolve the active harness profile before adding the spec: when it
disables the default subagent, forward no extra spec so Deep Agents keeps the
profile's behavior. Resolution is best effort and never blocks agent creation.

Cover both the forwarded spec and a compiled graph whose model must not be
offered the task tool under the disabled profile; both fail on the previous head.
@Lumea-art

Copy link
Copy Markdown
Contributor Author

Profile handling is fixed in aae2e71. powercontext_subagents() now takes the agent model, resolves the active harness profile with Deep Agents' own resolver, and only adds the built-in general-purpose spec when the profile does not disable it; resolution is best effort and never blocks agent creation.

Reproduction check with GeneralPurposeSubagentProfile(enabled=False) registered for the scripted model's provider: native create_deep_agent(model) and the adapter both bind no task tool; with the default profile both still bind it. Two new tests (spec forwarding and a compiled graph's bound tools) fail on bd245a2.

pytest tests/deepagents_adapter tests/langchain_middleware tests/test_integration_manifest.py → 92 passed, 1 skipped; ruff/format clean; manifest docs in sync.

… profile

model=None is deprecated but supported in the pinned 0.7 range, and Deep Agents
resolves it to its own default ChatAnthropic before applying the harness profile.
The adapter returned early for None, so a profile that disables the default
subagent was ignored and the explicit spec re-enabled delegation. Resolve the
same effective model with Deep Agents' own default builder before the profile
lookup; a failed default construction keeps the previous behavior because agent
creation cannot proceed without that model anyway.

Cover the default-model path with a registered disabled profile; it fails on the
previous head.
@Lumea-art

Copy link
Copy Markdown
Contributor Author

Fixed in 1969426. model=None now resolves the same effective model Deep Agents will use before the profile lookup: _effective_model() calls Deep Agents' own _build_default_model() (the function create_deep_agent calls for the deprecated default) and passes that instance to _harness_profile_for_model(..., spec=None). A default-model construction failure keeps the previous behavior, which is safe because create_deep_agent cannot proceed without that model either.

Verified against your exact reproduction with real ChatAnthropic construction (dummy key, no provider request): with register_harness_profile("anthropic", HarnessProfile(general_purpose_subagent=GeneralPurposeSubagentProfile(enabled=False))) and no explicit model or subagents, create_powercontext_deep_agent() forwards an empty subagent list, so no task tool is created; native create_deep_agent() behaves the same. test_disabled_general_purpose_profile_applies_to_the_default_model pins this and fails on aae2e71.

pytest tests/deepagents_adapter tests/langchain_middleware tests/test_integration_manifest.py → 93 passed, 1 skipped; ruff/format clean; integration manifest docs in sync.

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked 1969426: all previously reported correctness findings are fixed, including the default-model disabled-profile reproduction. No new blocking defect found in the updated paths. This review does not approve the added public Python interfaces; CI and real-provider acceptance remain separate gates.

@hidb4ai
hidb4ai dismissed stale reviews from themself November 21, 2026 15:20

The reported correctness defects were verified fixed at 1969426. Superseded by review 6006259133; this dismissal is not approval of the added public Python interfaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.6.0 v1.6.0 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(integrations): support Deep Agents integration

5 participants