-
Notifications
You must be signed in to change notification settings - Fork 414
feat(langgraph): configurable recursion_limit for LangGraph agents #1305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
opspawn
wants to merge
6
commits into
kagent-dev:main
Choose a base branch
from
opspawn:feat/recursion-limit-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+72
−3
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cd858b5
feat(langgraph): configurable recursion_limit for LangGraph agents
opspawn bef63d3
fix(langgraph): use Field(default_factory) and add gt=0 validation fo…
opspawn 42c232a
test: add coverage for invalid env var value in recursion_limit
opspawn cba7d25
fix(test): remove unused importlib import and harden default test
opspawn b953ac6
ci: retrigger e2e tests (Bun segfault in CI, unrelated to this change)
opspawn 7bfa15f
ci: retrigger e2e tests
opspawn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
58 changes: 58 additions & 0 deletions
58
python/packages/kagent-langgraph/tests/test_executor_config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| """Tests for LangGraphAgentExecutorConfig.""" | ||
|
|
||
| import os | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| def test_recursion_limit_default(): | ||
| """Test that default recursion_limit is 25 (LangGraph's default).""" | ||
| from kagent.langgraph._executor import LangGraphAgentExecutorConfig | ||
|
|
||
| with patch.dict(os.environ, {}, clear=False): | ||
| os.environ.pop("LANGGRAPH_RECURSION_LIMIT", None) | ||
| config = LangGraphAgentExecutorConfig() | ||
| assert config.recursion_limit == 25 | ||
|
|
||
|
|
||
| def test_recursion_limit_from_env_var(): | ||
| """Test that LANGGRAPH_RECURSION_LIMIT env var is picked up at instance creation.""" | ||
| import kagent.langgraph._executor as executor_mod | ||
|
|
||
| with patch.dict(os.environ, {"LANGGRAPH_RECURSION_LIMIT": "50"}): | ||
| config = executor_mod.LangGraphAgentExecutorConfig() | ||
| assert config.recursion_limit == 50 | ||
|
|
||
|
|
||
| def test_recursion_limit_explicit_override(): | ||
| """Test that explicit config value overrides env var default.""" | ||
| from kagent.langgraph._executor import LangGraphAgentExecutorConfig | ||
|
|
||
| config = LangGraphAgentExecutorConfig(recursion_limit=100) | ||
| assert config.recursion_limit == 100 | ||
|
|
||
|
|
||
| def test_recursion_limit_rejects_zero(): | ||
| """Test that recursion_limit=0 is rejected by gt=0 validation.""" | ||
| from kagent.langgraph._executor import LangGraphAgentExecutorConfig | ||
|
|
||
| with pytest.raises(Exception): | ||
| LangGraphAgentExecutorConfig(recursion_limit=0) | ||
|
|
||
|
|
||
| def test_recursion_limit_rejects_negative(): | ||
| """Test that negative recursion_limit is rejected by gt=0 validation.""" | ||
| from kagent.langgraph._executor import LangGraphAgentExecutorConfig | ||
|
|
||
| with pytest.raises(Exception): | ||
| LangGraphAgentExecutorConfig(recursion_limit=-5) | ||
|
|
||
|
|
||
| def test_recursion_limit_invalid_env_var(): | ||
| """Test that a non-numeric LANGGRAPH_RECURSION_LIMIT env var raises an error.""" | ||
| import kagent.langgraph._executor as executor_mod | ||
|
|
||
| with patch.dict(os.environ, {"LANGGRAPH_RECURSION_LIMIT": "abc"}): | ||
| with pytest.raises((ValueError, Exception)): | ||
| executor_mod.LangGraphAgentExecutorConfig() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test suite is missing coverage for invalid environment variable values. The current implementation will raise a ValueError if someone sets
LANGGRAPH_RECURSION_LIMITto a non-numeric value (e.g., "abc"), but this error case is not tested.Consider adding a test case that verifies the behavior when the environment variable contains an invalid value, to ensure it either fails gracefully with a helpful error message or falls back to a sensible default.