Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
923041c
refactor: update citation verification handling in DeepResearcherAgent
rkarmaka May 13, 2026
edda062
refactor: update error handling in deep research process
rkarmaka May 13, 2026
84d08eb
fix: resolve rebase conflicts for issue-235 empty source registry
rkarmaka Jul 8, 2026
74152b1
Merge branch 'develop' into fix/issue-235-empty-source-registry
rkarmaka Jul 8, 2026
ea07a49
Merge branch 'develop' into fix/issue-235-empty-source-registry
rkarmaka Jul 8, 2026
dd3a572
Merge branch 'develop' into fix/issue-235-empty-source-registry
AjayThorve Jul 14, 2026
5b16d9b
Merge branch 'develop' into fix/issue-235-empty-source-registry
AjayThorve Jul 14, 2026
75c237d
Merge branch 'release/2.2' into fix/issue-235-empty-source-registry
AjayThorve Jul 15, 2026
9121ba5
fix: surface unverified deep research reports
rkarmaka Jul 16, 2026
c682e0d
Merge branch 'release/2.2' into fix/issue-235-empty-source-registry
rkarmaka Jul 16, 2026
8d473cc
fix: keep deep research report state clean
rkarmaka Jul 16, 2026
2f61174
test: reuse citation warning helper
rkarmaka Jul 16, 2026
3670801
Merge branch 'release/2.2' into fix/issue-235-empty-source-registry
AjayThorve Jul 17, 2026
021464a
fix: preserve citation verification disposition
rkarmaka Jul 17, 2026
ef4680b
fix: keep inline edit verification warning
rkarmaka Jul 17, 2026
7975857
feat: add citation verification status handling and warnings in reports
rkarmaka Aug 21, 2026
62611f7
Merge remote-tracking branch 'upstream/develop' into fix/issue-235-em…
rkarmaka Aug 21, 2026
7325468
Merge upstream develop into fix/issue-235-empty-source-registry
rkarmaka Aug 21, 2026
c876d8b
Merge branch 'develop' into fix/issue-235-empty-source-registry
cdgamarose-nv Aug 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/aiq_agent/agents/chat_researcher/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,23 +332,28 @@ async def deep_research_node(state: ChatResearcherState) -> dict[str, Any]:
)
try:
result = await self.deep_research_fn(deep_state)
except EmptySourceRegistryError as exc:
logger.warning("Deep research produced no verifiable sources")
if exc.unavailable_tools:
from aiq_agent.common.tool_validation import format_user_facing_tool_error

err_msg = format_user_facing_tool_error(
"deep research",
exc.unavailable_tools,
exc.available_count,
)
else:
err_msg = (
"The search tools did not return any results for this question. "
"This may be due to a temporary issue or the question may need to be rephrased. "
"Please try again."
)
return {"messages": [AIMessage(content=err_msg)]}
# Deep researcher no longer raises EmptySourceRegistryError when the source
# registry is empty (issue #235): it now returns the report with
# `citation_verification_status` set so the report isn't lost. Block kept
# commented for reference until that flag is wired through to surface
# unverified-report UX here.
# except EmptySourceRegistryError as exc:
# logger.warning("Deep research produced no verifiable sources")
# if exc.unavailable_tools:
# from aiq_agent.common.tool_validation import format_user_facing_tool_error
#
# err_msg = format_user_facing_tool_error(
# "deep research",
# exc.unavailable_tools,
# exc.available_count,
# )
# else:
# err_msg = (
# "The search tools did not return any results for this question. "
# "This may be due to a temporary issue or the question may need to be rephrased. "
# "Please try again."
# )
# return {"messages": [AIMessage(content=err_msg)]}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
except Exception as e:
if _AuthError and isinstance(e, _AuthError):
logger.warning("Auth error in deep research: %s", e)
Expand Down
27 changes: 21 additions & 6 deletions src/aiq_agent/agents/deep_researcher/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

from aiq_agent.common import LLMProvider
from aiq_agent.common import load_prompt
from aiq_agent.common.citation_verification import EmptySourceRegistryError
from aiq_agent.common.citation_verification import sanitize_report
from aiq_agent.common.citation_verification import source_entries_from_parent_context
from aiq_agent.common.citation_verification import verify_citations
Expand Down Expand Up @@ -333,11 +332,27 @@ async def run(self, state: DeepResearchAgentState) -> DeepResearchAgentState:
research_type="deep research",
enable_logging=False,
)
raise EmptySourceRegistryError(
"deep research",
unavailable_tools=unavailable,
available_count=available_count,
)
if available_count == 0:
logger.error(
"Deep research produced a report but no sources were captured: "
"all configured tools are unavailable (%s). "
"Returning the report unverified.",
unavailable,
)
else:
logger.warning(
"Deep research produced a report but no sources were captured "
"despite %d available tool(s). The model may have answered "
"without using search results. Returning the report unverified.",
available_count,
)
if result is not None:
result["citation_verification_status"] = {
Comment thread
AjayThorve marked this conversation as resolved.
Resolved
"status": "unverified",
"reason": "empty_source_registry",
"available_tool_count": available_count,
"unavailable_tools": unavailable,
}
Comment thread
rkarmaka marked this conversation as resolved.
Resolved

