refactor: update citation verification handling in DeepResearcherAgent#237
refactor: update citation verification handling in DeepResearcherAgent#237rkarmaka wants to merge 2 commits into
Conversation
rkarmaka
commented
May 13, 2026
- Removed the raising of EmptySourceRegistryError when no sources are available during deep research.
- Added logging for cases where reports are generated without captured sources, indicating whether tools were unavailable or if the model answered without using search results.
- Introduced a new citation_verification_status field in DeepResearchAgentState to track unverified reports, including the reason and available tool count.
- Updated tests to ensure correct behavior when the source registry is empty and when sources are captured.
- Removed the raising of EmptySourceRegistryError when no sources are available during deep research. - Added logging for cases where reports are generated without captured sources, indicating whether tools were unavailable or if the model answered without using search results. - Introduced a new citation_verification_status field in DeepResearchAgentState to track unverified reports, including the reason and available tool count. - Updated tests to ensure correct behavior when the source registry is empty and when sources are captured.
|
@cdgamarose-nv Solving issue #235 |
Greptile SummaryThis PR refactors how
Confidence Score: 4/5The deep-researcher logic change is sound, but the chat_researcher node does not yet read citation_verification_status, so users can receive an unverified or potentially hallucinated deep-research report with no indication that source verification was skipped. The state-model and deep-researcher changes are clean and the new tests cover the two key branches. The gap is in chat_researcher: citation_verification_status is populated by deep_researcher but never inspected when building the response returned to the caller, meaning the unverified-report UX improvement the PR is building toward is currently absent. src/aiq_agent/agents/chat_researcher/agent.py — the citation_verification_status field on the returned DeepResearchAgentState is not yet consumed here. Important Files Changed
Sequence DiagramsequenceDiagram
participant CR as ChatResearcherAgent
participant DR as DeepResearcherAgent
participant SRM as SourceRegistryMiddleware
participant CV as citation_verification
CR->>DR: deep_research_fn(deep_state)
DR->>DR: agent.ainvoke() [retry loop]
DR->>SRM: _get_registry().all_sources()
alt Sources captured
SRM-->>DR: [source list]
DR->>CV: verify_citations(report, registry)
CV-->>DR: verified_report
DR-->>CR: "DeepResearchAgentState(citation_verification_status=None)"
else Empty source registry
SRM-->>DR: []
DR->>DR: validate_tool_availability()
alt "available_count == 0"
DR->>DR: logger.error(all tools unavailable)
else "available_count > 0"
DR->>DR: logger.warning(model answered without search)
end
DR->>DR: "result[citation_verification_status] = {status: unverified, ...}"
DR-->>CR: "DeepResearchAgentState(citation_verification_status={status: unverified, ...})"
Note over CR: citation_verification_status NOT checked - unverified report returned silently
end
Reviews (2): Last reviewed commit: "refactor: update error handling in deep ..." | Re-trigger Greptile |
| subagents: list[dict[str, Any]] = Field(default_factory=list) | ||
| clarifier_result: str | None = None | ||
| available_documents: list[AvailableDocument] | None = None | ||
| citation_verification_status: dict[str, Any] | None = None |
There was a problem hiding this comment.
Untyped status dict — consider a dedicated model
citation_verification_status is typed as dict[str, Any] | None, but its shape is well-defined (keys: status, reason, available_tool_count, unavailable_tools). An untyped dict makes downstream access error-prone and provides no validation. Introducing a small Pydantic model (e.g. CitationVerificationStatus) would let Pydantic enforce the schema and allow type-safe attribute access without changing the public interface.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Not adopting here — DeepResearchAgentState uses untyped dict[str, Any] consistently for its structured payload fields (user_info, tools_info, files, subagents, todos). Adding a typed model just for citation_verification_status would break that pattern for one field while the schema is still settling (downstream consumers in chat_researcher / API not yet wired).
For this repo: prefer matching the existing dict[str, Any] convention on DeepResearchAgentState and similar state bags. If we want type safety later, the right move is to convert all of them together, not per-field.
- Removed the raising of EmptySourceRegistryError when no verifiable sources are found during deep research. - Retained commented-out code for reference, indicating the previous error handling approach. - Adjusted the flow to ensure reports are returned with citation verification status, preventing loss of information when sources are unavailable.