Skip to content

CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.

fix(website): correct cache Usage.input_tokens docs and FAQ JSON-LD answers

xf gong21f586b5ea8d
diff --git a/website/docs/guides/agents/prompt-caching.md b/website/docs/guides/agents/prompt-caching.md
index 61518de..5c4e983 100644
--- a/website/docs/guides/agents/prompt-caching.md
+++ b/website/docs/guides/agents/prompt-caching.md
@@ -104,25 +104,29 @@ await agent.prompt("Summarise the document")
last_msg = agent.state.messages[-1] # AssistantMessage
usage = last_msg.usage
-print(usage.input_tokens) # total prompt tokens (inclusive of cache_read)
+print(usage.input_tokens) # uncached prompt tokens (excludes cache_read)
print(usage.cache_read_tokens) # tokens served from cache ← savings here
print(usage.cache_write_tokens) # tokens written to cache this turn
```
-Cache hit rate for a turn: `cache_read_tokens / input_tokens`.
+Cache hit rate for a turn:
+`cache_read_tokens / (input_tokens + cache_read_tokens + cache_write_tokens)`.
:::tip
-`input_tokens` in CubePi's `Usage` is the **inclusive** total (prompt
-= input + cache_read + cache_creation). Do **not** add `cache_read_tokens`
-to the denominator — you would be double-counting.
+`input_tokens` in CubePi's `Usage` is the **uncached** portion — tokens that
+were actually processed by the model this turn. The full prompt token count is
+`input_tokens + cache_read_tokens + cache_write_tokens`. On a 100 % cache hit,
+`input_tokens` is 0.
:::
You can also see these fields in the `cubepi trace` CLI output and in
-the OTel spans emitted by `Tracer`:
+the OTel spans emitted by `Tracer`. Note that the OTel span attribute
+`gen_ai.usage.input_tokens` follows the GenAI Semantic Convention and reports
+the **inclusive** total (uncached + cached):
```
-gen_ai.usage.input_tokens = 8 420 (inclusive)
-gen_ai.usage.cache_read.input_tokens = 7 980 (subset)
+gen_ai.usage.input_tokens = 8 420 (inclusive: uncached + cached)
+gen_ai.usage.cache_read.input_tokens = 7 980 (cached subset)
```
---
diff --git a/website/src/pages/faq.tsx b/website/src/pages/faq.tsx
index 5d1c368..2abe476 100644
--- a/website/src/pages/faq.tsx
+++ b/website/src/pages/faq.tsx
@@ -9,6 +9,19 @@ interface FaqItem {
a: React.ReactNode;
}
+/** Recursively extract plain text from a React node for use in JSON-LD. */
+function reactNodeToText(node: React.ReactNode): string {
+ if (node === null || node === undefined || typeof node === 'boolean') return '';
+ if (typeof node === 'string' || typeof node === 'number') return String(node);
+ if (Array.isArray(node)) return node.map(reactNodeToText).join('');
+ // React element
+ const el = node as React.ReactElement;
+ if (el && typeof el === 'object' && 'props' in el) {
+ return reactNodeToText(el.props.children);
+ }
+ return '';
+}
+
const EN_ITEMS: FaqItem[] = [
{
q: 'What is CubePi?',
@@ -389,8 +402,7 @@ export default function FAQ(): React.ReactElement {
name: item.q,
acceptedAnswer: {
'@type': 'Answer',
- // Strip JSX to plain text for structured data — good enough for schema.org
- text: typeof item.a === 'string' ? item.a : String(item.q),
+ text: reactNodeToText(item.a),
},
})),
};
diff --git a/website/versioned_docs/version-0.9/guides/agents/prompt-caching.md b/website/versioned_docs/version-0.9/guides/agents/prompt-caching.md
index 61518de..5c4e983 100644
--- a/website/versioned_docs/version-0.9/guides/agents/prompt-caching.md
+++ b/website/versioned_docs/version-0.9/guides/agents/prompt-caching.md
@@ -104,25 +104,29 @@ await agent.prompt("Summarise the document")
last_msg = agent.state.messages[-1] # AssistantMessage
usage = last_msg.usage
-print(usage.input_tokens) # total prompt tokens (inclusive of cache_read)
+print(usage.input_tokens) # uncached prompt tokens (excludes cache_read)
print(usage.cache_read_tokens) # tokens served from cache ← savings here
print(usage.cache_write_tokens) # tokens written to cache this turn
```
-Cache hit rate for a turn: `cache_read_tokens / input_tokens`.
+Cache hit rate for a turn:
+`cache_read_tokens / (input_tokens + cache_read_tokens + cache_write_tokens)`.
:::tip
-`input_tokens` in CubePi's `Usage` is the **inclusive** total (prompt
-= input + cache_read + cache_creation). Do **not** add `cache_read_tokens`
-to the denominator — you would be double-counting.
+`input_tokens` in CubePi's `Usage` is the **uncached** portion — tokens that
+were actually processed by the model this turn. The full prompt token count is
+`input_tokens + cache_read_tokens + cache_write_tokens`. On a 100 % cache hit,
+`input_tokens` is 0.
:::
You can also see these fields in the `cubepi trace` CLI output and in
-the OTel spans emitted by `Tracer`:
+the OTel spans emitted by `Tracer`. Note that the OTel span attribute
+`gen_ai.usage.input_tokens` follows the GenAI Semantic Convention and reports
+the **inclusive** total (uncached + cached):
```
-gen_ai.usage.input_tokens = 8 420 (inclusive)
-gen_ai.usage.cache_read.input_tokens = 7 980 (subset)
+gen_ai.usage.input_tokens = 8 420 (inclusive: uncached + cached)
+gen_ai.usage.cache_read.input_tokens = 7 980 (cached subset)
```
---