|
1 | | -Yes, 30k tokens is plausible. |
2 | | -Why it makes sense: |
3 | | -Gemini counts all input and output tokens, not just the short user prompt. Google’s docs say usage includes input, output, thinking, cached, and tool-use tokens, and that system instructions count as input too. Source: https://ai.google.dev/gemini-api/docs/tokens |
4 | | -In our current design, each provider turn sends a large payload:system_prompt |
5 | | -full graph_context |
6 | | -full tool definitions |
7 | | -conversation history |
8 | | -tool results |
9 | | - |
10 | | -We also did multi-turn loops. Google documents that multi-turn usage can include prior context, so later turns can be more expensive than they look. Source: https://ai.google.dev/gemini-api/docs/tokens |
11 | | -Your logs showed repeated tool calls and retries, which multiply the cost fast. |
12 | | -So even a tiny prompt like Tell me about node 1648030 can burn a surprising number of tokens if the request envelope is large. |
13 | | -Rough intuition: |
14 | | -30k tokens is only about 120k characters of effective counted context |
15 | | -a few repeated turns with big JSON context can absolutely get there |
16 | | -The biggest contributors in our setup are probably: |
17 | | -full graph context every turn |
18 | | -full transcript every turn |
19 | | -full tool result payloads every turn |
20 | | -repeated provider iterations |
21 | | -Good news: |
22 | | -the fixes we already made should reduce this |
23 | | -the next big optimization would be trimming the provider payload, especially graph_context and repeated history/tool-result content |
24 | | -If you want, next I can make a focused token-reduction pass on the provider payload so Gemini usage drops sharply without changing behavior much. |
| 1 | +I added the detailed schema plan in [compact_provider_context.schema.txt](/Users/jregalado/Projects/GeoGenetics/unicorn/src/libunicorn/graphengine/unicorn_agent/compact_provider_context.schema.txt). |
| 2 | +It covers: |
| 3 | +why the compact context exists |
| 4 | +the backend-first assembly mechanism |
| 5 | +the exact proposed top-level schema |
| 6 | +which fields belong in session, datasets, taxonomy, filters, tree, selection, table, report, and capabilities |
| 7 | +which large-context fields should be removed |
| 8 | +token-budget and truncation strategy |
| 9 | +implementation order and validation prompts |
| 10 | +The core idea in the doc is: the provider should receive a small backend-owned grounding snapshot, and use Unicorn tools for detail instead of getting a giant upfront context envelope. |
| 11 | +If you want, the next step can be very concrete: I can map this schema against the current buildAgentContext() field-by-field and show exactly what stays, what shrinks, and what moves to the backend. |
0 commit comments