trustgraph/tests/unit/test_retrieval
cybermaggedon 14e49d83c7
Expose LLM token usage across all service layers (#782)
Expose LLM token usage (in_token, out_token, model) across all
service layers

Propagate token counts from LLM services through the prompt,
text-completion, graph-RAG, document-RAG, and agent orchestrator
pipelines to the API gateway and Python SDK. All fields are Optional
— None means "not available", distinguishing from a real zero count.

Key changes:

- Schema: Add in_token/out_token/model to TextCompletionResponse,
  PromptResponse, GraphRagResponse, DocumentRagResponse,
  AgentResponse

- TextCompletionClient: New TextCompletionResult return type. Split
  into text_completion() (non-streaming) and
  text_completion_stream() (streaming with per-chunk handler
  callback)

- PromptClient: New PromptResult with response_type
  (text/json/jsonl), typed fields (text/object/objects), and token
  usage. All callers updated.

- RAG services: Accumulate token usage across all prompt calls
  (extract-concepts, edge-scoring, edge-reasoning,
  synthesis). Non-streaming path sends single combined response
  instead of chunk + end_of_session.

- Agent orchestrator: UsageTracker accumulates tokens across
  meta-router, pattern prompt calls, and react reasoning. Attached
  to end_of_dialog.

- Translators: Encode token fields when not None (is not None, not truthy)

- Python SDK: RAG and text-completion methods return
  TextCompletionResult (non-streaming) or RAGChunk/AgentAnswer with
  token fields (streaming)

- CLI: --show-usage flag on tg-invoke-llm, tg-invoke-prompt,
  tg-invoke-graph-rag, tg-invoke-document-rag, tg-invoke-agent
2026-04-13 14:38:34 +01:00
..
test_structured_diag Pub/sub abstraction: decouple from Pulsar (#751) 2026-04-01 20:16:53 +01:00
test_document_rag.py Expose LLM token usage across all service layers (#782) 2026-04-13 14:38:34 +01:00
test_document_rag_provenance_integration.py Expose LLM token usage across all service layers (#782) 2026-04-13 14:38:34 +01:00
test_document_rag_service.py Expose LLM token usage across all service layers (#782) 2026-04-13 14:38:34 +01:00
test_graph_rag.py Expose LLM token usage across all service layers (#782) 2026-04-13 14:38:34 +01:00
test_graph_rag_explain_forwarding.py Forward missing explain_triples through RAG clients and agent tool callback (#768) 2026-04-08 11:41:17 +01:00
test_graph_rag_provenance_integration.py Expose LLM token usage across all service layers (#782) 2026-04-13 14:38:34 +01:00
test_graph_rag_service.py Expose LLM token usage across all service layers (#782) 2026-04-13 14:38:34 +01:00
test_nlp_query.py Fix/sys integration issues (#494) 2025-09-05 08:38:15 +01:00
test_structured_query.py Structured data 2 (#645) 2026-02-23 15:56:29 +00:00