ask-rails 0.15.3 → 0.15.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 +4 -4
- data/README.md +32 -148
- data/lib/ask/rails/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dcbbe5b90ea4ca26543e8ff114cf09eece8d4bb86870a901e0c01410bb5cd8be
|
|
4
|
+
data.tar.gz: 1c0f1b2a39714a48432c2486d853803fa300eb1f170703508f09dd5db3f61b7b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 29a0091cf06a3960bdaf7251f1a2cd3ce38a4cd9f4004d322445e33da7b93373a5db8eb4c859b0e3d1dcaf49cb8933f8ea592be71fed0387cafeda825eb87979
|
|
7
|
+
data.tar.gz: b12f575ef3851ecd03dc223ca406edf2081dfc177df72af5cff712ceaeedf189b050bc7e67260afb1dfd5065ea9138a3f8338bb4e61e23915c607c2648ac1758
|
data/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# ask-rails
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://badge.fury.io/rb/ask-rails)
|
|
4
|
+
|
|
5
|
+
Rails integration for the [ask-rb](https://github.com/ask-rb) ecosystem. Provides generators, file conventions, and a railtie for building user-facing AI features (agents, workflows, actions) inside a Rails app. Requires Rails 7.1+.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
@@ -8,7 +10,7 @@ Add to your Gemfile:
|
|
|
8
10
|
|
|
9
11
|
```ruby
|
|
10
12
|
gem "ask-rails"
|
|
11
|
-
gem "ask-graph" # optional
|
|
13
|
+
gem "ask-graph" # optional, add only if you use workflows
|
|
12
14
|
```
|
|
13
15
|
|
|
14
16
|
Run the installer:
|
|
@@ -22,193 +24,75 @@ This creates:
|
|
|
22
24
|
|
|
23
25
|
| File | Purpose |
|
|
24
26
|
|---|---|
|
|
25
|
-
| `config/initializers/ask.rb` | Agent
|
|
27
|
+
| `config/initializers/ask.rb` | Agent, workflow, and action configuration |
|
|
26
28
|
| `app/agents/application_agent.rb` | Base class for your agents |
|
|
27
29
|
| `app/actions/application_action.rb` | Base class for your actions |
|
|
28
30
|
| `app/workflows/application_workflow.rb` | Base class for your workflows (only with ask-graph) |
|
|
29
|
-
| `db/migrate/*_create_ask_state.rb` | Shared key-value state table
|
|
31
|
+
| `db/migrate/*_create_ask_state.rb` | Shared key-value state table |
|
|
30
32
|
| `db/migrate/*_create_ask_audit_logs.rb` | Agent session audit log |
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
No controllers, views, or routes are generated. The admin chat UI ships in [ask-rails-harness](https://github.com/ask-rb/ask-rails-harness).
|
|
33
35
|
|
|
34
36
|
## Generators
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
rails generate ask:agent support_bot
|
|
42
|
-
```
|
|
38
|
+
- `rails generate ask:agent NAME`: creates `app/agents/<name>/` with `agent.rb`, `instructions.md`, and `tools/`.
|
|
39
|
+
- `rails generate ask:action NAME [NAMESPACE]`: creates an action under `app/actions/` (e.g. `ask:action chats create` → `app/actions/chats/create.rb`).
|
|
40
|
+
- `rails generate ask:workflow NAME`: creates `app/workflows/<name>/workflow.rb` and `steps/` (requires ask-graph).
|
|
41
|
+
- `rails generate ask:install --skip-graph`: skips workflow scaffolding when you don't use ask-graph.
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
app/agents/support_bot/
|
|
48
|
-
├── agent.rb # module SupportBot; class Agent < ApplicationAgent
|
|
49
|
-
├── instructions.md # auto-loaded as the system prompt
|
|
50
|
-
└── tools/ # per-agent tools (referenced with `tools :tool_name`)
|
|
51
|
-
```
|
|
43
|
+
## Quick Start
|
|
52
44
|
|
|
53
45
|
```ruby
|
|
54
46
|
# app/agents/support_bot/agent.rb
|
|
55
47
|
module SupportBot
|
|
56
48
|
class Agent < ApplicationAgent
|
|
57
49
|
model "gpt-4o"
|
|
58
|
-
# tools :search_knowledge_base
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Run it with `Ask::Agent.new("support_bot")`. The directory name is the
|
|
64
|
-
agent name — keep the file named `agent.rb`.
|
|
65
|
-
|
|
66
|
-
### `ask:workflow NAME`
|
|
67
|
-
|
|
68
|
-
Scaffolds a new workflow (requires ask-graph):
|
|
69
|
-
|
|
70
|
-
```bash
|
|
71
|
-
rails generate ask:workflow notify_customer
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Creates `app/workflows/notify_customer/workflow.rb` and `app/workflows/notify_customer/steps/`:
|
|
75
|
-
|
|
76
|
-
```ruby
|
|
77
|
-
module NotifyCustomer
|
|
78
|
-
class Workflow < ApplicationWorkflow
|
|
79
|
-
# step SomeStep
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### `ask:action NAME [NAMESPACE]`
|
|
85
|
-
|
|
86
|
-
Scaffolds a new action — a user-facing operation callable from any channel (web, Slack, voice) by name:
|
|
87
|
-
|
|
88
|
-
```bash
|
|
89
|
-
rails generate ask:action create_workspace # app/actions/create_workspace.rb
|
|
90
|
-
rails generate ask:action chats create # app/actions/chats/create.rb
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
Creates `app/actions/chats/create.rb`:
|
|
94
|
-
|
|
95
|
-
```ruby
|
|
96
|
-
module Chats
|
|
97
|
-
class Create < ApplicationAction
|
|
98
|
-
def call
|
|
99
|
-
Ask::Actions::Result.ok(message: "Chat created", data: { id: record.id })
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Skipping workflow scaffolding
|
|
106
|
-
|
|
107
|
-
If you don't use ask-graph, install with:
|
|
108
|
-
|
|
109
|
-
```bash
|
|
110
|
-
rails generate ask:install --skip-graph
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
The initializer still works — the graph block is omitted when ask-graph isn't installed.
|
|
114
|
-
|
|
115
|
-
## Usage
|
|
116
|
-
|
|
117
|
-
### Agents
|
|
118
|
-
|
|
119
|
-
```ruby
|
|
120
|
-
# app/agents/support_bot.rb
|
|
121
|
-
module Agents
|
|
122
|
-
class SupportBot < ApplicationAgent
|
|
123
|
-
model "gpt-4o"
|
|
124
|
-
system_prompt "You help users with support questions."
|
|
125
|
-
|
|
126
|
-
tool :bash
|
|
127
|
-
tool :read
|
|
128
50
|
end
|
|
129
51
|
end
|
|
130
52
|
```
|
|
131
53
|
|
|
132
54
|
```ruby
|
|
133
55
|
agent = Ask::Agent.new("support_bot")
|
|
134
|
-
response = agent.run("
|
|
56
|
+
response = agent.run("How do I reset my password?")
|
|
135
57
|
puts response
|
|
136
58
|
```
|
|
137
59
|
|
|
138
|
-
|
|
60
|
+
The directory name is the agent name. `instructions.md` next to `agent.rb` is auto-loaded as the system prompt.
|
|
139
61
|
|
|
140
|
-
|
|
141
|
-
# app/workflows/order_fulfillment/workflow.rb
|
|
142
|
-
module OrderFulfillment
|
|
143
|
-
class Workflow < ApplicationWorkflow
|
|
144
|
-
step ValidatePayment
|
|
145
|
-
step NotifyCustomer
|
|
146
|
-
step ShipOrder
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
```
|
|
62
|
+
## Essential API
|
|
150
63
|
|
|
151
|
-
|
|
152
|
-
# app/workflows/order_fulfillment/steps/validate_payment.rb
|
|
153
|
-
module OrderFulfillment
|
|
154
|
-
class ValidatePayment
|
|
155
|
-
def call(context)
|
|
156
|
-
context.payment = PaymentService.charge(context.input[:order])
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
```
|
|
64
|
+
### Ask::Actions: dispatch operations by name from any channel
|
|
161
65
|
|
|
162
66
|
```ruby
|
|
163
|
-
result = OrderFulfillment::Workflow.call(order: order)
|
|
164
|
-
result.payment
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
Checkpoints are saved to the shared `ask_state` table, so workflows resume after crashes.
|
|
168
|
-
|
|
169
|
-
### Actions
|
|
170
|
-
|
|
171
|
-
Actions are the operations your users trigger — booking an appointment, creating a chat, upgrading a plan. They live in `app/actions/` and are dispatched **by name**, so any channel (web controller, Slack handler, voice agent) calls the same operation:
|
|
172
|
-
|
|
173
|
-
```ruby
|
|
174
|
-
# app/actions/chats/create.rb
|
|
175
|
-
module Chats
|
|
176
|
-
class Create < ApplicationAction
|
|
177
|
-
def call
|
|
178
|
-
chat = context.channel.start_new_chat!
|
|
179
|
-
Ask::Actions::Result.ok(message: "Chat created", data: { chat: chat })
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
```ruby
|
|
186
|
-
# From any channel:
|
|
187
67
|
context = Ask::Actions::Context.new(user: current_user, session: session)
|
|
188
68
|
result = Ask::Actions.dispatch(action: "chats.create", context: context, params: { name: "general" })
|
|
189
|
-
result.ok?
|
|
190
|
-
result.message
|
|
191
|
-
result.data # => { chat: ... }
|
|
69
|
+
result.ok? # => true
|
|
70
|
+
result.message # => "Chat created"
|
|
192
71
|
```
|
|
193
72
|
|
|
194
|
-
|
|
73
|
+
`"chats.create"` resolves to `Chats::Create` (Zeitwerk autoloads `app/actions/`). Register explicitly to override the convention or list actions:
|
|
195
74
|
|
|
196
75
|
```ruby
|
|
197
|
-
# config/initializers/ask.rb
|
|
198
76
|
Ask::Actions.register "chats.create", Chats::Create
|
|
77
|
+
Ask::Actions.available # => ["chats.create"]
|
|
199
78
|
```
|
|
200
79
|
|
|
201
|
-
Unknown action names raise `Ask::Actions::Backend::UnknownAction
|
|
80
|
+
Actions return an `Ask::Actions::Result` (`Result.ok` / `Result.error`). Unknown action names raise `Ask::Actions::Backend::UnknownAction`.
|
|
81
|
+
|
|
82
|
+
### Ask::Rails::State: ActiveRecord-backed state
|
|
202
83
|
|
|
203
|
-
|
|
84
|
+
`Ask::Rails::State` backs the `ask_state` table and works with any database (PostgreSQL, MySQL, SQLite). ask-graph stores workflow checkpoints there; ask-agent session persistence uses the same table, keyed by convention.
|
|
204
85
|
|
|
205
|
-
|
|
86
|
+
## Full documentation
|
|
206
87
|
|
|
207
|
-
-
|
|
208
|
-
- **Rails credentials:** `rails credentials:edit` → add `ask.openai`, `ask.anthropic`
|
|
209
|
-
- **File:** `~/.ask/credentials.yml`
|
|
88
|
+
The full ask-rb documentation lives at https://ask-rb.github.io/ask-docs. [Rails app integration](https://ask-rb.github.io/ask-docs/getting-started/rails-app) covers ask-rails in depth. API reference: https://ask-rb.github.io/ask-docs/reference/api.
|
|
210
89
|
|
|
211
|
-
|
|
90
|
+
## Development
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
bundle install
|
|
94
|
+
bundle exec rake test
|
|
95
|
+
```
|
|
212
96
|
|
|
213
97
|
## License
|
|
214
98
|
|
data/lib/ask/rails/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ask-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.15.
|
|
4
|
+
version: 0.15.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kaka Ruto
|
|
@@ -29,14 +29,14 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version:
|
|
32
|
+
version: 0.40.1
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version:
|
|
39
|
+
version: 0.40.1
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: minitest
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
148
148
|
- !ruby/object:Gem::Version
|
|
149
149
|
version: '0'
|
|
150
150
|
requirements: []
|
|
151
|
-
rubygems_version: 4.0.
|
|
151
|
+
rubygems_version: 4.0.18
|
|
152
152
|
specification_version: 4
|
|
153
153
|
summary: Rails integration for the ask-rb ecosystem
|
|
154
154
|
test_files: []
|