pikuri-core 0.0.3 → 0.0.5
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 +10 -0
- data/lib/pikuri/agent/chat_transport.rb +6 -5
- data/lib/pikuri/agent/configurator.rb +59 -77
- data/lib/pikuri/agent/context_window_detector.rb +70 -10
- data/lib/pikuri/agent/control/cancellable.rb +7 -17
- data/lib/pikuri/agent/control/interloper.rb +20 -23
- data/lib/pikuri/agent/control/step_limit.rb +0 -14
- data/lib/pikuri/agent/event.rb +15 -0
- data/lib/pikuri/agent/extension.rb +49 -23
- data/lib/pikuri/agent/listener/terminal.rb +5 -1
- data/lib/pikuri/agent/listener/token_log.rb +20 -21
- data/lib/pikuri/agent/listener_list.rb +7 -5
- data/lib/pikuri/agent/synthesizer.rb +2 -2
- data/lib/pikuri/agent.rb +257 -164
- data/lib/pikuri/file_type.rb +457 -0
- data/lib/pikuri/finalizers.rb +118 -0
- data/lib/pikuri/paths.rb +29 -0
- data/lib/pikuri/subprocess.rb +45 -12
- data/lib/pikuri/tool/parameters.rb +64 -3
- data/lib/pikuri/tool.rb +15 -7
- data/lib/pikuri/version.rb +1 -1
- metadata +5 -3
- data/lib/pikuri/tool/sub_agent.rb +0 -150
|
@@ -41,10 +41,10 @@ module Pikuri
|
|
|
41
41
|
#
|
|
42
42
|
# msg #1: ctx=6.8k/32.0k Δ+6.8k ↑6.8k ↓0.0k
|
|
43
43
|
#
|
|
44
|
-
# When the owning {Agent} has a non-empty {Agent#
|
|
45
|
-
#
|
|
44
|
+
# When the owning {Agent} has a non-empty {Agent#id} (i.e. a
|
|
45
|
+
# sub-agent), the line is prefixed with +[id] +:
|
|
46
46
|
#
|
|
47
|
-
# [
|
|
47
|
+
# [researcher 0] msg #1: ctx=4.2k Δ+4.2k ↑4.2k ↓0.0k
|
|
48
48
|
#
|
|
49
49
|
# +ctx+ is the snapshot
|
|
50
50
|
# (+input + cached + cache_creation + output+; see
|
|
@@ -89,16 +89,15 @@ module Pikuri
|
|
|
89
89
|
# @return [Integer, nil]
|
|
90
90
|
attr_accessor :context_window_cap
|
|
91
91
|
|
|
92
|
-
# @return [String] owning agent's
|
|
92
|
+
# @return [String] owning agent's id ({Agent#id}). Empty by
|
|
93
93
|
# default (main agent); set by {#for_sub_agent} from the
|
|
94
|
-
# sub-agent's generated
|
|
95
|
-
# prefixed with +[<
|
|
96
|
-
#
|
|
97
|
-
|
|
98
|
-
attr_reader :name
|
|
94
|
+
# sub-agent's generated id so the log lines can be
|
|
95
|
+
# prefixed with +[<id>] +. Read-only — for a sub-agent's
|
|
96
|
+
# listener you get a fresh instance via {#for_sub_agent}.
|
|
97
|
+
attr_reader :id
|
|
99
98
|
|
|
100
99
|
# The most recent log line, in the exact format written to
|
|
101
|
-
# {LOGGER} (including any +[<
|
|
100
|
+
# {LOGGER} (including any +[<id>] + prefix). Empty until
|
|
102
101
|
# the first {Event::Tokens} has been processed. Hosts that
|
|
103
102
|
# want to surface the current context-window snapshot in
|
|
104
103
|
# their own UI (e.g. a TUI status footer) read this
|
|
@@ -113,12 +112,12 @@ module Pikuri
|
|
|
113
112
|
# @return [String]
|
|
114
113
|
attr_reader :status_line
|
|
115
114
|
|
|
116
|
-
# @param
|
|
117
|
-
# log line as +[<
|
|
118
|
-
#
|
|
119
|
-
def initialize(
|
|
115
|
+
# @param id [String] owning agent's id, prepended to each
|
|
116
|
+
# log line as +[<id>] + when non-empty. Defaults to +""+
|
|
117
|
+
# for the main agent.
|
|
118
|
+
def initialize(id: '')
|
|
120
119
|
super()
|
|
121
|
-
@
|
|
120
|
+
@id = id
|
|
122
121
|
@msg = 0
|
|
123
122
|
@context_window_size = 0
|
|
124
123
|
@context_window_cap = nil
|
|
@@ -128,17 +127,17 @@ module Pikuri
|
|
|
128
127
|
# Sub-agent variant: a fresh +TokenLog+ with a zeroed
|
|
129
128
|
# snapshot so the sub-agent's context-window readings
|
|
130
129
|
# track its own +RubyLLM::Chat+ rather than continuing the
|
|
131
|
-
# parent's. Picks the sub-agent's +
|
|
132
|
-
# forwarded params so its log lines carry the +[<
|
|
130
|
+
# parent's. Picks the sub-agent's +id:+ out of the
|
|
131
|
+
# forwarded params so its log lines carry the +[<id>] +
|
|
133
132
|
# prefix; defaults to +""+ when absent. The cap is left
|
|
134
133
|
# +nil+ here; the sub-agent's {Agent#initialize} emits a
|
|
135
134
|
# fresh {Event::ContextCap} immediately after construction
|
|
136
135
|
# and this listener picks it up off the stream.
|
|
137
136
|
#
|
|
138
|
-
# @param
|
|
137
|
+
# @param id [String] sub-agent's id
|
|
139
138
|
# @return [TokenLog]
|
|
140
|
-
def for_sub_agent(
|
|
141
|
-
self.class.new(
|
|
139
|
+
def for_sub_agent(id: '', **)
|
|
140
|
+
self.class.new(id: id)
|
|
142
141
|
end
|
|
143
142
|
|
|
144
143
|
# @param event [Agent::Event]
|
|
@@ -184,7 +183,7 @@ module Pikuri
|
|
|
184
183
|
|
|
185
184
|
def format_line(input, output, delta)
|
|
186
185
|
sign = delta.negative? ? '-' : '+'
|
|
187
|
-
prefix = @
|
|
186
|
+
prefix = @id.empty? ? '' : "[#{@id}] "
|
|
188
187
|
"#{prefix}msg ##{@msg}: ctx=#{format_ctx} Δ#{sign}#{format_k(delta.abs)} ↑#{format_k(input)} ↓#{format_k(output)}"
|
|
189
188
|
end
|
|
190
189
|
|
|
@@ -35,8 +35,9 @@ module Pikuri
|
|
|
35
35
|
|
|
36
36
|
# Iterate over the wrapped listeners in registration order. The
|
|
37
37
|
# method exists so a ListenerList can be passed directly to
|
|
38
|
-
# {Configurator#add_listeners} (used by
|
|
39
|
-
# seeding a sub-agent's Configurator
|
|
38
|
+
# {Configurator#add_listeners} (used by the +agent+ tool from
|
|
39
|
+
# +pikuri-subagents+ when seeding a sub-agent's Configurator
|
|
40
|
+
# from the parent's list).
|
|
40
41
|
#
|
|
41
42
|
# @yield [listener]
|
|
42
43
|
# @yieldparam listener [Listener::Base]
|
|
@@ -59,13 +60,14 @@ module Pikuri
|
|
|
59
60
|
# change this class — see {Listener::Terminal#for_sub_agent}
|
|
60
61
|
# (fresh padded instance) and
|
|
61
62
|
# {Listener::TokenLog#for_sub_agent} (fresh, zeroed snapshot
|
|
62
|
-
# with the forwarded +
|
|
63
|
+
# with the forwarded +id:+).
|
|
63
64
|
#
|
|
64
65
|
# +params+ is a flat hash forwarded as kwargs to every
|
|
65
66
|
# listener's hook; each listener picks the keys it cares about
|
|
66
67
|
# and ignores the rest. The only key currently consumed by
|
|
67
|
-
# bundled listeners is +
|
|
68
|
-
#
|
|
68
|
+
# bundled listeners is +id:+ (used by {Listener::TokenLog} to
|
|
69
|
+
# prefix its log lines with the sub-agent's id). Calling with
|
|
70
|
+
# no params is always valid.
|
|
69
71
|
#
|
|
70
72
|
# @param params [Hash{Symbol => Object}]
|
|
71
73
|
# @return [ListenerList]
|
|
@@ -45,7 +45,7 @@ module Pikuri
|
|
|
45
45
|
# reasoning and answer flow through the same listener
|
|
46
46
|
# surface the parent agent uses — terminal renders them
|
|
47
47
|
# inline (padded under sub-agent), an in-memory recorder
|
|
48
|
-
# picks them up, a TokenLog tags them with the synth
|
|
48
|
+
# picks them up, a TokenLog tags them with the synth id.
|
|
49
49
|
#
|
|
50
50
|
# @param chat [RubyLLM::Chat] a *fresh* chat with no tools.
|
|
51
51
|
# The caller is responsible for constructing it with the
|
|
@@ -58,7 +58,7 @@ module Pikuri
|
|
|
58
58
|
# @param listeners [Agent::ListenerList] listeners to wire
|
|
59
59
|
# the synth chat into. Typically the parent agent's list
|
|
60
60
|
# run through {ListenerList#for_sub_agent} with the
|
|
61
|
-
# synth's +
|
|
61
|
+
# synth's +id:+ so any +TokenLog+ tags its lines with
|
|
62
62
|
# the synth bracket and any +Terminal+ pads its output.
|
|
63
63
|
# @param step_limit [Control::StepLimit, nil] defensive
|
|
64
64
|
# step budget. The synth has no tools so it should never
|