Skip to content

v0.6.0

Choose a tag to compare

@mikecarroll mikecarroll released this 01 Nov 21:14
· 18 commits to main since this release
07fe543

๐Ÿš€ What's New

Squishling v0.6.0 adds prompt caching, on by default: each request asks the provider to cache the stable part of the prompt (the purpose and the note on the inputs), so repeated calls and a call's retries can read it back instead of paying for it again. You can control it per class, method, escalation step or squish! call, see whether it hits in cache_read_tokens and cache_write_tokens, and budget for it: max_total_input_tokens counts cache writes but, by default, not cheap reads.

gem "squishling", "~> 0.6"

Requires Ruby 3.3+ and an adapter: the ruby_llm gem (2.1+) or any OpenAI-compatible endpoint.


โš ๏ธ Upgrading from 0.5.1

Caching is on by default, so read these before upgrading.

1. Requests now ask the provider to cache the prompt. With the RubyLLM adapter, each request goes out with RubyLLM's with_caching. Anthropic Claude charges a premium for writing a cache entry (about 1.25x the input price for the 5-minute lifetime) and pays it back only when a later request reads it, so a class with a long prompt that is called once and never again costs slightly more. Opt out globally, or where it doesn't pay off:

Squishling.configure { |c| c.default_cache = false }   # every call

class Triager
  include Squishling
  squishling cache: false                              # this class (and subclasses)
end

A model that can't take cache controls may reject the request. That raises ConfigurationError (never retried), so set cache: false for that model. The OpenAI-compatible adapter ignores the setting, and providers that cache on their own (OpenAI, Google Gemini) still do.

2. max_total_input_tokens now counts tokens written to the prompt cache. RubyLLM reports them apart from input_tokens, so a call that writes a large cached prompt can reach the budget sooner than before. Tokens read back from the cache are left out unless you opt in:

Squishling.configure { |c| c.budget_counts_cache_reads = true }   # default: false

Output tokens are unchanged.

3. The OpenAI-compatible adapter reports input_tokens net of cached tokens, as every adapter does: cached reads go to cache_read_tokens and a server's cache writes to cache_write_tokens. Code that read input_tokens from squawk usage or an observer for this adapter sees a smaller number on cache hits. A custom adapter's input_tokens should likewise exclude cached tokens.


๐Ÿ’ธ Prompt Caching

cache is true, false, or a Hash of options for the provider. Each level overrides the one above, nil inherits, and a Hash replaces the level above's rather than merging into it:

Squishling.configure { |c| c.default_cache = false }              # every call (default: true)

class Triager
  include Squishling
  squishling cache: false                                         # this class (and subclasses)

  squish :triage, cache: { ttl: "1h" } do                         # one method
    string :priority
  end
end

squish!(cache: false, escalation: ["claude-opus-5-5"])            # one hand-off
# escalation: [{ model: "claude-haiku-4-5", cache: false }, "claude-sonnet-5-5"]   # one step

There is no class-level cache false macro, since it would collide with ActiveRecord::Base.cache: use squishling cache: false. A System One judgment (type: :judgment) is never cached. A prefix below the model's minimum is simply not cached, a harmless no-op. See Prompt caching.


๐Ÿ‘€ See Whether It Hits

Observer::Usage gains cache_read_tokens and cache_write_tokens (nil when the provider reports none), and they appear in squawk's usage. For adapter authors, Adapter::Request, ModelPath::Step and Testing::Request gain a cache member that defaults to false, so existing constructors keep working, and an adapter reports cache usage as :cache_read_tokens and :cache_write_tokens in Adapter::Response#tokens. See Adapters and Observers.


๐Ÿ”Œ More Adapters

The adapter docs now list two separate adapter gems built on Squishling.register_adapter: squishling-apple_fm (the on-device model in macOS, free and offline, for development) and squishling-claude_code (your local Claude Code CLI, on your own subscription instead of API billing).


โš ๏ธ Worth Knowing

None of these is a regression from 0.5.1:

  • #78 is partly fixed (in 0.5.1): still open are Struct, Data, OpenStruct and Set arguments being sent as their inspect string, and Testing.no_llm_call swapping the process-wide adapter, so it isn't safe under parallel test threads. Observer::Call#purpose is the fully rendered system prompt, so treat it as sensitive.
  • #91: reserved params keys are matched case-sensitively, and a few protocol keys (such as Bedrock additionalModelRequestFields) aren't reserved.
  • #92: some overlong-prompt detection still follows message text, and a TLS failure is an LLMError under RubyLLM but a ConfigurationError under the OpenAI-compatible adapter.
  • #93: whether the API key can be captured from in-flight local variables by tools such as Sentry's include_local_variables is being investigated.

๐Ÿ”— Resources