langgraph_rb 0.1.6 → 0.1.7
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/examples/chat_openai_tools_example.rb +6 -2
- data/lib/langgraph_rb/chat_openai.rb +6 -0
- data/lib/langgraph_rb/graph.rb +2 -2
- data/lib/langgraph_rb/llm_base.rb +10 -0
- data/lib/langgraph_rb/node.rb +7 -3
- data/lib/langgraph_rb/observers/base.rb +4 -0
- data/lib/langgraph_rb/observers/langfuse.rb +18 -0
- data/lib/langgraph_rb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bd46b52a6c57bec611953702facad328eda63e0c5f66f85c403230d05548709b
|
|
4
|
+
data.tar.gz: 19e32e26b6c38044536b8498c7900bcb19386adf1853881cc3a9c3ca3861dae4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed37faa9f9cc70f30a63ac31f96daafd2fa8f6362f78607ac3532ee396fdd04037265a428fc2e5492b4971100be836845e29228e59b5876abc8b50239c9b83a4
|
|
7
|
+
data.tar.gz: 33a4b49fa73f482c4a66299b0a58964be9a81f505e44d35c36b033334b73a24341fc3e78349ff0652f26ca0ae6884b5623fa07d8263570367a790b1324e278ec
|
|
@@ -38,7 +38,7 @@ end
|
|
|
38
38
|
def run_chat_openai_tools
|
|
39
39
|
tools = [MovieInfoTool.new(api_key: ENV['TMDB_API_KEY'] || 'demo')]
|
|
40
40
|
|
|
41
|
-
chat = LangGraphRB::ChatOpenAI.new(model: ENV.fetch('OPENAI_MODEL', 'gpt-4o-
|
|
41
|
+
chat = LangGraphRB::ChatOpenAI.new(model: ENV.fetch('OPENAI_MODEL', 'gpt-4o-min3i'), temperature: 0)
|
|
42
42
|
chat = chat.bind_tools(tools)
|
|
43
43
|
|
|
44
44
|
observers = [LangGraphRB::Observers::LangfuseObserver.new(name: 'chat-openai-tools-example')]
|
|
@@ -50,7 +50,11 @@ def run_chat_openai_tools
|
|
|
50
50
|
{ messages: existing + [user_msg] }
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
# Optional: callback to observe each assistant message as it's produced
|
|
54
|
+
add_message_callback = ->(message) { puts "New message: #{message}" }
|
|
55
|
+
sys_prompt = "You are a movie assistant. Use tools when helpful."
|
|
56
|
+
|
|
57
|
+
llm_node :chat, llm_client: chat, system_prompt: sys_prompt, add_message_callback: add_message_callback
|
|
54
58
|
|
|
55
59
|
tool_node :tool, tools: tools
|
|
56
60
|
|
data/lib/langgraph_rb/graph.rb
CHANGED
|
@@ -35,11 +35,11 @@ module LangGraphRB
|
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
def llm_node(name, llm_client:, system_prompt: nil, &block)
|
|
38
|
+
def llm_node(name, llm_client:, system_prompt: nil, add_message_callback: nil, &block)
|
|
39
39
|
name = name.to_sym
|
|
40
40
|
raise GraphError, "Node '#{name}' already exists" if @nodes.key?(name)
|
|
41
41
|
|
|
42
|
-
@nodes[name] = LLMNode.new(name, llm_client: llm_client, system_prompt: system_prompt, &block)
|
|
42
|
+
@nodes[name] = LLMNode.new(name, llm_client: llm_client, system_prompt: system_prompt, add_message_callback: add_message_callback, &block)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def tool_node(name, tools:, &block)
|
|
@@ -54,6 +54,16 @@ module LangGraphRB
|
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
|
+
|
|
58
|
+
def notify_llm_error(payload)
|
|
59
|
+
@observers.each do |observer|
|
|
60
|
+
begin
|
|
61
|
+
observer.on_llm_error(payload, @node_name)
|
|
62
|
+
rescue => _e
|
|
63
|
+
# Ignore observer errors
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
57
67
|
end
|
|
58
68
|
end
|
|
59
69
|
|
data/lib/langgraph_rb/node.rb
CHANGED
|
@@ -35,11 +35,12 @@ module LangGraphRB
|
|
|
35
35
|
|
|
36
36
|
# Specialized node for LLM calls
|
|
37
37
|
class LLMNode < Node
|
|
38
|
-
attr_reader :llm_client, :system_prompt
|
|
38
|
+
attr_reader :llm_client, :system_prompt, :add_message_callback
|
|
39
39
|
|
|
40
|
-
def initialize(name, llm_client:, system_prompt: nil, &block)
|
|
40
|
+
def initialize(name, llm_client:, system_prompt: nil, add_message_callback: nil, &block)
|
|
41
41
|
@llm_client = llm_client
|
|
42
42
|
@system_prompt = system_prompt
|
|
43
|
+
@add_message_callback = add_message_callback
|
|
43
44
|
|
|
44
45
|
# Use default LLM behavior if no custom block provided
|
|
45
46
|
super(name, &(block || method(:default_llm_call)))
|
|
@@ -49,7 +50,8 @@ module LangGraphRB
|
|
|
49
50
|
# Auto-inject LLM config into the context for both default and custom blocks
|
|
50
51
|
merged_context = (context || {}).merge(
|
|
51
52
|
llm_client: @llm_client,
|
|
52
|
-
system_prompt: @system_prompt
|
|
53
|
+
system_prompt: @system_prompt,
|
|
54
|
+
add_message_callback: @add_message_callback
|
|
53
55
|
)
|
|
54
56
|
|
|
55
57
|
begin
|
|
@@ -87,12 +89,14 @@ module LangGraphRB
|
|
|
87
89
|
content: nil,
|
|
88
90
|
tool_calls: response[:tool_calls]
|
|
89
91
|
}
|
|
92
|
+
@add_message_callback&.call(assistant_msg)
|
|
90
93
|
{
|
|
91
94
|
messages: (state[:messages] || []) + [assistant_msg],
|
|
92
95
|
tool_call: response[:tool_calls].first
|
|
93
96
|
}
|
|
94
97
|
else
|
|
95
98
|
assistant_msg = { role: 'assistant', content: response.to_s }
|
|
99
|
+
@add_message_callback&.call(assistant_msg)
|
|
96
100
|
{
|
|
97
101
|
messages: (state[:messages] || []) + [assistant_msg],
|
|
98
102
|
last_response: response.to_s
|
|
@@ -165,6 +165,24 @@ module LangGraphRB
|
|
|
165
165
|
rescue => _e
|
|
166
166
|
end
|
|
167
167
|
|
|
168
|
+
def on_llm_error(data, node_name)
|
|
169
|
+
record = with_records_lock do
|
|
170
|
+
stack = @records_by_node[node_name]
|
|
171
|
+
stack.empty? ? nil : stack[-1]
|
|
172
|
+
end
|
|
173
|
+
return unless record && record[:generation]
|
|
174
|
+
|
|
175
|
+
generation = record[:generation]
|
|
176
|
+
generation.output = data[:error]
|
|
177
|
+
generation.end_time = Time.now.utc
|
|
178
|
+
Langfuse.update_generation(generation)
|
|
179
|
+
|
|
180
|
+
with_records_lock do
|
|
181
|
+
record[:generation] = nil
|
|
182
|
+
end
|
|
183
|
+
rescue => _e
|
|
184
|
+
end
|
|
185
|
+
|
|
168
186
|
private
|
|
169
187
|
|
|
170
188
|
def ensure_trace!(event)
|
data/lib/langgraph_rb/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: langgraph_rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Julian Toro
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-10-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json
|