soka 0.0.1 โ 0.0.3
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 +4 -4
- data/CHANGELOG.md +38 -0
- data/CLAUDE.md +347 -188
- data/README.md +137 -9
- data/examples/10_think_in_languages.rb +113 -0
- data/examples/2_event_handling.rb +5 -4
- data/examples/3_memory.rb +4 -2
- data/examples/4_hooks.rb +0 -1
- data/examples/9_custom_instructions.rb +190 -0
- data/lib/soka/agent.rb +22 -4
- data/lib/soka/agent_tool.rb +1 -1
- data/lib/soka/agents/dsl_methods.rb +14 -1
- data/lib/soka/engines/base.rb +6 -4
- data/lib/soka/engines/concerns/prompt_template.rb +44 -53
- data/lib/soka/engines/concerns/response_parser.rb +60 -0
- data/lib/soka/engines/concerns/response_processor.rb +5 -6
- data/lib/soka/engines/concerns/result_builder.rb +25 -0
- data/lib/soka/engines/react.rb +4 -26
- data/lib/soka/engines/reasoning_context.rb +4 -2
- data/lib/soka/result.rb +1 -5
- data/lib/soka/thoughts_memory.rb +0 -12
- data/lib/soka/version.rb +1 -1
- data/lib/soka.rb +0 -3
- metadata +7 -46
- data/lib/soka/test_helpers.rb +0 -162
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b99b5c66b841d01fa4ac0955e3924d5057787027827bdd9794094304ad218fae
|
4
|
+
data.tar.gz: 4343a63fd6057865f9fd03ac7de05e3a12ca1e2ef6e8b4fe2b35e4c088e7cb1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 633bf8b6bece348f71a53ca68229b710cbb0437372eaac0ca8d7b3e1a83baea6f9a31ed3d4cc68267f6cafcd6bbb5aefc28327212cacbc74d1d15437c0faf5ec
|
7
|
+
data.tar.gz: 3c5e8939f02d9ad9804e053b57ae22227c00662a4a57d35b4685e63a980534412c81441d75a46939d94e288b122084f7f612022c95e20ed506c1162114c25d1b
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,44 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.0.3] - 2025-08-03
|
11
|
+
|
12
|
+
### Features
|
13
|
+
- feat: add think_in feature for multilingual reasoning (2e587f3)
|
14
|
+
- feat: add custom instructions support for agents (95c2689)
|
15
|
+
- feat: add think_in languages example (505ef60)
|
16
|
+
|
17
|
+
### Code Refactoring
|
18
|
+
- refactor: optimize think_in feature and improve security (4bcd026)
|
19
|
+
- refactor: remove confidence score from result and related components (057cf93)
|
20
|
+
- refactor: extract response parsing and result building into separate concerns (0d62388)
|
21
|
+
|
22
|
+
### Tests
|
23
|
+
- test: fix RSpec violations and restructure tests (17c1af7)
|
24
|
+
- test: add RSpec test for think_in feature (759c113)
|
25
|
+
- test: remove test_helpers module and update test files (2e587f3)
|
26
|
+
|
27
|
+
### Documentation
|
28
|
+
- docs: add documentation for custom instructions and multilingual thinking features (151e8e3)
|
29
|
+
- docs: add Rails integration documentation (41815e6)
|
30
|
+
|
31
|
+
### Chores
|
32
|
+
- chore(release): add changelog extraction step for GitHub release (cbb65d8)
|
33
|
+
- chore: add .rspec_status to gitignore (0a0ebb3)
|
34
|
+
|
35
|
+
## [0.0.2] - 2025-08-01
|
36
|
+
|
37
|
+
### Features
|
38
|
+
- feat(agent_tool): add support for 'Object' type mapping
|
39
|
+
|
40
|
+
### Code Refactoring
|
41
|
+
- refactor: remove dry-rb dependencies
|
42
|
+
- refactor: change tool execution method from call to execute
|
43
|
+
|
44
|
+
### Chores
|
45
|
+
- chore: update gemspec description to include 'Gemini AI Studio'
|
46
|
+
- chore(README): update footer to include creator information
|
47
|
+
|
10
48
|
## [0.0.1] - 2025-07-29
|
11
49
|
|
12
50
|
### Code Refactoring
|
data/CLAUDE.md
CHANGED
@@ -1,201 +1,349 @@
|
|
1
1
|
# Soka - Ruby ReAct Agent Framework
|
2
2
|
|
3
|
-
##
|
3
|
+
## ๐ฏ What is Soka?
|
4
4
|
|
5
|
-
Soka is a Ruby
|
5
|
+
Soka is a Ruby framework for building AI agents using the ReAct (Reasoning and Acting) pattern. It enables your Ruby applications to leverage AI capabilities through a clean, object-oriented interface.
|
6
6
|
|
7
|
-
|
7
|
+
### Key Features
|
8
|
+
- **Multi-Provider Support**: Works with Gemini, OpenAI, and Anthropic out of the box
|
9
|
+
- **ReAct Pattern**: Implements structured reasoning with Thought โ Action โ Observation โ Final Answer flow
|
10
|
+
- **Tool System**: Define custom tools that agents can use to interact with your application
|
11
|
+
- **Memory Management**: Built-in conversation and thought process tracking
|
12
|
+
- **Minimal Dependencies**: Only requires `faraday` and `zeitwerk` - no heavy frameworks
|
13
|
+
|
14
|
+
## ๐ Quick Start
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
class MyAgent < Soka::Agent
|
18
|
+
provider :gemini
|
19
|
+
model 'gemini-2.5-flash-lite'
|
20
|
+
|
21
|
+
tool :calculator, 'Performs math calculations' do
|
22
|
+
def call(expression:)
|
23
|
+
# Your tool logic here
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
agent = MyAgent.new
|
29
|
+
result = agent.run("Calculate 123 * 456")
|
30
|
+
puts result.final_answer
|
31
|
+
```
|
32
|
+
|
33
|
+
## ๐ Project Structure
|
8
34
|
|
9
|
-
### Directory Structure
|
10
35
|
```
|
11
36
|
soka/
|
12
|
-
โโโ lib/
|
13
|
-
โ โโโ
|
14
|
-
โ
|
15
|
-
โ
|
16
|
-
โ
|
17
|
-
โ
|
18
|
-
โ
|
19
|
-
โ
|
20
|
-
โ
|
21
|
-
โ
|
22
|
-
โ
|
23
|
-
โ
|
24
|
-
โ
|
25
|
-
โ
|
26
|
-
โ
|
27
|
-
โ
|
28
|
-
โ
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
37
|
+
โโโ lib/soka/
|
38
|
+
โ โโโ agent.rb # Core Agent class with DSL
|
39
|
+
โ โโโ agent_tool.rb # Base class for tools
|
40
|
+
โ โโโ agents/ # Agent components (modular design)
|
41
|
+
โ โ โโโ dsl_methods.rb # DSL for agent configuration
|
42
|
+
โ โ โโโ hook_manager.rb # Lifecycle hooks
|
43
|
+
โ โ โโโ llm_builder.rb # LLM instance creation
|
44
|
+
โ โ โโโ retry_handler.rb # Retry logic
|
45
|
+
โ โ โโโ tool_builder.rb # Tool management
|
46
|
+
โ โโโ engines/ # Reasoning engines
|
47
|
+
โ โ โโโ react.rb # ReAct implementation
|
48
|
+
โ โ โโโ concerns/ # Shared engine modules
|
49
|
+
โ โโโ llms/ # AI provider integrations
|
50
|
+
โ โ โโโ gemini.rb # Google Gemini
|
51
|
+
โ โ โโโ openai.rb # OpenAI GPT
|
52
|
+
โ โ โโโ anthropic.rb # Anthropic Claude
|
53
|
+
โ โโโ memory.rb # Conversation memory
|
54
|
+
โโโ examples/ # Working examples (1-10)
|
55
|
+
โโโ spec/ # RSpec tests
|
56
|
+
```
|
57
|
+
|
58
|
+
## ๐ง Core Components
|
59
|
+
|
60
|
+
### Agent System
|
61
|
+
The heart of Soka - defines agents with a simple DSL:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
class MyAgent < Soka::Agent
|
65
|
+
provider :gemini # Choose AI provider
|
66
|
+
model 'gemini-2.5-flash-lite' # Specify model
|
67
|
+
max_iterations 10 # Limit reasoning cycles
|
68
|
+
timeout 30 # Request timeout
|
69
|
+
|
70
|
+
# Define tools
|
71
|
+
tool :my_tool, 'Description' do
|
72
|
+
def call(param:)
|
73
|
+
# Tool implementation
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Lifecycle hooks
|
78
|
+
before_action { |task| log("Starting: #{task}") }
|
79
|
+
after_action { |result| log("Completed: #{result}") }
|
80
|
+
on_error { |error| handle_error(error) }
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
### Tool System
|
85
|
+
Create reusable tools with parameter validation:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
class WeatherTool < Soka::AgentTool
|
89
|
+
desc 'Get weather information'
|
90
|
+
|
91
|
+
params do
|
92
|
+
requires :location, String, desc: 'City name'
|
93
|
+
optional :units, String, inclusion: %w[celsius fahrenheit]
|
94
|
+
end
|
95
|
+
|
96
|
+
def call(location:, units: 'celsius')
|
97
|
+
# Fetch weather data
|
98
|
+
"Weather in #{location}: 22ยฐC, Sunny"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
### ReAct Engine
|
104
|
+
Implements the reasoning pattern with structured tags:
|
105
|
+
|
106
|
+
1. **Thought**: Agent thinks about the task
|
107
|
+
2. **Action**: Decides which tool to use
|
108
|
+
3. **Observation**: Receives tool results
|
109
|
+
4. **Final Answer**: Provides the solution
|
110
|
+
|
111
|
+
The engine automatically:
|
112
|
+
- Manages iteration loops
|
113
|
+
- Calculates confidence scores
|
114
|
+
- Handles tool execution
|
115
|
+
- Tracks reasoning context
|
116
|
+
|
117
|
+
### Memory System
|
118
|
+
Two types of memory for different purposes:
|
119
|
+
|
120
|
+
- **Conversation Memory**: Tracks dialogue history
|
121
|
+
- **Thoughts Memory**: Records complete reasoning processes
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
# Initialize with existing conversation
|
125
|
+
memory = Soka::Memory.new
|
126
|
+
memory.add(role: 'user', content: 'Previous question')
|
127
|
+
memory.add(role: 'assistant', content: 'Previous answer')
|
128
|
+
|
129
|
+
agent = MyAgent.new(memory: memory)
|
130
|
+
```
|
131
|
+
|
132
|
+
## ๐จ Advanced Features
|
133
|
+
|
134
|
+
### Custom Instructions
|
135
|
+
Change your agent's personality and response style:
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
class FriendlyAgent < Soka::Agent
|
139
|
+
provider :gemini
|
140
|
+
|
141
|
+
# Define personality at class level
|
142
|
+
instructions <<~PROMPT
|
143
|
+
You are a friendly, helpful assistant.
|
144
|
+
Use casual language and be encouraging.
|
145
|
+
Add emojis when appropriate.
|
146
|
+
PROMPT
|
147
|
+
end
|
148
|
+
|
149
|
+
# Or override at runtime
|
150
|
+
agent = FriendlyAgent.new(
|
151
|
+
instructions: 'Be more formal and professional.'
|
152
|
+
)
|
153
|
+
```
|
154
|
+
|
155
|
+
### Multilingual Thinking (Think In)
|
156
|
+
Optimize reasoning for specific languages:
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
class GlobalAgent < Soka::Agent
|
160
|
+
provider :gemini
|
161
|
+
|
162
|
+
# Set default thinking language
|
163
|
+
think_in 'zh-TW' # Think in Traditional Chinese
|
164
|
+
end
|
165
|
+
|
166
|
+
# Or set dynamically
|
167
|
+
agent = GlobalAgent.new(think_in: 'ja-JP')
|
168
|
+
result = agent.run("Help me with this task")
|
169
|
+
```
|
170
|
+
|
171
|
+
**Key Points:**
|
172
|
+
- Thinking language affects internal reasoning only
|
173
|
+
- Responses adapt to user's input language
|
174
|
+
- Default is English (`'en'`)
|
175
|
+
- No automatic language detection (explicit setting required)
|
176
|
+
|
177
|
+
### Conditional Tools
|
178
|
+
Load tools based on conditions:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
class SmartAgent < Soka::Agent
|
182
|
+
# Only in development
|
183
|
+
tool DebugTool, if: -> { ENV['RAILS_ENV'] == 'development' }
|
184
|
+
|
185
|
+
# Based on user permissions
|
186
|
+
tool AdminTool, if: -> { current_user.admin? }
|
187
|
+
|
188
|
+
# Feature flags
|
189
|
+
tool BetaFeature, if: -> { feature_enabled?(:beta) }
|
190
|
+
end
|
58
191
|
```
|
59
192
|
|
60
|
-
##
|
61
|
-
|
62
|
-
###
|
63
|
-
|
64
|
-
|
65
|
-
- Built-in lifecycle hooks (before_action, after_action, on_error)
|
66
|
-
- Uses `times` loop instead of `loop` for iteration control
|
67
|
-
- Modular design: functionality separated into concern modules
|
68
|
-
- `DSLMethods`: DSL method definitions
|
69
|
-
- `HookManager`: Lifecycle hook management
|
70
|
-
- `LLMBuilder`: LLM instance construction
|
71
|
-
- `RetryHandler`: Retry handling
|
72
|
-
- `ToolBuilder`: Tool construction and management
|
73
|
-
|
74
|
-
### 2. Tool System (`agent_tool.rb`)
|
75
|
-
- Grape API-like parameter definition system
|
76
|
-
- Built-in parameter validation (presence, length, inclusion, format)
|
77
|
-
- Supports required and optional parameters
|
78
|
-
- Auto-generates tool description schemas
|
79
|
-
|
80
|
-
### 3. ReAct Engine (`engines/react.rb`)
|
81
|
-
- Implements tagged ReAct flow: `<Thought>`, `<Action>`, `<Observation>`, `<Final_Answer>`
|
82
|
-
- Uses Struct instead of OpenStruct (Rubocop compliant)
|
83
|
-
- Automatically manages conversation context and tool execution
|
84
|
-
- Calculates confidence scores (based on iteration count)
|
85
|
-
- Uses `ReasoningContext` to manage reasoning state
|
86
|
-
- Shared modules:
|
87
|
-
- `PromptTemplate`: Prompt template management
|
88
|
-
- `ResponseProcessor`: Response processing logic
|
89
|
-
|
90
|
-
### 4. LLM Integration
|
91
|
-
- **LLM Unified Interface Layer (`llm.rb`)**
|
92
|
-
- Provides unified API interface
|
93
|
-
- Supports streaming and non-streaming modes
|
94
|
-
- Auto-routes to corresponding provider implementation
|
95
|
-
- **LLM Provider Implementations (`llms/`)**
|
96
|
-
- Gemini: Uses Google Generative AI API, defaults to `gemini-2.5-flash-lite`
|
97
|
-
- OpenAI: Supports GPT-4 series, includes streaming capabilities
|
98
|
-
- Anthropic: Supports Claude 3 series, handles system prompts
|
99
|
-
- Shared modules:
|
100
|
-
- `ResponseParser`: Unified response parsing
|
101
|
-
- `StreamingHandler`: Stream response handling
|
102
|
-
- Built-in error handling and retry mechanisms
|
103
|
-
|
104
|
-
### 5. Memory System
|
105
|
-
- `Memory`: Manages conversation history
|
106
|
-
- `ThoughtsMemory`: Records complete ReAct thought processes
|
107
|
-
- Supports initial memory loading
|
108
|
-
|
109
|
-
## Design Decisions
|
110
|
-
|
111
|
-
### 1. Using Zeitwerk Autoloading
|
112
|
-
- Simplifies require management
|
113
|
-
- Supports hot reloading (development environment)
|
114
|
-
- Automatically handles namespaces
|
115
|
-
|
116
|
-
### 2. Dry-rb Ecosystem Integration
|
117
|
-
- `dry-validation`: Powerful parameter validation
|
118
|
-
- `dry-struct`: Type-safe data structures
|
119
|
-
- `dry-types`: Type definitions and coercion
|
120
|
-
|
121
|
-
### 3. Configuration System Design
|
122
|
-
- Supports global configuration and instance-level overrides
|
123
|
-
- Block-style DSL provides intuitive configuration
|
124
|
-
- Fallback mechanism ensures service availability
|
125
|
-
- Configuration includes AI providers and performance settings
|
126
|
-
|
127
|
-
### 4. Error Handling Strategy
|
128
|
-
- Layered error class inheritance
|
129
|
-
- Tool execution errors don't interrupt entire flow
|
130
|
-
- Configurable retry mechanism (exponential backoff)
|
131
|
-
|
132
|
-
## Testing Strategy
|
133
|
-
|
134
|
-
### Unit Tests
|
135
|
-
- Using RSpec 3
|
136
|
-
- Provides `TestHelpers` module for mocking AI responses
|
137
|
-
- Supports tool mocking and error simulation
|
138
|
-
|
139
|
-
### Integration Tests
|
140
|
-
- `test_soka.rb`: Quick test without real API keys
|
141
|
-
- `examples/1_basic.rb`: Actual API integration test
|
142
|
-
|
143
|
-
## Development Guide
|
144
|
-
|
145
|
-
### Adding New AI Provider
|
146
|
-
1. Create new file in `lib/soka/llms/`
|
193
|
+
## ๐ Development Guide
|
194
|
+
|
195
|
+
### Creating a New AI Provider
|
196
|
+
|
197
|
+
1. Create file in `lib/soka/llms/your_provider.rb`
|
147
198
|
2. Inherit from `Soka::LLMs::Base`
|
148
199
|
3. Implement required methods:
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
module Soka
|
203
|
+
module LLMs
|
204
|
+
class YourProvider < Base
|
205
|
+
def default_model
|
206
|
+
'your-default-model'
|
207
|
+
end
|
208
|
+
|
209
|
+
def base_url
|
210
|
+
'https://api.yourprovider.com'
|
211
|
+
end
|
212
|
+
|
213
|
+
def chat(messages, **params)
|
214
|
+
# Make API request
|
215
|
+
# Return response
|
216
|
+
end
|
217
|
+
|
218
|
+
def parse_response(response)
|
219
|
+
# Parse API response
|
220
|
+
# Return standardized format
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
```
|
226
|
+
|
227
|
+
### Creating Custom Engines
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
class MyEngine < Soka::Engines::Base
|
231
|
+
def reason(task, &block)
|
232
|
+
# Implement your reasoning logic
|
233
|
+
emit_event(:thought, "Thinking about: #{task}")
|
234
|
+
|
235
|
+
# Process and return result
|
236
|
+
MyResult.new(
|
237
|
+
input: task,
|
238
|
+
output: "Processed result",
|
239
|
+
status: :success
|
240
|
+
)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
```
|
244
|
+
|
245
|
+
## โ๏ธ Configuration
|
246
|
+
|
247
|
+
### Global Configuration
|
248
|
+
|
249
|
+
```ruby
|
250
|
+
Soka.setup do |config|
|
251
|
+
config.ai do |ai|
|
252
|
+
ai.provider = :gemini
|
253
|
+
ai.model = 'gemini-2.5-flash-lite'
|
254
|
+
ai.api_key = ENV['GEMINI_API_KEY']
|
255
|
+
end
|
256
|
+
|
257
|
+
config.performance do |perf|
|
258
|
+
perf.max_iterations = 10
|
259
|
+
perf.timeout = 30
|
260
|
+
end
|
261
|
+
end
|
262
|
+
```
|
263
|
+
|
264
|
+
### Environment Variables
|
265
|
+
|
266
|
+
```bash
|
267
|
+
# .env file
|
268
|
+
GEMINI_API_KEY=your_api_key
|
269
|
+
OPENAI_API_KEY=your_api_key
|
270
|
+
ANTHROPIC_API_KEY=your_api_key
|
271
|
+
```
|
272
|
+
|
273
|
+
## ๐ Performance & Security
|
274
|
+
|
275
|
+
### Performance Tips
|
276
|
+
- Set appropriate `max_iterations` to prevent infinite loops
|
277
|
+
- Use `timeout` to handle slow API responses
|
278
|
+
- Implement caching for frequently used tools
|
279
|
+
- Consider memory limits for long conversations
|
280
|
+
|
281
|
+
### Security Best Practices
|
282
|
+
- Never commit API keys to version control
|
283
|
+
- Use environment variables for sensitive data
|
284
|
+
- Validate all tool inputs
|
285
|
+
- Sanitize tool outputs before returning
|
286
|
+
- Implement rate limiting for production use
|
287
|
+
|
288
|
+
## ๐งช Testing
|
289
|
+
|
290
|
+
### Unit Testing
|
291
|
+
|
292
|
+
```ruby
|
293
|
+
RSpec.describe MyAgent do
|
294
|
+
let(:agent) { described_class.new }
|
295
|
+
|
296
|
+
it 'processes tasks correctly' do
|
297
|
+
result = agent.run('Test task')
|
298
|
+
expect(result).to be_successful
|
299
|
+
expect(result.final_answer).to include('expected')
|
300
|
+
end
|
301
|
+
end
|
302
|
+
```
|
303
|
+
|
304
|
+
### Mocking AI Responses
|
305
|
+
|
306
|
+
```ruby
|
307
|
+
allow(agent).to receive(:llm).and_return(mock_llm)
|
308
|
+
allow(mock_llm).to receive(:chat).and_return(
|
309
|
+
double(content: '<Thought>Test</Thought><Final_Answer>Done</Final_Answer>')
|
310
|
+
)
|
311
|
+
```
|
312
|
+
|
313
|
+
## ๐ Examples
|
314
|
+
|
315
|
+
The `examples/` directory contains 10 comprehensive examples:
|
316
|
+
|
317
|
+
1. **Basic Usage** - Simple agent setup and execution
|
318
|
+
2. **Event Handling** - Responding to agent events
|
319
|
+
3. **Memory Management** - Using conversation memory
|
320
|
+
4. **Lifecycle Hooks** - before/after/error handling
|
321
|
+
5. **Error Handling** - Graceful error management
|
322
|
+
6. **Retry Logic** - Automatic retry configuration
|
323
|
+
7. **Conditional Tools** - Dynamic tool loading
|
324
|
+
8. **Multi-Provider** - Switching between AI providers
|
325
|
+
9. **Custom Instructions** - Personality customization
|
326
|
+
10. **Multilingual Thinking** - Language-specific reasoning
|
327
|
+
|
328
|
+
## ๐ Future Roadmap
|
329
|
+
|
330
|
+
- [ ] Additional LLM providers (Cohere, Hugging Face)
|
331
|
+
- [ ] Built-in caching mechanism
|
332
|
+
- [ ] Vector database integration for RAG
|
333
|
+
- [ ] More built-in tools (web search, file operations)
|
334
|
+
- [ ] WebSocket support for real-time streaming
|
335
|
+
- [ ] Direct method-as-tool support
|
336
|
+
|
337
|
+
## ๐ Development Standards
|
338
|
+
|
339
|
+
### Code Quality
|
340
|
+
- Run `bundle exec rubocop` before committing
|
341
|
+
- Ensure all tests pass with `bundle exec rspec`
|
342
|
+
- Follow Ruby style guide and conventions
|
343
|
+
- Keep methods small and focused
|
344
|
+
- Write clear, self-documenting code
|
345
|
+
|
346
|
+
### Code Quality Checks (Important for AI Assistants)
|
199
347
|
- **When adjusting code, the final step is to run Rubocop to check if the code complies with rules**
|
200
348
|
- **When Rubocop has any issues, fix them until all rules are satisfied**
|
201
349
|
- **When adjusting code, the final step is to perform a code review to avoid redundant design and ensure code conciseness**
|
@@ -210,4 +358,15 @@ soka/
|
|
210
358
|
- Include method purpose descriptions
|
211
359
|
- Explain parameter types and purposes
|
212
360
|
- Explain return value types and meanings
|
213
|
-
- For complex logic, add implementation detail explanations
|
361
|
+
- For complex logic, add implementation detail explanations
|
362
|
+
- Include usage examples in comments
|
363
|
+
- Document all public APIs
|
364
|
+
- Keep README and CLAUDE.md updated
|
365
|
+
|
366
|
+
## ๐ค Contributing
|
367
|
+
|
368
|
+
[Contributing Guidelines]
|
369
|
+
|
370
|
+
---
|
371
|
+
|
372
|
+
*Built with โค๏ธ using Ruby and AI*
|