# Post-process: sanitize report (strip body URLs, shortened URLs, unsafe URLs)
sanitization = sanitize_report(final_message)
Expand Down
7 changes: 7 additions & 0 deletions src/aiq_agent/agents/deep_researcher/models/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class DeepResearchAgentState(BaseModel):
rubric: DeepAgents rubric used by RubricMiddleware when available.
clarifier_result: Log from clarifier agent dialog.
available_documents: User-uploaded documents with summaries for context.
citation_verification_status: Set when citation verification was skipped
because the source registry was empty. ``None`` means the report was

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Do not equate missing status with verified

The new contract says None means the report was verified, but the control flow also leaves it None when enable_citation_verification=False and when verification runs with a nonempty registry but finds zero valid citations. In the latter case, a report with no citation markers is returned unchanged and the API/UI omit the warning even though no claims were verified.

Make the verification engine return an explicit closed outcome for every run—at minimum verified, unverified, or disabled—with machine-readable reasons such as no_sources and no_valid_citations. Propagate that outcome instead of inferring success from absence.

verified normally. When populated, contains keys: ``status``
(``"unverified"``), ``reason``, ``available_tool_count``,
``unavailable_tools``. Downstream consumers can read this to flag
unverified results.
"""

messages: Annotated[list[AnyMessage], add_messages]
Expand All @@ -67,3 +73,4 @@ class DeepResearchAgentState(BaseModel):
rubric: str | None = None
clarifier_result: str | None = None
available_documents: list[AvailableDocument] | None = None
citation_verification_status: dict[str, Any] | None = None
Comment thread
AjayThorve marked this conversation as resolved.
Resolved
56 changes: 56 additions & 0 deletions tests/aiq_agent/agents/deep_researcher/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,62 @@ async def test_run_empty_result_messages(self, mock_llm_provider, real_tool):
# Should handle empty messages
assert result is not None

@pytest.mark.asyncio
async def test_run_empty_source_registry_returns_unverified_status(
self, mock_llm_provider, real_tool, mock_create_deep_agent
):
"""Empty source registry no longer raises — return the report with an unverified status flag.

Regression for issue #235: previously raised EmptySourceRegistryError and lost the report.
"""
with patch(
"aiq_agent.agents.deep_researcher.factory.create_deep_agent",
return_value=mock_create_deep_agent,
):
from aiq_agent.agents.deep_researcher.agent import DeepResearcherAgent

agent = DeepResearcherAgent(
llm_provider=mock_llm_provider,
tools=[real_tool],
)

state = DeepResearchAgentState(messages=[HumanMessage(content="Test query")])
# Intentionally do NOT populate source_registry_middleware.registry.

result = await agent.run(state)

assert result is not None
assert result.messages, "Report should be preserved even when sources are missing"
assert result.citation_verification_status is not None
assert result.citation_verification_status["status"] == "unverified"
assert result.citation_verification_status["reason"] == "empty_source_registry"
assert "available_tool_count" in result.citation_verification_status
assert "unavailable_tools" in result.citation_verification_status

@pytest.mark.asyncio
async def test_run_with_sources_leaves_verification_status_none(
self, mock_llm_provider, real_tool, mock_create_deep_agent
):
"""When sources are captured, citation_verification_status stays None (verified path)."""
with patch(
"aiq_agent.agents.deep_researcher.factory.create_deep_agent",
return_value=mock_create_deep_agent,
):
from aiq_agent.agents.deep_researcher.agent import DeepResearcherAgent

agent = DeepResearcherAgent(
llm_provider=mock_llm_provider,
tools=[real_tool],
)

state = DeepResearchAgentState(messages=[HumanMessage(content="Test query")])
agent.source_registry_middleware.registry.add(SourceEntry(url="https://example.com"))

result = await agent.run(state)

assert result is not None
assert result.citation_verification_status is None

@pytest.mark.asyncio
async def test_run_replaces_final_message_with_writer_markdown(self, mock_llm_provider, real_tool):
"""The final answer comes from /shared/output.md."""
Expand Down