soka-rails 0.0.2 → 0.0.4

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: 956c0fc8a0ecef6e81f471a6674f4a0c7c5df800f720618ecf54a32c87583d1f
4
- data.tar.gz: d7d16aff15e796d33c284bb77f1db2f7ff42ba61dbf3fb7f76ded2e87a0758d5
3
+ metadata.gz: 5bfac5b44ed7fdb83d9355212bf03c75131ec6acb1fd1a6eae3637bd8e809f4e
4
+ data.tar.gz: 93e686020ecea4fc2cdfce51bd46859d3d18885a49ec53a8a05bb5fb4ddcda72
5
5
  SHA512:
6
- metadata.gz: fd259ec01dcb6ba6c760685a3d1f94bf0091a9298014f696c782cf7839e182651d1e9c44457ed9505bc76a6b048ab72a9bc9b16063c43b436a5b7d48ce98ad17
7
- data.tar.gz: 3383aba5cdbf64703815efe55214ad63e9ae8d8aedcd6f845c97ef4c6382cf91ba8a9cd0217c75a4fa7db38fa62507072a3550d64c8098dadfa85fd97e0585d9
6
+ metadata.gz: a279aa038cf1447539bed9f8bef7a52e15c0c41443c660ff3677753274f9d34b7cf4faea593eb23a504b66c9afab7ea4f9eeab64634d6f63ff01bf3562a22d6d
7
+ data.tar.gz: 5719156f98210602c47b05c982c3866db95e622a250633d3e5182960b8f7e91ba98fb569c0cac520239a0f80d47490ddb90dc38bae7ef23dc3f3bd5a188b4892
data/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.0.4] - 2025-08-04
9
+
10
+ ### Added
11
+ - Support for dynamic instructions in Soka v0.0.4
12
+ - Ability to generate agent instructions dynamically via methods
13
+ - Context-aware behavior based on runtime conditions (environment, time, user, etc.)
14
+ - Updated README with dynamic instructions examples
15
+ - Enhanced agent generator template with dynamic instructions examples
16
+
17
+ ## [0.0.3] - 2025-08-04
18
+
19
+ ### Added
20
+ - Upgrade to Soka v0.0.3 with custom instructions and multilingual support
21
+
8
22
  ## [0.0.2] - 2025-08-01
9
23
 
10
24
  ### Fixed
data/DESIGN.md CHANGED
@@ -478,7 +478,6 @@ module Soka
478
478
  def mock_ai_response(response_attrs = {})
