Back to Notes

AskTGE Work Summary

AskTGE Engineering Work Summary

All implementation complete. Individual planning docs deleted.


Performance Fixes — All Done

14 issues identified and resolved across AskTGE + multiagent-backend:

#IssueFix
1Frontend chunk accumulation (50× bandwidth waste)Delta-only forwarding via last_sent_len offset — O(N²) → O(N)
2AUnnecessary KB search on doc analysis (prompt)System prompt instructs LLM not to KB-search attached document content
2BUnnecessary KB search on doc analysis (routing)Removed not has_files hard-block — Issue 2A prompt handles nuance
3No prompt caching (guardrails re-scanned every turn)cachePoint injected into system prompt + tool definitions via CachingBedrockConverse subclass
4Sequential KB tool executionReplaced ToolNode with asyncio.gather parallel executor
5Cross-region inference latencyclaude-sonnet-4-6 confirmed available in ap-southeast-2, BEDROCK_MODEL_ID updated
6Synchronous presigned URL generationS3 calls batch-enriched post-stream via asyncio.gather + asyncio.to_thread
7Duplicate citation enrichmentRemoved URL generation from event_parser.py — single enrichment path in app.py
8aVerbose logging in prod + stagingLOG_LEVEL=WARNING in .env.prod and .env.staging
8bRegex not pre-compiled_RE_CONTENT, _RE_TEXT, _RE_NAME compiled once at module load
9Duplicate tool usage SSE eventsrun_id dedup guard in _parse_tool_start
10Repeated thinking messages_thinking_sent flag suppresses all but first thinking event per request
11Eager LLM/graph compilation at importLazy _get_llm() / _build_tools_graph() — nothing built until first request
12System prompt mismatch (~1,400 extra tokens)SystemMessage stripped from incoming messages in app.py before graph — seed node owns system prompt
13Guardrail scope (4 policies on doc analysis)Reduced to 2 guardrail policies for doc analysis use cases

Impact (combined):

  • Document analysis: ~21s → ~6s (~70% faster)
  • KB query: ~20s → ~14s (~30% faster)
  • SSE bandwidth: ~150 KB → ~3 KB per 1,000-token response (50× reduction)
  • Input token cost (turn 2+): ~90% reduction via prompt caching

Code Deduplication — All Done

Key refactors across AskTGE codebase:

ItemWhat changed
Session validation@require_valid_session decorator — replaced 30+ duplicated 5-line blocks
Configuration moduleconfig/settings.py — unified config replacing simple_config.py
Document convertersConsolidated converter modules, removed duplication
SSE terminal eventsCollapsed final_response + complete into single complete terminal event
Citation handlingRemoved 2 redundant citation capture blocks from chat_service.py — only complete event captures
time.sleep auditRemoved 7 artificial progress-pacing sleeps from chat_service.py

Configuration Migration — Done

simple_config.py → config/settings.py migration complete. All route files updated to use new config. Migration guide followed and confirmed.