Skip to content

SubAgentMiddleware regression — runtime config not passed to subagent invocations (PR #602 fix lost in #1041 refactor) #2362

@kushmadlani

Description

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title.
  • I searched existing issues and didn't find this.
  • I can reproduce this with the latest released version.
  • I included a minimal reproducible example and steps to reproduce.

Area (Required)

  • deepagents (SDK)
  • cli

Related Issues / PRs

#569, #139, #602, #1041

Reproduction Steps / Example Code (Python)

from dataclasses import dataclass
from langchain.agents import create_agent
from langchain.tools import tool, ToolRuntime
from deepagents import create_deep_agent

@dataclass
class MyContext:
    api_url: str = "https://example.com"

@tool
def check_context(query: str, runtime: ToolRuntime[MyContext]) -> str:
    """Tool that needs runtime.context."""
    return f"Context: {runtime.context.api_url}"

agent = create_deep_agent(
    tools=[check_context],
    context_schema=MyContext,
)

# This works:
agent.invoke({"messages": [...]}, context=MyContext())

# But when the agent delegates to a subagent via the task tool,
# the subagent's tools receive runtime.context = None

Error Message and Stack Trace (if applicable)

Description

Environment / System Info

No response

Metadata

Metadata

Labels

bugSomething isn't workingdeepagentsRelated to the `deepagents` SDK / agent harnessexternalUser is not a member of the `langchain-ai` GitHub organization

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions