mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-05 15:10:20 +08:00
* feat: add citation support in research report block and markdown - Enhanced ResearchReportBlock to fetch citations based on researchId and pass them to the Markdown component. - Introduced CitationLink component to display citation metadata on hover for links in markdown. - Implemented CitationCard and CitationList components for displaying citation details and lists. - Updated Markdown component to handle citation links and inline citations. - Created HoverCard component for displaying citation information in a tooltip-like manner. - Modified store to manage citations, including setting and retrieving citations for ongoing research. - Added CitationsEvent type to handle citations in chat events and updated Message type to include citations. * fix(log): Enable the logging level when enabling the DEBUG environment variable (#793) * fix(frontend): render all tool calls in the frontend #796 (#797) * build(deps): bump jspdf from 3.0.4 to 4.0.0 in /web (#798) Bumps [jspdf](https://github.com/parallax/jsPDF) from 3.0.4 to 4.0.0. - [Release notes](https://github.com/parallax/jsPDF/releases) - [Changelog](https://github.com/parallax/jsPDF/blob/master/RELEASE.md) - [Commits](https://github.com/parallax/jsPDF/compare/v3.0.4...v4.0.0) --- updated-dependencies: - dependency-name: jspdf dependency-version: 4.0.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix(frontend):added the display of the 'analyst' message #800 (#801) * fix: migrate from deprecated create_react_agent to langchain.agents.create_agent (#802) * fix: migrate from deprecated create_react_agent to langchain.agents.create_agent Fixes #799 - Replace deprecated langgraph.prebuilt.create_react_agent with langchain.agents.create_agent (LangGraph 1.0 migration) - Add DynamicPromptMiddleware to handle dynamic prompt templates (replaces the 'prompt' callable parameter) - Add PreModelHookMiddleware to handle pre-model hooks (replaces the 'pre_model_hook' parameter) - Update AgentState import from langchain.agents in template.py - Update tests to use the new API * fix:update the code with review comments * fix: Add runtime parameter to compress_messages method(#803) * fix: Add runtime parameter to compress_messages method(#803) The compress_messages method was being called by PreModelHookMiddleware with both state and runtime parameters, but only accepted state parameter. This caused a TypeError when the middleware executed the pre_model_hook. Added optional runtime parameter to compress_messages signature to match the expected interface while maintaining backward compatibility. * Update the code with the review comments * fix: Refactor citation handling and add comprehensive tests for citation features * refactor: Clean up imports and formatting across citation modules * fix: Add monkeypatch to clear AGENT_RECURSION_LIMIT in recursion limit tests * feat: Enhance citation link handling in Markdown component * fix: Exclude citations from finish reason handling in mergeMessage function * fix(nodes): update message handling * fix(citations): improve citation extraction and handling in event processing * feat(citations): enhance citation extraction and handling with improved merging and normalization * fix(reporter): update citation formatting instructions for clarity and consistency * fix(reporter): prioritize using Markdown tables for data presentation and comparison --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: LoftyComet <1277173875@qq。> Co-authored-by: Willem Jiang <willem.jiang@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
184 lines
6.2 KiB
Python
184 lines
6.2 KiB
Python
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
import sys
|
|
import types
|
|
|
|
from src.config.configuration import Configuration
|
|
|
|
# Patch sys.path so relative import works
|
|
|
|
# Patch Resource for import
|
|
mock_resource = type("Resource", (), {})
|
|
|
|
# Patch src.rag.retriever.Resource for import
|
|
|
|
module_name = "src.rag.retriever"
|
|
if module_name not in sys.modules:
|
|
retriever_mod = types.ModuleType(module_name)
|
|
retriever_mod.Resource = mock_resource
|
|
sys.modules[module_name] = retriever_mod
|
|
|
|
# Relative import of Configuration
|
|
|
|
|
|
def test_default_configuration():
|
|
config = Configuration()
|
|
assert config.resources == []
|
|
assert config.max_plan_iterations == 1
|
|
assert config.max_step_num == 3
|
|
assert config.max_search_results == 3
|
|
assert config.mcp_settings is None
|
|
|
|
|
|
def test_from_runnable_config_with_config_dict(monkeypatch):
|
|
config_dict = {
|
|
"configurable": {
|
|
"max_plan_iterations": 5,
|
|
"max_step_num": 7,
|
|
"max_search_results": 10,
|
|
"mcp_settings": {"foo": "bar"},
|
|
}
|
|
}
|
|
config = Configuration.from_runnable_config(config_dict)
|
|
assert config.max_plan_iterations == 5
|
|
assert config.max_step_num == 7
|
|
assert config.max_search_results == 10
|
|
assert config.mcp_settings == {"foo": "bar"}
|
|
|
|
|
|
def test_from_runnable_config_with_env_override(monkeypatch):
|
|
monkeypatch.setenv("MAX_PLAN_ITERATIONS", "9")
|
|
monkeypatch.setenv("MAX_STEP_NUM", "11")
|
|
config_dict = {
|
|
"configurable": {
|
|
"max_plan_iterations": 2,
|
|
"max_step_num": 3,
|
|
"max_search_results": 4,
|
|
}
|
|
}
|
|
config = Configuration.from_runnable_config(config_dict)
|
|
# Environment variables take precedence and are strings
|
|
assert config.max_plan_iterations == "9"
|
|
assert config.max_step_num == "11"
|
|
assert config.max_search_results == 4 # not overridden
|
|
# Clean up
|
|
monkeypatch.delenv("MAX_PLAN_ITERATIONS")
|
|
monkeypatch.delenv("MAX_STEP_NUM")
|
|
|
|
|
|
def test_from_runnable_config_with_none_and_falsy(monkeypatch):
|
|
"""Test that None values are skipped but falsy values (0, False, empty string) are preserved."""
|
|
config_dict = {
|
|
"configurable": {
|
|
"max_plan_iterations": None, # None should be skipped, use default
|
|
"max_step_num": 0, # 0 is valid, should be preserved
|
|
"max_search_results": "", # Empty string should be preserved
|
|
}
|
|
}
|
|
config = Configuration.from_runnable_config(config_dict)
|
|
# None values should fall back to defaults
|
|
assert config.max_plan_iterations == 1
|
|
# Falsy but valid values should be preserved
|
|
assert config.max_step_num == 0
|
|
assert config.max_search_results == ""
|
|
|
|
|
|
def test_from_runnable_config_with_no_config():
|
|
config = Configuration.from_runnable_config()
|
|
assert config.max_plan_iterations == 1
|
|
assert config.max_step_num == 3
|
|
assert config.max_search_results == 3
|
|
assert config.resources == []
|
|
assert config.mcp_settings is None
|
|
|
|
|
|
def test_from_runnable_config_with_boolean_false_values():
|
|
"""Test that boolean False values are correctly preserved and not filtered out.
|
|
|
|
This is a regression test for the bug where False values were treated as falsy
|
|
and filtered out, causing fields to revert to their default values.
|
|
"""
|
|
config_dict = {
|
|
"configurable": {
|
|
"enable_web_search": False, # Should be preserved as False, not revert to True
|
|
"enable_deep_thinking": False, # Should be preserved as False
|
|
"enforce_web_search": False, # Should be preserved as False
|
|
"enforce_researcher_search": False, # Should be preserved as False
|
|
"max_plan_iterations": 5, # Control: non-falsy value
|
|
}
|
|
}
|
|
config = Configuration.from_runnable_config(config_dict)
|
|
|
|
# Assert that False values are preserved
|
|
assert config.enable_web_search is False, "enable_web_search should be False, not default True"
|
|
assert config.enable_deep_thinking is False, "enable_deep_thinking should be False"
|
|
assert config.enforce_web_search is False, "enforce_web_search should be False"
|
|
assert config.enforce_researcher_search is False, "enforce_researcher_search should be False, not default True"
|
|
|
|
# Control: verify non-falsy values still work
|
|
assert config.max_plan_iterations == 5
|
|
|
|
|
|
def test_from_runnable_config_with_boolean_true_values():
|
|
"""Test that boolean True values work correctly (control test)."""
|
|
config_dict = {
|
|
"configurable": {
|
|
"enable_web_search": True,
|
|
"enable_deep_thinking": True,
|
|
"enforce_web_search": True,
|
|
}
|
|
}
|
|
config = Configuration.from_runnable_config(config_dict)
|
|
|
|
assert config.enable_web_search is True
|
|
assert config.enable_deep_thinking is True
|
|
assert config.enforce_web_search is True
|
|
|
|
def test_get_recursion_limit_default(monkeypatch):
|
|
from src.config.configuration import get_recursion_limit
|
|
|
|
monkeypatch.delenv("AGENT_RECURSION_LIMIT", raising=False)
|
|
result = get_recursion_limit()
|
|
assert result == 25
|
|
|
|
|
|
def test_get_recursion_limit_custom_default(monkeypatch):
|
|
from src.config.configuration import get_recursion_limit
|
|
|
|
monkeypatch.delenv("AGENT_RECURSION_LIMIT", raising=False)
|
|
result = get_recursion_limit(50)
|
|
assert result == 50
|
|
|
|
|
|
def test_get_recursion_limit_from_env(monkeypatch):
|
|
from src.config.configuration import get_recursion_limit
|
|
|
|
monkeypatch.setenv("AGENT_RECURSION_LIMIT", "100")
|
|
result = get_recursion_limit()
|
|
assert result == 100
|
|
|
|
|
|
def test_get_recursion_limit_invalid_env_value(monkeypatch):
|
|
from src.config.configuration import get_recursion_limit
|
|
|
|
monkeypatch.setenv("AGENT_RECURSION_LIMIT", "invalid")
|
|
result = get_recursion_limit()
|
|
assert result == 25
|
|
|
|
|
|
def test_get_recursion_limit_negative_env_value(monkeypatch):
|
|
from src.config.configuration import get_recursion_limit
|
|
|
|
monkeypatch.setenv("AGENT_RECURSION_LIMIT", "-5")
|
|
result = get_recursion_limit()
|
|
assert result == 25
|
|
|
|
|
|
def test_get_recursion_limit_zero_env_value(monkeypatch):
|
|
from src.config.configuration import get_recursion_limit
|
|
|
|
monkeypatch.setenv("AGENT_RECURSION_LIMIT", "0")
|
|
result = get_recursion_limit()
|
|
assert result == 25
|