fix: critical bugs in compress_research, LangGraph deprecations + first unit test suite (77 tests)#254
Open
at384 (zamal-db) wants to merge 1 commit into
Conversation
…ests) Bug Fixes: - Fix langchain-ai#252: remove_up_to_last_ai_message now removes the oldest AI/Tool exchange instead of the newest, preserving the most recent research context - Fix langchain-ai#230: compress_research token limit check now uses compression_model instead of research_model (matching the model actually used for compression) - Fix langchain-ai#225: Replace deprecated LangGraph StateGraph params output= and input= with output_schema= and input_schema= (deprecated since V05) Enhancements: - Extend get_api_key_for_model with 6 new providers (groq, deepseek, mistral, cohere, fireworks, bedrock) via a data-driven _PROVIDER_API_KEY_MAP Tests: - Add first-ever unit test suite: 77 tests covering utils, configuration, and state modules with zero external dependencies required
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR fixes 3 confirmed bugs and adds the first-ever unit test suite (77 tests) for open_deep_research.
Bug Fixes
1. Wrong model in
compress_researchtoken-limit check (relates to #230)File:
src/open_deep_research/deep_researcher.pyL569The
compress_researchfunction invokesconfigurable.compression_model(L528) but theis_token_limit_exceededfallback was checking againstconfigurable.research_model. When a token-limit error is raised by the compression model, the check against the research model can silently fail to match the provider causing the loop to raise instead of gracefully trimming messages.`diff
`
2.
remove_up_to_last_ai_messageremoves newest context instead of oldest (relates to #252)File:
src/open_deep_research/utils.pyThe original implementation searches backwards (
range(len-1, -1, -1)) and returnsmessages[:i]removing the most recent AI exchange (the freshest research). The function is called in the compress loop to shed context when hitting token limits, so it should remove the oldest exchange first.Fixed: Forward search finds the first
AIMessageskips its associatedToolMessagereplies returns everything after progressively dropping the oldest research while preserving recent context.3. LangGraph V05 deprecation warnings (relates to #225)
File:
src/open_deep_research/deep_researcher.pyL591, L703StateGraph(output=...)andStateGraph(input=...)are deprecated since LangGraph V05:`diff
`
Improvements
Extended provider support in
get_api_key_for_modelReplaced the hardcoded 3-provider
if/elifchain with a data-driven_PROVIDER_API_KEY_MAPcovering 9 providers: OpenAI, Anthropic, Google, Groq, DeepSeek, Mistral, Cohere, Fireworks, and Bedrock (AWS). Adding a new provider is now a single dict entry.First Unit Test Suite (77 tests)
This repo had zero tests. This PR adds a comprehensive
tests/unit/suite:test_utils.pyremove_up_to_last_ai_message,is_token_limit_exceeded,get_model_token_limit,get_config_value,get_today_str,anthropic_websearch_called,openai_websearch_called,get_api_key_for_model,get_notes_from_tool_callstest_configuration.pySearchAPI,MCPConfig,Configuration(defaults,from_runnable_config, env overrides)test_state.pyoverride_reducer, all structured output models (ConductResearch,ResearchComplete,Summary,ClarifyWithUser,ResearchQuestion)All 77 tests pass. No new dependencies added.
Verification
uv run pytest tests/unit/ -v)clarify_with_userwrite_research_briefresearch_supervisor)git diff --stat: 7 files changed, 827 insertions(+), 22 deletions(-)