langchain-ai / langchain-ai/deepagentsjs

feat(deepagents): per-subagent recursionLimit override

Open
#755 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.6k
Forks
272
Avg merge
1d 13h
Merged PRs (30d)
38

Description

## Problem

The `SubAgent` interface has no way to set a recursion limit for an individual subagent. All subagents inherit whatever `recursionLimit` is in the parent's ambient `RunnableConfig` — there's no field to give one subagent a smaller or larger ceiling than the parent.

**Use cases:**
- Bounding an expensive delegation (e.g. a tight ceiling for a quick lookup subagent that shouldn't run away)
- Giving research-heavy subagents more headroom without raising the global limit for all subagents

## Current behavior

- `createDeepAgent()` sets `.withConfig({ recursionLimit: 10_000 })` on the top-level graph
- Subagents are invoked via `subagent.invoke(subagentState, config)` where `config` is the parent's ambient config — no per-subagent override

## Proposed solution

Add an optional `recursionLimit?: number` field to the `SubAgent` interface. When set, the task tool merges it into the invoke config before calling `subagent.invoke()`, overriding the parent's ambient value for that specific subagent only.

```ts
const bounded: SubAgent = {
name: "bounded",
description: "Short-lived helper with a tight step ceiling",
systemPrompt: "You are a focused helper.",
recursionLimit: 50,
};
```

## Prior art

- Python repo: [langchain-ai/deepagents#1698](https://github.com/langchain-ai/deepagents/issues/1698) — same request, two PRs (#2012, #2150) implemented it but were auto-closed by the assignment bot
- JS repo: [#183](https://github.com/langchain-ai/deepagentsjs/pull/183) raised the global default to 10k but didn't add per-subagent control
- [#76](https://github.com/langchain-ai/deepagentsjs/issues/76) was the narrower "top-level default missing" bug, already fixed by #183

I have a PR ready for this — will link it shortly.

Contributor guide

Open the contributing guide

Research direction

Start at the SubAgent interface and the task tool's subagent.invoke() call described in the issue. Trace how the parent RunnableConfig is passed and merged, then verify that a subagent-specific recursionLimit overrides the ambient value without changing the parent's limit.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
ai
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.