479
479
  default_response = {
480
480
  final_answer: "Mocked answer",
481
- confidence_score: 0.95,
482
481
  status: :completed,
483
482
  iterations: 1,
484
483
  thought_process: []
@@ -616,7 +615,6 @@ class ConversationsController < ApplicationController
616
615
  def build_response(result)
617
616
  {
618
617
  answer: result.final_answer,
619
- confidence: result.confidence_score,
620
618
  status: result.status,
621
619
  metadata: {
622
620
  iterations: result.iterations,
@@ -652,7 +650,6 @@ class ProcessConversationJob < ApplicationJob
652
650
  user.conversations.create!(
653
651
  message: message,
654
652
  response: result.final_answer,
655
- confidence: result.confidence_score,
656
653
  metadata: {
657
654
  iterations: result.iterations,
658
655
  thought_process: result.thought_process
data/README.md CHANGED
@@ -26,6 +26,9 @@ Soka Rails is a Rails integration package for the Soka AI Agent Framework, provi
26
26
  - 🔄 **Rails Lifecycle Hooks**: Integrates with Rails logging and error tracking
27
27
  - 💾 **Session Memory Support**: Store conversation history in Rails sessions
28
28
  - 🔐 **Authentication Integration**: Works with Rails authentication systems
29
+ - 🗣️ **Custom Instructions**: Customize agent personality and behavior
30
+ - 🎯 **Dynamic Instructions**: Generate instructions dynamically via methods
31
+ - 🌐 **Multilingual Thinking**: Support for reasoning in different languages
29
32
 
30
33
  ## Installation
31
34
 
@@ -91,7 +94,7 @@ class ConversationsController < ApplicationController
91
94
 
92
95
  render json: {
93
96
  answer: result.final_answer,
94
- confidence: result.confidence_score
97
+ status: result.status
95
98
  }
96
99
  end
97
100
  end
@@ -130,6 +133,15 @@ class WeatherAgent < ApplicationAgent
130
133
  tool WeatherApiTool
131
134
  tool LocationTool
132
135
 
136
+ # Custom instructions
137
+ # instructions "You are a helpful weather assistant"
138
+
139
+ # Dynamic instructions via method
140
+ # instructions :generate_instructions
141
+
142
+ # Multilingual thinking
143
+ # think_in 'zh-TW' # Think in Traditional Chinese
144
+
133
145
  # Rails integration hooks
134
146
  before_action :log_request
135
147
  on_error :notify_error_service
@@ -144,6 +156,15 @@ class WeatherAgent < ApplicationAgent
144
156
  Rails.error.report(error, context: context)
145
157
  :continue
146
158
  end
159
+
160
+ # Example of dynamic instructions method
161
+ # def generate_instructions
162
+ # <<~PROMPT
163
+ # You are a weather assistant for #{Rails.env} environment.
164
+ # Current time: #{Time.zone.now}
165
+ # User location: #{request&.location&.city || 'Unknown'}
166
+ # PROMPT
167
+ # end
147
168
  end
148
169
  ```
149
170
 
@@ -194,6 +215,59 @@ class ConversationsController < ApplicationController
194
215
  end
195
216
  ```
196
217
 
218
+ ### Custom Instructions and Dynamic Instructions
219
+
220
+ ```ruby
221
+ class CustomerSupportAgent < ApplicationAgent
222
+ # Static instructions
223
+ instructions <<~PROMPT
224
+ You are a friendly customer support agent.
225
+ Always be polite and helpful.
226
+ Use emojis when appropriate.
227
+ PROMPT
228
+
229
+ # OR Dynamic instructions via method
230
+ instructions :generate_context_aware_instructions
231
+
232
+ private
233
+
234
+ def generate_context_aware_instructions
235
+ business_hours = (9..17).include?(Time.zone.now.hour)
236
+
237
+ <<~PROMPT
238
+ You are a customer support agent for #{Rails.application.class.module_parent_name}.
239
+ Environment: #{Rails.env}
240
+ Current time: #{Time.zone.now.strftime('%Y-%m-%d %H:%M:%S %Z')}
241
+ Business hours: #{business_hours ? 'Yes' : 'No (after hours)'}
242
+ #{business_hours ? 'Provide immediate assistance.' : 'Inform about callback options.'}
243
+ PROMPT
244
+ end
245
+ end
246
+ ```
247
+
248
+ ### Multilingual Thinking
249
+
250
+ ```ruby
251
+ class GlobalSupportAgent < ApplicationAgent
252
+ # Set default thinking language
253
+ think_in 'zh-TW' # Think in Traditional Chinese
254
+
255
+ # Or set dynamically at runtime
256
+ def initialize(options = {})
257
+ super
258
+ # Detect user's preferred language from session or request
259
+ self.think_in = detect_user_language
260
+ end
261
+
262
+ private
263
+
264
+ def detect_user_language
265
+ # Logic to detect language from session, user preferences, or request headers
266
+ session[:locale] || I18n.locale || 'en'
267
+ end
268
+ end
269
+ ```
270
+
197
271
  ### Event Streaming
198
272
 
199
273
  ```ruby
@@ -243,6 +317,15 @@ class WeatherAgent < ApplicationAgent
243
317
  tool TemperatureTool
244
318
  tool HumidityTool
245
319
 
320
+ # Custom instructions
321
+ # instructions "You are a weather expert. Always provide temperature in both Celsius and Fahrenheit."
322
+
323
+ # Dynamic instructions via method
324
+ # instructions :generate_instructions
325
+
326
+ # Multilingual thinking
327
+ # think_in 'en' # Supported: 'en', 'zh-TW', 'ja-JP', etc.
328
+
246
329
  # Configuration
247
330
  # max_iterations 10
248
331
  # timeout 30
@@ -389,7 +472,7 @@ end
389
472
 
390
473
  - Ruby: >= 3.4
391
474
  - Rails: >= 7.0
392
- - Soka: >= 1.0
475
+ - Soka: >= 0.0.4
393
476
 
394
477
  ## Contributing
395
478
 
data/SPEC.md CHANGED
@@ -291,7 +291,6 @@ class ConversationsController < ApplicationController
291
291
 
292
292
  render json: {
293
293
  answer: result.final_answer,
294
- confidence: result.confidence_score,
295
294
  status: result.status
296
295
  }
297
296
  end
@@ -10,6 +10,15 @@ class <%= @agent_class_name %> < ApplicationAgent
10
10
  # tool YourTool
11
11
  <% end -%>
12
12
 
13
+ # Custom instructions
14
+ # instructions "You are a helpful assistant specialized in..."
15
+
16
+ # Dynamic instructions via method
17
+ # instructions :generate_instructions # Reference a method for dynamic instructions
18
+
19
+ # Multilingual thinking
20
+ # think_in 'en' # 'en', 'zh-TW', 'ja-JP', etc.
21
+
13
22
  # Configuration
14
23
  # max_iterations 10
15
24
  # timeout 30
@@ -22,4 +31,13 @@ class <%= @agent_class_name %> < ApplicationAgent
22
31
  # private
23
32
 
24
33
  # Implement your private methods here
34
+
35
+ # Example of dynamic instructions method
36
+ # def generate_instructions
37
+ # <<~PROMPT
38
+ # You are a #{Rails.env} environment assistant.
39
+ # Current Time: #{Time.zone.now.strftime('%Y-%m-%d %H:%M:%S')}
40
+ # User: #{current_user&.name || 'Guest'}
41
+ # PROMPT
42
+ # end
25
43
  end
@@ -15,14 +15,14 @@ RSpec.describe <%= @tool_class_name %>Tool, type: :tool do
15
15
  }
16
16
  end
17
17
 
18
- it 'executes successfully with valid params' do
18
+ it 'calls successfully with valid params' do
19
19
  result = tool.call(**params)
20
20
 
21
21
  expect(result).to be_a(Hash)
22
22
  expect(result[:result]).to be_present
23
23
  end
24
24
  <% else -%>
25
- it 'executes successfully' do
25
+ it 'calls successfully' do
26
26
  result = tool.call
27
27
 
28
28
  expect(result).to be_a(Hash)
@@ -19,7 +19,6 @@ module Soka
19
19
  def build_mock_response(attrs)
20
20
  default_response = {
21
21
  final_answer: 'Mocked answer',
22
- confidence_score: 0.95,
23
22
  status: :completed,
24
23
  iterations: 1,
25
24
  thought_process: []
@@ -95,7 +94,6 @@ module Soka
95
94
  default_attrs = {
96
95
  status: :completed,
97
96
  final_answer: 'Success',
98
- confidence_score: 0.95,
99
97
  iterations: 1
100
98
  }
101
99
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Soka
4
4
  module Rails
5
- VERSION = '0.0.2'
5
+ VERSION = '0.0.4'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soka-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiunjiun
@@ -35,14 +35,14 @@ dependencies:
35
35
  requirements:
36
36
  - - "~>"
37
37
  - !ruby/object:Gem::Version
38
- version: 0.0.1
38
+ version: 0.0.4
39
39
  type: :runtime
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  requirements:
43
43
  - - "~>"
44
44
  - !ruby/object:Gem::Version
45
- version: 0.0.1
45
+ version: 0.0.4
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: zeitwerk
48
48
  requirement: !ruby/object:Gem::Requirement