ask-agent 0.8.1 → 0.9.0

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: 82d7ec2cb06f4ce9cbaa41ece0ac4800772b44dcbe54c33e46f6edefb863f1b2
4
+ data.tar.gz: b8b5cfec092ae7b0117f0a4ec3b441becc0ea21c806107cb0ae9c51c5b215618
5
5
  SHA512:
6
- metadata.gz: cc258ca1b71919c61a5986f18190c3c5b2bed2d17d1f8efa6e63a8f8f37e258694603ce9b9c382e1843b6c03f94f7121b976f2875d9e429146bd024dfbd9162c
7
- data.tar.gz: b371ea561dcd8d67e49c26e0fa18eaa0d142040f0e1adb4de7eba9c517d5cc7e03892dda1edccf2f0b46a3c2e672408f4fe8103547dee9ebd029f5d6f23d0482
6
+ metadata.gz: d9a3dd55f214105d58858f31122a0064a9a94165f37d5b8fc8d1f202ce87fe19ff8ad4f0c6e52de1d66bf115940e3c48e8673762d16912514668b82cabd8daa3
7
+ data.tar.gz: ecaecabad77df46494a9ee0f99840cbeeaf59163cecaf1ccb8af8810e98bfa8333455c1ed3b50d1bc66c106c38e74b98329d28fea3d2e4393cacdd9453213c23
data/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## [0.9.0] — 2026-07-21
2
+
3
+ ### Added
4
+
5
+ - **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.
6
+
7
+ ```ruby
8
+ # Global config
9
+ Ask::Agent.configure do |c|
10
+ c.prompt_caching = true
11
+ end
12
+
13
+ # Or per-session
14
+ session = Ask::Agent::Session.new(model: "claude-sonnet-4", prompt_caching: true)
15
+ ```
16
+
17
+ **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`.
18
+
19
+ **OpenAI**: Caching is automatic for prompts exceeding 1024 tokens. Response metadata includes `cached_tokens` from `usage.prompt_tokens_details.cached_tokens`.
20
+
21
+ - **Prompt caching capability** — Both `Ask::Providers::Anthropic` and `Ask::Providers::OpenAI` now advertise `prompt_caching: true` in their capabilities.
22
+
1
23
  ## [0.8.1] — 2026-07-21
2
24
 
3
25
  ### 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,6 +19,7 @@ module Ask
19
19
  @compactor_enabled = true
20
20
  @compactor_threshold = 0.8
21
21
  @parallel_tool_execution = true
22
+ @max_tool_retries = 3
22
23
  @prompt_caching = false
23
24
 
24
25
  @middleware = Middleware::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.0"
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaka Ruto