1. Tool-Set Pruning:
- Replaced full 18-tool array (~3,130 tokens) on every call with intent-based subsets (5-7 tools = ~700-900 tokens).
- Added select_tools(query) covering MARKET_TOOLS, ANOMALY_TOOLS, PROPERTY_TOOLS, and GEO_TOOLS.
- All subsets include generate_data_export.
2. Synthesis Tool Stripping & Dynamic Token Budget:
- Tool-call rounds send selected tools with max_tokens=300 (tool JSONs are small).
- Synthesis round strips all tools completely (saving 3,130 tokens on final generation) and raises max_tokens to 2,000 to prevent report truncation (resolves finish_reason='length').
3. Session History Fact Compression:
- Implemented _compress_for_history() to store factual text summaries in session history while delivering full rich markdown tables to users.
- Saves ~85% history tokens per turn.
4. Hard Cap on Tool Result Payloads:
- Lowered max returned rows from 50 to 30 and enforced a 2,000-character ceiling per tool result in compress_tool_output()…
refactor: split groq_service into focused modules + SSE streaming