rialto.
09/29/2025, 12:34 PMgreg (BAML)
09/29/2025, 4:08 PMgreg (BAML)
09/29/2025, 4:11 PMrialto.
09/29/2025, 4:34 PMgreg (BAML)
09/29/2025, 6:40 PMrialto.
09/30/2025, 7:23 PMrialto.
10/02/2025, 3:25 PMgreg (BAML)
10/02/2025, 4:41 PMrialto.
10/04/2025, 2:14 PMgreg (BAML)
10/05/2025, 5:39 AMfunction Talk(history: Message[], query: string) -> string {
client ClaudeSonnet
prompt #"
{{ _.role("user", cache_control={"type": "ephemeral"}) }}
Conversation history: {{ history }}
{{ _.role("user") }}
{{ query }}
"#
}
If the history changes, you will get a cache miss, so this will only be helpful if the message history is a stable thing you reuse over and over.
If the conversations are more dynamic, or you need to preserve the roles of the senders of the messages, you can include the caching instruction in each message. Then you'll have cache hits for all the previously seen messages and misses for new messages:
function Talk(history: Message[], query: string) -> string {
client ClaudeSonnet
prompt #"
{% for message in history %}
{{ _.role(message.role, cache_control={"type": "ephemeral"}) }}
{{ message.content }}
{% endfor %}
{{ query }}
"#
}
You're right that the query must be recomputed each time we send a request. I've been working under the assumption that the caching you're talking about is LLM provider prompt caching (an optimization on the LLM provider's side), and not caching of the creation of the prompt on the client side.
To help me understand, could you say what would proper caching look like for you? You mentioned not wanting to rebuild your context every time, and I didn't quite follow what you mean there.