ask-agent 0.8.1 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a50ba3d8610e0e05d54ff53c23757a4ef6ecfddb3bc43094d469ebd252e6cfa
4
- data.tar.gz: 2269528d25df7991e2aefbc84c4fc89a5a6a4ac4b1d9fbfb95ab9dd421bfa9ba
3
+ metadata.gz: edea591926e0360d2eb24990d423ef183e3abf99bc141df768a7ee11774db288
4
+ data.tar.gz: 2e5f013ee517281679e0ab717792ce3110411389b1b2df185b7d6c4c7636e106
5
5
  SHA512:
6
- metadata.gz: cc258ca1b71919c61a5986f18190c3c5b2bed2d17d1f8efa6e63a8f8f37e258694603ce9b9c382e1843b6c03f94f7121b976f2875d9e429146bd024dfbd9162c
7
- data.tar.gz: b371ea561dcd8d67e49c26e0fa18eaa0d142040f0e1adb4de7eba9c517d5cc7e03892dda1edccf2f0b46a3c2e672408f4fe8103547dee9ebd029f5d6f23d0482
6
+ metadata.gz: d7a430b5c791d0d25920836d604f529b1cac16e8c608f6ebaf1c04b0e5b449a1887c8b3a293ed1e2c6e75cdea23fc7c8614f0e80860c6cfad234951eaf8bc1f7
7
+ data.tar.gz: 580ccbb6e82210c446f7c8669d0b57a3fb90297156502d6a6c4a872c3f871c6838722c754fe02577083dc49f5cd28da9365d5f9da800d5e1921302bd8bd10958
data/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ ## [0.9.1] — 2026-07-21
2
+
3
+ ### Changed
4
+
5
+ - **`prompt_caching` now defaults to `true`** globally. All sessions automatically send cache-control hints to supporting providers (Anthropic, OpenAI). Non-supporting providers ignore the parameter safely.
6
+
7
+ ## [0.9.0] — 2026-07-21
8
+
9
+ ### Added
10
+
11
+ - **Prompt caching support** — `prompt_caching` option enables provider-native prompt caching for significant cost savings on repeated conversation prefixes. Works with both Anthropic and OpenAI.
12
+
13
+ ```ruby
14
+ # Global config
15
+ Ask::Agent.configure do |c|
16
+ c.prompt_caching = true
17
+ end
18
+
19
+ # Or per-session
20
+ session = Ask::Agent::Session.new(model: "claude-sonnet-4", prompt_caching: true)
21
+ ```
22
+
23
+ **Anthropic**: Caches the system prompt and the last user message content. The provider automatically returns cached reads instead of processing the full context on repeated calls. Response metadata includes `cache_creation_input_tokens` and `cache_read_input_tokens`.
24
+
25
+ **OpenAI**: Caching is automatic for prompts exceeding 1024 tokens. Response metadata includes `cached_tokens` from `usage.prompt_tokens_details.cached_tokens`.
26
+
27
+ - **Prompt caching capability** — Both `Ask::Providers::Anthropic` and `Ask::Providers::OpenAI` now advertise `prompt_caching: true` in their capabilities.
28
+
1
29
  ## [0.8.1] — 2026-07-21
2
30
 
3
31
  ### Added
@@ -33,7 +33,7 @@ module Ask
33
33
 
34
34
  attr_writer :test_provider
35
35
 
36
- def initialize(model:, tools: [], temperature: nil, schema: nil, provider: nil, **)
36
+ def initialize(model:, tools: [], temperature: nil, schema: nil, provider: nil, prompt_caching: nil, **)
37
37
  @model_id = model.respond_to?(:id) ? model.id : model.to_s
38
38
  @model_info = Ask::ModelCatalog.find(@model_id)
39
39
  @tools = tools
@@ -43,10 +43,11 @@ module Ask
43
43
  @provider_override = provider
44
44
  @provider = nil
45
45
 
46
- # Read configured middleware and stream transforms from global config
46
+ # Read configured middleware, transforms, and caching from global config
47
47
  config = Ask::Agent.configuration
48
48
  @middleware_pipeline = config.middleware.configured? ? config.middleware : nil
49
49
  @transform_pipeline = config.stream_transforms.configured? ? config.stream_transforms : nil
50
+ @prompt_caching = prompt_caching.nil? ? config.prompt_caching : prompt_caching
50
51
  end
51
52
 
52
53
  def ask(message = nil, &block)
@@ -142,6 +143,9 @@ module Ask
142
143
  # Build the request hash for the provider call.
143
144
  # Middleware can mutate this hash to inject defaults, modify params, etc.
144
145
  def build_request(stream)
146
+ extra = (@extra_params || {}).dup
147
+ extra[:prompt_caching] = true if @prompt_caching
148
+
145
149
  {
146
150
  messages: @messages.map(&:to_h),
147
151
  model: @model_id,
@@ -149,7 +153,7 @@ module Ask
149
153
  temperature: @temperature,
150
154
  stream: stream,
151
155
  schema: @schema&.respond_to?(:to_json_schema) ? @schema.to_json_schema : @schema,
152
- extra_params: (@extra_params || {}).dup
156
+ extra_params: extra
153
157
  }
154
158
  end
155
159
 
@@ -19,7 +19,8 @@ module Ask
19
19
  @compactor_enabled = true
20
20
  @compactor_threshold = 0.8
21
21
  @parallel_tool_execution = true
22
- @prompt_caching = false
22
+ @max_tool_retries = 3
23
+ @prompt_caching = true
23
24
 
24
25
  @middleware = Middleware::Pipeline.new
25
26
  @stream_transforms = StreamTransforms::Pipeline.new
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ask
4
4
  module Agent
5
- VERSION = "0.8.1"
5
+ VERSION = "0.9.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ask-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaka Ruto