llama_bot_rails 0.1.8 → 0.1.10
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/app/channels/llama_bot_rails/chat_channel.rb +23 -4
- data/app/controllers/llama_bot_rails/agent_controller.rb +2 -2
- data/lib/generators/llama_bot_rails/install/install_generator.rb +25 -5
- data/lib/generators/llama_bot_rails/install/templates/agent_state_builder.rb.erb +22 -0
- data/lib/llama_bot_rails/agent_state_builder.rb +2 -2
- data/lib/llama_bot_rails/engine.rb +1 -1
- data/lib/llama_bot_rails/version.rb +1 -1
- data/lib/llama_bot_rails.rb +4 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a76c323b0d08220d2952ce3c1c3962dd203e645556123306fd9beb58c6ae17e6
|
4
|
+
data.tar.gz: 9e7c143edb324d49097ddabad7006635027ea6150cb07407702110546f0503c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 232cd0a6410caffa47b25d0fd0e62a69ba9fdfdc779f7adc9ded2cab80879544dffc1de5a4a65e1dabfeadad6b4c0a5ff410d26d71e0ed44101ec9ab00ef0af2
|
7
|
+
data.tar.gz: 730c59884b06bbb671955a2d128c31c6e6b85c24fe6b70120bb7d67af5249d88696eb7069d99689598ed35dc2aaa422626111fe8d3f6b154d2c68dde3d72cda6
|
@@ -133,10 +133,9 @@ module LlamaBotRails
|
|
133
133
|
# Forward the processed data to the LlamaBot Backend Socket
|
134
134
|
message = data["message"]
|
135
135
|
|
136
|
-
# 1. Instantiate the builder
|
137
136
|
builder = state_builder_class.new(
|
138
|
-
params:
|
139
|
-
context: {
|
137
|
+
params: data,
|
138
|
+
context: { api_token: @api_token }
|
140
139
|
)
|
141
140
|
|
142
141
|
# 2. Construct the LangGraph-ready state
|
@@ -171,7 +170,27 @@ module LlamaBotRails
|
|
171
170
|
private
|
172
171
|
|
173
172
|
def state_builder_class
|
174
|
-
LlamaBotRails.config.state_builder_class
|
173
|
+
builder_class_name = LlamaBotRails.config.state_builder_class || 'LlamaBotRails::AgentStateBuilder'
|
174
|
+
|
175
|
+
begin
|
176
|
+
builder_class_name.constantize
|
177
|
+
rescue NameError => e
|
178
|
+
# If it's not the default class, try to manually load from app/llama_bot
|
179
|
+
if builder_class_name != 'LlamaBotRails::AgentStateBuilder'
|
180
|
+
llama_bot_file = Rails.root.join("app", "llama_bot", "agent_state_builder.rb")
|
181
|
+
if llama_bot_file.exist?
|
182
|
+
Rails.logger.info "[LlamaBot] Autoload failed, attempting to manually load #{llama_bot_file}"
|
183
|
+
begin
|
184
|
+
load llama_bot_file.to_s
|
185
|
+
return builder_class_name.constantize
|
186
|
+
rescue => load_error
|
187
|
+
Rails.logger.error "[LlamaBot] Manual load failed: #{load_error.message}"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
raise NameError, "Could not load state builder class '#{builder_class_name}'. Make sure it's defined in app/llama_bot/agent_state_builder.rb or is available in your autoload paths. Original error: #{e.message}"
|
193
|
+
end
|
175
194
|
end
|
176
195
|
|
177
196
|
def setup_external_websocket(connection_id)
|
@@ -85,8 +85,8 @@ module LlamaBotRails
|
|
85
85
|
|
86
86
|
# 1. Instantiate the builder
|
87
87
|
builder = state_builder_class.new(
|
88
|
-
params:
|
89
|
-
context: {
|
88
|
+
params: params,
|
89
|
+
context: { api_token: @api_token }
|
90
90
|
)
|
91
91
|
|
92
92
|
# 2. Construct the LangGraph-ready state
|
@@ -14,9 +14,15 @@ module LlamaBotRails
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
empty_directory "
|
19
|
-
copy_file "agent_prompt.txt", "
|
17
|
+
def create_agent_prompt
|
18
|
+
empty_directory "app/llama_bot/prompts"
|
19
|
+
copy_file "agent_prompt.txt", "app/llama_bot/prompts/agent_prompt.txt"
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_agent_state_builder
|
23
|
+
empty_directory "app/llama_bot"
|
24
|
+
template "agent_state_builder.rb.erb", "app/llama_bot/agent_state_builder.rb"
|
25
|
+
say_status("created", "app/llama_bot/agent_state_builder.rb", :green)
|
20
26
|
end
|
21
27
|
|
22
28
|
def mount_engine
|
@@ -46,9 +52,17 @@ module LlamaBotRails
|
|
46
52
|
def create_initializer
|
47
53
|
create_file "config/initializers/llama_bot_rails.rb", <<~RUBY
|
48
54
|
Rails.application.configure do
|
49
|
-
config.llama_bot_rails.websocket_url
|
50
|
-
config.llama_bot_rails.llamabot_api_url
|
55
|
+
config.llama_bot_rails.websocket_url = ENV.fetch("LLAMABOT_WEBSOCKET_URL", "ws://localhost:8000/ws")
|
56
|
+
config.llama_bot_rails.llamabot_api_url = ENV.fetch("LLAMABOT_API_URL", "http://localhost:8000")
|
51
57
|
config.llama_bot_rails.enable_console_tool = !Rails.env.production?
|
58
|
+
|
59
|
+
# ------------------------------------------------------------------------
|
60
|
+
# Custom State Builder
|
61
|
+
# ------------------------------------------------------------------------
|
62
|
+
# The gem uses `LlamaBotRails::AgentStateBuilder` by default.
|
63
|
+
# Uncomment this line to use the builder in app/llama_bot/
|
64
|
+
#
|
65
|
+
# config.llama_bot_rails.state_builder_class = "#{app_name}::AgentStateBuilder"
|
52
66
|
end
|
53
67
|
RUBY
|
54
68
|
end
|
@@ -56,6 +70,12 @@ module LlamaBotRails
|
|
56
70
|
def finish
|
57
71
|
say "\n✅ LlamaBotRails installed! Visit http://localhost:3000/llama_bot/agent/chat\n", :green
|
58
72
|
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def app_name
|
77
|
+
Rails.application.class.module_parent_name
|
78
|
+
end
|
59
79
|
end
|
60
80
|
end
|
61
81
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Customize the params sent to your LangGraph agent here.
|
4
|
+
# Uncomment the line in the initializer to activate this builder.
|
5
|
+
module <%= app_name %>
|
6
|
+
class AgentStateBuilder
|
7
|
+
def initialize(params:, context:)
|
8
|
+
@params = params
|
9
|
+
@context = context
|
10
|
+
end
|
11
|
+
|
12
|
+
def build
|
13
|
+
{
|
14
|
+
message: @params[:message], # Rails param from JS/chat UI. This is the user's message to the agent.
|
15
|
+
thread_id: @context[:thread_id], # This is the thread id for the agent. It is used to track the conversation history.
|
16
|
+
api_token: @context[:api_token], # This is an authenticated API token for the agent, so that it can authenticate with us. (It may need access to resources on our Rails app, such as the Rails Console.)
|
17
|
+
agent_prompt: LlamaBotRails.agent_prompt_text, # System prompt instructions for the agent. Can be customized in app/llama_bot/prompts/agent_prompt.txt
|
18
|
+
agent_name: "llamabot" # This routes to the appropriate LangGraph agent as defined in LlamaBot/langgraph.json, and enables us to access different agents on our LlamaBot server.
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -13,9 +13,9 @@ module LlamaBotRails
|
|
13
13
|
def build
|
14
14
|
{
|
15
15
|
message: @params[:message], # Rails param from JS/chat UI. This is the user's message to the agent.
|
16
|
-
thread_id: @
|
16
|
+
thread_id: @params[:thread_id], # This is the thread id for the agent. It is used to track the conversation history.
|
17
17
|
api_token: @context[:api_token], # This is an authenticated API token for the agent, so that it can authenticate with us. (It may need access to resources on our Rails app, such as the Rails Console.)
|
18
|
-
agent_prompt: LlamaBotRails.agent_prompt_text, # System prompt instructions for the agent. Can be customized in
|
18
|
+
agent_prompt: LlamaBotRails.agent_prompt_text, # System prompt instructions for the agent. Can be customized in app/llama_bot/prompts/agent_prompt.txt
|
19
19
|
agent_name: "llamabot" #This routes to the appropriate LangGraph agent as defined in LlamaBot/langgraph.json, and enables us to access different agents on our LlamaBot server.
|
20
20
|
}
|
21
21
|
end
|
@@ -20,7 +20,7 @@ module LlamaBotRails
|
|
20
20
|
end
|
21
21
|
|
22
22
|
initializer "llama_bot_rails.defaults" do |app|
|
23
|
-
app.config.llama_bot_rails.state_builder_class
|
23
|
+
app.config.llama_bot_rails.state_builder_class ||= "LlamaBotRails::AgentStateBuilder"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/lib/llama_bot_rails.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require "llama_bot_rails/version"
|
2
2
|
require "llama_bot_rails/engine"
|
3
|
+
|
4
|
+
# require "llama_bot_rails/railtie" # We don't need this, as we're loading the LlamaBot path directly in the engine.
|
3
5
|
require "llama_bot_rails/llama_bot"
|
6
|
+
require "llama_bot_rails/agent_state_builder"
|
4
7
|
|
5
8
|
module LlamaBotRails
|
6
9
|
class << self
|
@@ -9,7 +12,7 @@ module LlamaBotRails
|
|
9
12
|
end
|
10
13
|
|
11
14
|
def agent_prompt_path
|
12
|
-
Rails.root.join("
|
15
|
+
Rails.root.join("app", "llama_bot", "prompts", "agent_prompt.txt")
|
13
16
|
end
|
14
17
|
|
15
18
|
def agent_prompt_text
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: llama_bot_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kody Kendall
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- config/routes.rb
|
125
125
|
- lib/generators/llama_bot_rails/install/install_generator.rb
|
126
126
|
- lib/generators/llama_bot_rails/install/templates/agent_prompt.txt
|
127
|
+
- lib/generators/llama_bot_rails/install/templates/agent_state_builder.rb.erb
|
127
128
|
- lib/llama_bot_rails.rb
|
128
129
|
- lib/llama_bot_rails/agent_state_builder.rb
|
129
130
|
- lib/llama_bot_rails/engine.rb
|