You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(providers): prompt caching capability and usage-based cache pricing
Replace the arbitrary cached-rate heuristic with a single cache-aware pricing
function, and add prompt caching as an opt-in capability for Anthropic.
Pricing: priceModelUsage in cost-policy.ts is now the only place cache
arithmetic happens. Provider adapters normalize their wire shape into
ModelUsage (input always excludes cache buckets); the pricing function never
branches on provider. This removes five divergent behaviors, including the
!!request.context heuristic that gave Router and Evaluator an unearned 10x
input discount, and the overwrite that silently billed Anthropic cache reads
and writes at zero. Also parses OpenAI cache_write_tokens, previously ignored.
Caching: Anthropic gets a capability-gated advanced switch that places
cache_control on the last tool and last system block; system is now always a
TextBlockParam array. OpenAI gets a stable per-block prompt_cache_key with no
UI, since its caching is automatic.
Copy file name to clipboardExpand all lines: apps/docs/content/docs/en/workflows/blocks/agent.mdx
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,8 +80,11 @@ Some settings live under advanced, or appear only for models that support them:
80
80
-**Temperature.** How varied the output is. Stay low (0–0.3) when you need accuracy and repeatability, middle (around 0.5) for everyday work, higher (0.7+) when you want creative variety.
81
81
-**Max output tokens.** Caps the response length. Defaults to the model's full limit.
82
82
-**Reasoning effort / Thinking level.** For models with extended reasoning, how much the model thinks before answering. Higher is more thorough but slower and costs more tokens.
83
+
-**Prompt caching.** For Anthropic Claude models, reuses the system prompt and tool definitions between runs instead of re-reading them every time. Cached input costs a tenth of the normal rate, but writing the cache costs 1.25x, so leave it off for one-off runs and turn it on when the same agent runs repeatedly. The cache covers a prefix only if it reaches 1,024 tokens (2,048 on Haiku) — below that Anthropic ignores it and nothing changes. Entries expire after five minutes of no use.
83
84
-**API key.** Your key for the chosen provider. Hidden on hosted Sim, which supplies one.
84
85
86
+
OpenAI and Gemini cache automatically at no extra cost and need no setting; their discount is already reflected in what you are charged.
87
+
85
88
## Outputs
86
89
87
90
After the agent runs, later blocks read its result by name:
@@ -141,6 +144,7 @@ The Agent reads the message from Start with `<start.input>` and returns a result
141
144
{ question: "What is the difference between the tool usage controls (Auto, Force, None)?", answer: "In Auto, the model decides when to call a tool based on context. In Force, the model must call the tool on every run. In None, the tool is hidden from the model and never sent, which disables it without removing it from the block." },
142
145
{ question: "How does the Response Format work?", answer: "It enforces structured output by providing a JSON Schema. When set, the model's response is constrained to match the schema exactly, and each field is read directly by downstream blocks using <agent.fieldName>. Without a response format, the agent returns its standard outputs: content, model, tokens, and toolCalls." },
143
146
{ question: "What does the Reasoning Effort / Thinking Level setting do?", answer: "They appear only for models that support extended reasoning. Reasoning Effort (OpenAI o-series and GPT-5 models) and Thinking Level (Anthropic Claude and Gemini models with thinking) control how much compute the model spends reasoning before responding. Higher levels produce more thorough answers but cost more tokens and take longer." },
147
+
{ question: "When should I turn on Prompt Caching?", answer: "Turn it on when the same agent runs repeatedly with a large, stable system prompt or tool set — cached input bills at a tenth of the normal input rate. Leave it off for one-off runs, because writing the cache costs 1.25x and nothing reads it back. The setting appears only for Anthropic Claude models; OpenAI and Gemini cache automatically with no setting and no write fee. Anthropic only caches a prefix of at least 1,024 tokens (2,048 on Haiku), and entries expire after five minutes of no use." },
144
148
{ question: "How does max output tokens work with Anthropic models?", answer: "The Agent block uses each Anthropic model's full max output token limit by default (for example, 64,000 tokens). You can override this with the Max Output Tokens setting. For non-streaming requests that exceed the SDK's internal threshold, the provider automatically uses internal streaming to avoid timeouts." },
145
149
{ question: "Can I use the Agent block with a custom or self-hosted model?", answer: "Yes. Use any Ollama or VLLM-compatible model by typing the model name directly into the model combobox, as long as it exposes a compatible API endpoint." },
Copy file name to clipboardExpand all lines: apps/docs/content/docs/en/workflows/deployment/agent-events.mdx
+12-8Lines changed: 12 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,11 @@ Agent blocks can emit more than answer text while they run: **provider-exposed t
12
12
Sim does **not** invent thinking for providers that do not stream it. Bedrock Converse, many OpenAI-compat models, and non-reasoning chat models stay text-only (plus tools when a live tool loop is wired).
Thinking and tool frames each require the stream protocol header plus their own deployment policy:
17
+
Sending the header is a statement about the **client**: it understands v1 framing, so answer text can stream live and be retracted with `chunk_reset`. That alone does not expose anything — it only changes cadence, and it applies even when both event policies are off.
18
+
19
+
Thinking and tool frames need the header **plus** their own deployment policy:
@@ -24,15 +26,15 @@ Thinking and tool frames each require the stream protocol header plus their own
24
26
X-Sim-Stream-Protocol: agent-events-v1
25
27
```
26
28
27
-
Legacy clients that omit the header keep today’s text-only SSE even if either deployment policy is enabled. The hosted chat UI always sends the header for its own deployments.
29
+
Legacy clients that omit the header keep today’s text-only SSE even if either deployment policy is enabled. The hosted chat UI always sends the header for its own deployments, so hosted chats stream token by token regardless of the toggles.
28
30
29
31
## Simple SSE frame shapes
30
32
31
33
Answer text stays on `chunk`. Thinking and tools never reuse `chunk` (so older clients that append every `chunk` into the answer cannot leak thinking).
32
34
33
35
| Frame | Meaning |
34
36
|-------|---------|
35
-
|`{ "blockId", "chunk": "…" }`| Answer text. Legacy clients receive settled final-turn text; opted-in clients receive it live as the model generates (see below) |
37
+
|`{ "blockId", "chunk": "…" }`| Answer text. Legacy clients receive settled final-turn text in one piece; opted-in clients receive it live as the model generates (see below) |
36
38
|`{ "blockId", "event": "chunk_reset" }`| Opted-in only: discard the block’s streamed answer text — it belonged to a turn that resolved to tool calls |
@@ -45,8 +47,8 @@ Answer text stays on `chunk`. Thinking and tools never reuse `chunk` (so older c
45
47
46
48
During a live tool loop, the model can’t be classified mid-turn: text it emits may turn out to be the final answer or preamble before a tool call (the stop reason arrives only at turn end).
47
49
48
-
-**Opted-in clients** (protocol header + either event policy) receive answer text as `chunk` frames **live**, token by token. If the turn then resolves to tool calls, a `chunk_reset` frame tells the client to discard that block’s streamed text — the final turn re-streams live after tools settle. Append `chunk`, honor `chunk_reset`, and the displayed answer always converges to the block’s final content.
49
-
-**Legacy clients** (no header) never see provisional text: only settled final-turn text is emitted as `chunk`, delivered when the turn completes.
50
+
-**Opted-in clients** (protocol header; no event policy required) receive answer text as `chunk` frames **live**, token by token. If the turn then resolves to tool calls, a `chunk_reset` frame tells the client to discard that block’s streamed text — the final turn re-streams live after tools settle. Append `chunk`, honor `chunk_reset`, and the displayed answer always converges to the block’s final content.
51
+
-**Legacy clients** (no header) never see provisional text: only settled final-turn text is emitted as `chunk`, delivered in one piece when the turn completes. Honoring `chunk_reset` is what buys live cadence, so send the header if you want it.
50
52
51
53
Logs, memory, and the block’s `content` output always contain final-turn text only — intermediate preamble is never persisted.
52
54
@@ -71,7 +73,9 @@ The terminal output panel shows Thinking / Tools chrome above the block output w
71
73
72
74
## Chat deployment toggles
73
75
74
-
In **Deploy → Chat**, enable **Include thinking** for provider-exposed thinking and **Include tool calls** for tool names and lifecycle status. The switches are independent, and both event types still require the protocol header. Tool arguments and results are never included in lifecycle frames. Redeploy or update the chat after changing Agent models or tools.
76
+
In **Deploy → Chat**, enable **Include thinking** for provider-exposed thinking and **Include tool calls** for tool names and lifecycle status. The switches are independent, and both event types still require the protocol header. Neither switch affects answer-text cadence.
77
+
78
+
Tool arguments and results are never exposed to a public chat — not in lifecycle frames, and not through the terminal `final` envelope, where the block's own tool calls are reduced to the same name-and-lifecycle shape. The authenticated workflow API still returns full tool results. Redeploy or update the chat after changing Agent models or tools.
75
79
76
80
## Capability honesty (high level)
77
81
@@ -81,7 +85,7 @@ Per-model support is generated from the model registry on the [Agent block page]
81
85
|--------|----------|------------|
82
86
| Anthropic / Azure Anthropic | Yes (incl. redacted blocks in traces). The newest Claude generations omit full thinking; Sim requests summarized thinking for them on streaming runs | Yes |
83
87
| Gemini / Vertex | Yes when a thinking level is set (thought summaries requested on agent-events runs) | Yes |
84
-
| OpenAI Responses | Reasoning **summaries** when streamed (requires OpenAI organization verification; unverified orgs fall back to no summaries) |Silent tool loop; tool chips arrive settled (start + end together) once tools finish, ahead of the streamed answer — no live in-progress chips yet|
88
+
| OpenAI Responses | Reasoning **summaries** when streamed (requires OpenAI organization verification; unverified orgs fall back to no summaries) |Yes|
85
89
| OpenAI-compat (Groq, DeepSeek, …) | Only if vendor streams `reasoning` / `reasoning_content`| Live loop where wired (e.g. Groq, DeepSeek) |
86
90
| Bedrock | Not invented | Yes when streaming tool loop is used |
@@ -308,6 +310,19 @@ Return ONLY the JSON array.`,
308
310
value: MODELS_WITH_THINKING,
309
311
},
310
312
},
313
+
{
314
+
id: 'promptCaching',
315
+
title: 'Prompt Caching',
316
+
type: 'switch',
317
+
description:
318
+
'Cache the system prompt and tool definitions so repeat runs reuse them at a reduced rate. Writing the cache costs more than a normal request, so this pays off when the same prompt runs repeatedly.',
319
+
defaultValue: false,
320
+
mode: 'advanced',
321
+
condition: {
322
+
field: 'model',
323
+
value: MODELS_WITH_PROMPT_CACHING,
324
+
},
325
+
},
311
326
312
327
...getProviderCredentialSubBlocks(),
313
328
{
@@ -646,6 +661,10 @@ Return ONLY the JSON array.`,
646
661
type: 'string',
647
662
description: 'Thinking level for models with extended thinking (Anthropic Claude, Gemini 3)',
648
663
},
664
+
promptCaching: {
665
+
type: 'boolean',
666
+
description: 'Cache the system prompt and tool definitions on models that support it',
0 commit comments