bugfix + Enhc: DeepLitSearchAgent#105
Merged
Merged
Conversation
… instances of components
…lization, query generation, and error handling.
## Summary
This PR implements comprehensive dependency injection for the DeepLitSearchAgent, significantly improving testability, flexibility, and maintainability. Building on the initial query agent injection work, this adds dependency injection for all major components while maintaining full backward compatibility.
## Changes Made
### **Core Dependency Injection Enhancement**
- **Extended constructor parameters** to support injection of 8 additional components:
- `link_relevancy_assessor: LinkRelevancyAssessor | None = None`
- `web_scraper: SimpleWebScraper | None = None`
- `pdf_scraper: SimplePDFScraper | None = None`
- `triage_component: TriageComponent | None = None`
- `clarification_component: ClarificationComponent | None = None`
- `instruction_component: InstructionBuilderComponent | None = None`
- `research_synthesis_component: ResearchSynthesisComponent | None = None`
### **Smart Initialization Logic**
- **Config-aware initialization**: Components respect configuration flags (e.g., scrapers only auto-created when `enable_full_content_scraping=True`)
- **Fallback defaults**: When no dependency is injected, sensible defaults are created automatically
- **Override support**: Injected dependencies take precedence over config-based creation
### **Enhanced Test Coverage**
- **3 new comprehensive test methods**:
- `test_initialization_comprehensive_dependency_injection()`: Tests all 10+ dependencies
- `test_initialization_partial_dependency_injection()`: Tests mixed injection scenarios
- Enhanced existing `test_dependency_injection_workflow()`: Tests injected agents are used in workflow
- **Improved existing tests**: Fixed MultiRubricRelevancyOutputSchema validation with missing `overall_relevance` field
### **Bug Fixes**
- **Fixed search tool input schema issue**: Corrected `SearchToolInputSchema` usage in `_execute_searches()`
- **Updated test schema validation**: Added missing `EnhancedRelevancyLabel` imports and `overall_relevance` fields
## Benefits
### **Testing & Development**
- **100% mockable**: All dependencies can be injected for comprehensive unit testing
- **Isolated testing**: Components can be tested independently without side effects
- **Faster tests**: Mock components eliminate external dependencies
### **Architecture & Maintenance**
- **Clear separation of concerns**: Dependencies are explicit and well-defined
- **Flexible configuration**: Users can provide custom-configured instances
- **Better debugging**: Easier to isolate issues to specific components
### **Backward Compatibility**
- **Zero breaking changes**: All existing code continues to work unchanged
- **Progressive adoption**: Users can adopt dependency injection incrementally
- **Configuration respect**: All config flags continue to work as expected
## Usage Examples
```python
# Full dependency injection for testing
agent = DeepLitSearchAgent(
query_agent=mock_query_agent,
followup_query_agent=mock_followup_agent,
relevancy_agent=mock_relevancy_agent,
link_relevancy_assessor=mock_link_assessor,
web_scraper=mock_web_scraper,
triage_component=mock_triage,
# ... etc
)
# Partial injection
agent = DeepLitSearchAgent(
query_agent=custom_query_agent,
web_scraper=custom_scraper
# Other components use defaults
)
# Default behavior (unchanged)
agent = DeepLitSearchAgent() # All defaults
```
## Run tests
```bash
python -m pytest tests/agents/search/test_deep_search.py::TestDeepLitSearchAgent::test_initialization_comprehensive_dependency_injection -v
python -m pytest tests/agents/search/test_deep_search.py::TestDeepLitSearchAgent::test_dependency_injection_workflow -v
```
## Checks
- [x] **Comprehensive test coverage** with dependency injection validation
- [x] **Backward compatibility** maintained (all existing tests pass)
- [x] **Demo script compatibility** verified
- [x] **Configuration respect** (scrapers, link assessor, semantic scholar)
- [x] **Schema validation fixes** (MultiRubricRelevancyOutputSchema)
Use `self.search_tool.input_schema` for time being
…T/accelerated-discovery into bugfix/deepsearch-agent-clean
NISH1001
approved these changes
Aug 6, 2025
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 bugfixes and adds dep. injection for the DeepLitSearchAgent, improving testability, flexibility, and maintainability.
Changes Made
Core Dependency Injection Enhancement
link_relevancy_assessor: LinkRelevancyAssessor | None = Noneweb_scraper: SimpleWebScraper | None = Nonepdf_scraper: SimplePDFScraper | None = Nonetriage_component: TriageComponent | None = Noneclarification_component: ClarificationComponent | None = Noneinstruction_component: InstructionBuilderComponent | None = Noneresearch_synthesis_component: ResearchSynthesisComponent | None = NoneInitialization Notes
enable_full_content_scraping=True)Bug Fixes
SearchToolInputSchemausage in_execute_searches()EnhancedRelevancyLabelimports andoverall_relevancefieldsUsage Examples
Run tests
Run Demo
Checks
Coverage
Total coverage 43%
Of course! Here is your coverage report formatted as a GitHub Markdown table.
akd/__init__.pyakd/_base.py40, 46-51, 85, 91, 99, 108, 164, 168, 175-191, 199-202, 210, 231, 238-240, 256, 293-297, 305-307, 310-313, 318-334, 338-340, 344-346, 362-374, 389akd/agents/__init__.pyakd/agents/_base.py56, 59, 78akd/agents/extraction.py16, 19, 34-39akd/agents/factory.py1-110akd/agents/intents.pyakd/agents/litsearch.py1-24akd/agents/query.pyakd/agents/relevancy.pyakd/agents/search/__init__.pyakd/agents/search/_base.py79, 144-146, 154-161, 170akd/agents/search/components/__init__.pyakd/agents/search/components/clarification.py74-98akd/agents/search/components/instruction_builder.py81, 91-94akd/agents/search/components/research_synthesis.py131, 157-159, 164-167, 186-218akd/agents/search/components/triage.py71, 77-78akd/agents/search/controlled.py141-167, 175-176, 179-182, 189-250, 263-362, 375-438, 446-460, 475-498, 515-555, 565-616, 620-630, 634-655, 664-701, 705-724, 728-753, 762, 775-909akd/agents/search/deep_search.py240, 250, 309-310, 341-342, 404-410, 414-444, 448, 464-507, 604-608, 669, 671akd/agents/storm/__init__.py1-3akd/agents/storm/config.py1-62akd/agents/storm/nodes.py1-148akd/agents/storm/state.py1-22akd/agents/storm/storm.py1-140akd/agents/storm/tools.py1-213akd/agents/storm/utils/__init__.pyakd/agents/storm/utils/article_utils.py1-32akd/agents/storm/utils/interview_utils.py1-53akd/agents/storm/utils/model_utils.py1-40akd/agents/storm/utils/outline_utils.py1-80akd/agents/storm/utils/prompts.py1-125akd/common_types.py6-7, 17-18, 27-28, 32akd/configs/__init__.pyakd/configs/guardrails_config.pyakd/configs/lit_config.py1-29akd/configs/project.py63akd/configs/prompts.pyakd/configs/storm_config.py1-30akd/errors.pyakd/guardrails.pyakd/mapping/__init__.pyakd/mapping/mappers.py171, 182-201, 230-239, 245, 365-368, 415, 443, 454, 489-490, 516, 547-566, 611, 613, 615, 621-633, 644, 679, 732, 737, 744, 756-759, 766-783akd/nodes/__init__.pyakd/nodes/states.py10, 46-52akd/nodes/states_v2.py1-384akd/nodes/supervisor.py36-49, 53, 57, 66-76, 80-87, 90, 104-127, 135, 152-155, 159-167, 170-182, 194-238, 247-249akd/nodes/templates.py40-45, 50-83, 103, 120-137, 151-165, 185-198, 207-233akd/serializers.py27-48, 53-54, 59-60akd/structures.py21-22, 305-307akd/tools/__init__.pyakd/tools/_base.pyakd/tools/code_search.py70-89, 97-109, 141, 153, 159-161, 190-196, 204-218, 227-243, 296-297, 302-305, 336-337, 346-355, 374-425, 445, 499-500, 514-515, 522-523, 581-596, 627, 637-638, 642-643, 718-721, 728-729, 743-744, 751-752akd/tools/factory.py1-86akd/tools/granite_guardian_tool.py71-72, 137-150, 153-167, 170-174, 177-182, 188-215, 218-246akd/tools/link_relevancy_assessor.py75, 183-186, 192-246, 255-306, 318-373, 379-393, 419-449akd/tools/misc.py35-38, 45, 54, 65, 74, 78, 85, 89, 93-95, 107-110, 116-120, 123-142, 145akd/tools/relevancy.py1-459akd/tools/scrapers/__init__.pyakd/tools/scrapers/_base.py134-160, 181-295, 308-322, 329-332, 337-361, 372-373, 395-426akd/tools/scrapers/composite.py1-136akd/tools/scrapers/omni.py84-86, 90-92, 112-114, 129-152, 168-175, 181-183, 192-208, 219-235akd/tools/scrapers/pdf_scrapers.py48-70, 92-103, 109-129, 135-144, 149-150, 162-164, 177-188, 204-227akd/tools/scrapers/resolvers.py1-171akd/tools/scrapers/utils.py56-58, 75-76, 79, 92-96, 103-106, 113-116, 123-126, 132, 143akd/tools/scrapers/web_scrapers.py33-53, 66-71, 84-103, 120-154, 162-163, 173-187akd/tools/search/__init__.pyakd/tools/search/_base.pyakd/tools/search/searxng_search.py96-110, 152-158, 169-171, 188, 194, 228, 237, 249-253, 256, 293-298, 321akd/tools/search/semantic_scholar_search.py82-89, 119-132, 153-210, 218-255, 277-332, 341-368, 393-492, 502-525, 541-552, 571-617akd/tools/source_validator.py135-143, 157-174, 186-199, 216-243, 263-293, 315-349, 357-399, 422-502, 526-532akd/tools/utils.py37-168, 191, 196-198, 206-226, 230-237akd/utils.py12-13, 17-22, 33, 42-56, 75-109, 133-139short test summary