Skip to content

Add memory field to SubAgent TypedDict for per-subagent AGENTS.md loading #2456

@kavishkartha05

Description

Checked other resources

  • This is a feature request, not a bug report.
  • I searched existing issues and didn't find this feature.
  • I checked the docs and README for existing functionality.
  • This request applies to this repo (deepagents) and not an external package.

Area (Required)

  • deepagents (SDK)
  • cli

Feature description

The SubAgent TypedDict supports a skills field that wires up SkillsMiddleware for per-subagent skill loading. However, there is no equivalent memory field for MemoryMiddleware, even though both follow the same pattern of loading files from a backend at startup and injecting them into the system prompt.

Currently, if a user wants to give a custom subagent its own AGENTS.md memory, they must either drop down to CompiledSubAgent and wire MemoryMiddleware manually, or add it directly to the subagent's middleware list. Neither approach is discoverable, especially since skills already exists as a first-class field on SubAgent.

Proposed solution (optional)

I'd love to take this on. Here's my approach:

I would think to add a memory field to the SubAgent TypedDict in middleware/subagents.py, mirroring the existing skills field.

So something like:

memory: NotRequired[list[str]]
"""Memory file paths (AGENTS.md) for MemoryMiddleware; same format as create_deep_agent(memory=...)."""

Then handle it in graph.py in the subagent processing loop directly after the existing skills handling:

subagent_memory = spec.get("memory")
if subagent_memory:
    subagent_middleware.append(MemoryMiddleware(backend=backend, sources=subagent_memory))

Additional context (optional)

The skills field on SubAgent was added with the same pattern and is already tested in test_custom_subagent_with_skills_parameter. The memory field would follow the same implementation and test structure.

The general-purpose subagent already inherits memory from create_deep_agent(memory=...) via MemoryMiddleware on the main agent stack. But custom SubAgent specs have no equivalent. This means users building specialized subagents can't declaratively give them their own persistent instructions via AGENTS.md, even though that's a core pattern the SDK is built around.

I strongly feel that adding a memory field brings custom subagents to full parity with both the main agent and the general-purpose subagent, making the API consistent across all agent types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    deepagentsRelated to the `deepagents` SDK / agent harnessexternalUser is not a member of the `langchain-ai` GitHub organization

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions