From dbbe5ba808a60341474a0a510d92c967e26106e5 Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Wed, 8 Apr 2026 10:42:56 +0100 Subject: [PATCH] fix: forward explain_triples through RAG clients and agent tool callback RAG clients and the KnowledgeQueryImpl tool callback were dropping explain_triples from explain events, losing provenance data (including focus edge selections) when graph-rag is invoked via the agent. --- trustgraph-base/trustgraph/base/graph_rag_client.py | 4 ++-- trustgraph-base/trustgraph/clients/document_rag_client.py | 4 ++-- trustgraph-base/trustgraph/clients/graph_rag_client.py | 4 ++-- trustgraph-flow/trustgraph/agent/react/tools.py | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/trustgraph-base/trustgraph/base/graph_rag_client.py b/trustgraph-base/trustgraph/base/graph_rag_client.py index 32007943..9db23293 100644 --- a/trustgraph-base/trustgraph/base/graph_rag_client.py +++ b/trustgraph-base/trustgraph/base/graph_rag_client.py @@ -15,7 +15,7 @@ class GraphRagClient(RequestResponse): user: User identifier collection: Collection identifier chunk_callback: Optional async callback(text, end_of_stream) for text chunks - explain_callback: Optional async callback(explain_id, explain_graph) for explain notifications + explain_callback: Optional async callback(explain_id, explain_graph, explain_triples) for explain notifications timeout: Request timeout in seconds Returns: @@ -30,7 +30,7 @@ class GraphRagClient(RequestResponse): # Handle explain notifications if resp.message_type == 'explain': if explain_callback and resp.explain_id: - await explain_callback(resp.explain_id, resp.explain_graph) + await explain_callback(resp.explain_id, resp.explain_graph, resp.explain_triples) return False # Continue receiving # Handle text chunks diff --git a/trustgraph-base/trustgraph/clients/document_rag_client.py b/trustgraph-base/trustgraph/clients/document_rag_client.py index 057376fb..365ea09d 100644 --- a/trustgraph-base/trustgraph/clients/document_rag_client.py +++ b/trustgraph-base/trustgraph/clients/document_rag_client.py @@ -43,7 +43,7 @@ class DocumentRagClient(BaseClient): user: User identifier collection: Collection identifier chunk_callback: Optional callback(text, end_of_stream) for text chunks - explain_callback: Optional callback(explain_id, explain_graph) for explain notifications + explain_callback: Optional callback(explain_id, explain_graph, explain_triples) for explain notifications timeout: Request timeout in seconds Returns: @@ -55,7 +55,7 @@ class DocumentRagClient(BaseClient): # Handle explain notifications (response is None/empty, explain_id present) if x.explain_id and not x.response: if explain_callback: - explain_callback(x.explain_id, x.explain_graph) + explain_callback(x.explain_id, x.explain_graph, x.explain_triples) return False # Continue receiving # Handle text chunks diff --git a/trustgraph-base/trustgraph/clients/graph_rag_client.py b/trustgraph-base/trustgraph/clients/graph_rag_client.py index 17d7b0f0..0d33bf91 100644 --- a/trustgraph-base/trustgraph/clients/graph_rag_client.py +++ b/trustgraph-base/trustgraph/clients/graph_rag_client.py @@ -47,7 +47,7 @@ class GraphRagClient(BaseClient): user: User identifier collection: Collection identifier chunk_callback: Optional callback(text, end_of_stream) for text chunks - explain_callback: Optional callback(explain_id, explain_graph) for explain notifications + explain_callback: Optional callback(explain_id, explain_graph, explain_triples) for explain notifications timeout: Request timeout in seconds Returns: @@ -59,7 +59,7 @@ class GraphRagClient(BaseClient): # Handle explain notifications if x.message_type == 'explain': if explain_callback and x.explain_id: - explain_callback(x.explain_id, x.explain_graph) + explain_callback(x.explain_id, x.explain_graph, x.explain_triples) return False # Continue receiving # Handle text chunks diff --git a/trustgraph-flow/trustgraph/agent/react/tools.py b/trustgraph-flow/trustgraph/agent/react/tools.py index 041558ec..6fd96ade 100644 --- a/trustgraph-flow/trustgraph/agent/react/tools.py +++ b/trustgraph-flow/trustgraph/agent/react/tools.py @@ -39,13 +39,14 @@ class KnowledgeQueryImpl: if respond: from ... schema import AgentResponse - async def explain_callback(explain_id, explain_graph): + async def explain_callback(explain_id, explain_graph, explain_triples=None): self.context.last_sub_explain_uri = explain_id await respond(AgentResponse( chunk_type="explain", content="", explain_id=explain_id, explain_graph=explain_graph, + explain_triples=explain_triples or [], )) if current_uri: