Skip to content

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
langchain-ai:mainfrom
zamal-db:fix/critical-bugs-and-first-tests
Open

fix: critical bugs in compress_research, LangGraph deprecations + first unit test suite (77 tests)#254
at384 (zamal-db) wants to merge 1 commit into
langchain-ai:mainfrom
zamal-db:fix/critical-bugs-and-first-tests

Conversation

@zamal-db

Copy link
Copy Markdown

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_research token-limit check (relates to #230)

File: src/open_deep_research/deep_researcher.py L569

The compress_research function invokes configurable.compression_model (L528) but the is_token_limit_exceeded fallback was checking against configurable.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

  • if is_token_limit_exceeded(e, configurable.research_model):
  • if is_token_limit_exceeded(e, configurable.compression_model):
    `

2. remove_up_to_last_ai_message removes newest context instead of oldest (relates to #252)

File: src/open_deep_research/utils.py

The original implementation searches backwards (range(len-1, -1, -1)) and returns messages[: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 AIMessage skips its associated ToolMessage replies 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.py L591, L703

StateGraph(output=...) and StateGraph(input=...) are deprecated since LangGraph V05:

`diff

  • output=ResearcherOutputState,
  • output_schema=ResearcherOutputState,
  • input=AgentInputState,
  • input_schema=AgentInputState,
    `

Note: config_schema= is intentionally left unchanged it maps to context_schema= in V10 which changes runtime behavior and should be migrated separately.


Improvements

Extended provider support in get_api_key_for_model

Replaced the hardcoded 3-provider if/elif chain with a data-driven _PROVIDER_API_KEY_MAP covering 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:

Module Tests Covers
test_utils.py 56 remove_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_calls
test_configuration.py 11 SearchAPI, MCPConfig, Configuration (defaults, from_runnable_config, env overrides)
test_state.py 10 override_reducer, all structured output models (ConductResearch, ResearchComplete, Summary, ClarifyWithUser, ResearchQuestion)

All 77 tests pass. No new dependencies added.


Verification

  • All 77 unit tests pass (uv run pytest tests/unit/ -v)
  • Integration tested end-to-end with live Vertex AI Gemini API (graph execution: clarify_with_user write_research_brief research_supervisor)
  • git diff --stat: 7 files changed, 827 insertions(+), 22 deletions(-)

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant