aia 2.0.0.0.pre.alpha → 2.0.0
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/.version +1 -1
- data/CHANGELOG.md +151 -228
- data/README.md +42 -19
- data/bin/aia +8 -3
- data/lib/aia/aia_completion.bash +2 -3
- data/lib/aia/aia_completion.fish +6 -5
- data/lib/aia/aia_completion.zsh +2 -3
- data/lib/aia/chat_loop.rb +24 -66
- data/lib/aia/config/cli_parser.rb +164 -123
- data/lib/aia/config/defaults.yml +12 -39
- data/lib/aia/config/mcp_parser.rb +42 -40
- data/lib/aia/config/model_spec.rb +8 -14
- data/lib/aia/config/validator.rb +144 -156
- data/lib/aia/config/value_caster.rb +76 -0
- data/lib/aia/config.rb +72 -54
- data/lib/aia/content_extractor.rb +2 -0
- data/lib/aia/cost_calculator.rb +1 -0
- data/lib/aia/crew.rb +29 -19
- data/lib/aia/debate_handler.rb +45 -20
- data/lib/aia/delegate_handler.rb +7 -3
- data/lib/aia/directive.rb +10 -8
- data/lib/aia/directives/configuration_directives.rb +164 -109
- data/lib/aia/directives/context_directives.rb +55 -40
- data/lib/aia/directives/execution_directives.rb +25 -25
- data/lib/aia/directives/model_directives.rb +112 -195
- data/lib/aia/directives/trakflow_directives.rb +27 -9
- data/lib/aia/directives/utility_directives.rb +86 -87
- data/lib/aia/directives/web_and_file_directives.rb +83 -63
- data/lib/aia/fact_asserter.rb +3 -3
- data/lib/aia/history_transfer.rb +64 -24
- data/lib/aia/layered_orchestrator.rb +66 -43
- data/lib/aia/logger.rb +27 -62
- data/lib/aia/mcp_config_normalizer.rb +27 -14
- data/lib/aia/mcp_connection_manager.rb +193 -186
- data/lib/aia/mcp_discovery.rb +43 -15
- data/lib/aia/mcp_grouper.rb +2 -1
- data/lib/aia/mcp_server_config.rb +48 -0
- data/lib/aia/mcp_utility.rb +28 -20
- data/lib/aia/mention_router.rb +22 -52
- data/lib/aia/modality_query.rb +36 -0
- data/lib/aia/model_alias_registry.rb +11 -11
- data/lib/aia/model_registry.rb +75 -0
- data/lib/aia/network_builder.rb +17 -11
- data/lib/aia/network_memory_manager.rb +6 -6
- data/lib/aia/patches/ruby_llm_streaming_error.rb +21 -4
- data/lib/aia/patches/ruby_llm_tool_param_compat.rb +18 -0
- data/lib/aia/pipeline_orchestrator.rb +88 -45
- data/lib/aia/plugin_monitor.rb +9 -6
- data/lib/aia/prompt_decomposer.rb +6 -4
- data/lib/aia/prompt_handler.rb +90 -69
- data/lib/aia/provider_registry.rb +105 -0
- data/lib/aia/robot_builder.rb +1 -1
- data/lib/aia/robot_factory.rb +77 -69
- data/lib/aia/robot_namer.rb +2 -8
- data/lib/aia/robot_sync.rb +79 -0
- data/lib/aia/role_catalog.rb +89 -0
- data/lib/aia/session.rb +32 -14
- data/lib/aia/session_tracker.rb +39 -41
- data/lib/aia/similarity_scorer.rb +5 -3
- data/lib/aia/skill_utils.rb +60 -19
- data/lib/aia/spawn_handler.rb +16 -4
- data/lib/aia/spawn_spec_parser.rb +6 -7
- data/lib/aia/special_mode_handler.rb +80 -57
- data/lib/aia/speech.rb +103 -0
- data/lib/aia/startup_coordinator.rb +17 -91
- data/lib/aia/streaming_runner.rb +16 -5
- data/lib/aia/system_prompt_assembler.rb +20 -15
- data/lib/aia/task_board.rb +60 -0
- data/lib/aia/task_coordinator.rb +10 -5
- data/lib/aia/timing.rb +15 -0
- data/lib/aia/tool_approver.rb +205 -0
- data/lib/aia/tool_filter.rb +1 -9
- data/lib/aia/tool_filter_strategy.rb +39 -25
- data/lib/aia/tool_introspection.rb +25 -0
- data/lib/aia/tool_loader.rb +71 -31
- data/lib/aia/tool_utility.rb +6 -5
- data/lib/aia/tools/delegate_to_foreman_tool.rb +6 -4
- data/lib/aia/tools/recruit_robot_tool.rb +12 -12
- data/lib/aia/tools/reskill_robot_tool.rb +7 -7
- data/lib/aia/tools/task_board_tool.rb +17 -16
- data/lib/aia/trakflow_bridge.rb +19 -11
- data/lib/aia/turn_state.rb +32 -8
- data/lib/aia/ui_presenter.rb +83 -59
- data/lib/aia/utility.rb +8 -24
- data/lib/aia/variable_input_collector.rb +1 -3
- data/lib/aia/verification_network.rb +10 -12
- data/lib/aia.rb +49 -8
- metadata +27 -162
- data/.better-commits.json +0 -150
- data/.config/tocer/configuration.yml +0 -6
- data/.envrc +0 -15
- data/.loki +0 -231
- data/.quality/flay_baseline.txt +0 -1
- data/.quality/flog_baseline.txt +0 -29
- data/.quality/reek_baseline.txt +0 -80
- data/.rubocop.yml +0 -116
- data/COMMITS.md +0 -196
- data/IMPLEMENTATION_PLAN.md +0 -506
- data/Rakefile +0 -160
- data/architecture_review.md +0 -314
- data/docs/AGENTS.md +0 -40
- data/docs/advanced-prompting.md +0 -814
- data/docs/assets/images/aia.png +0 -0
- data/docs/cli-reference.md +0 -1241
- data/docs/configuration.md +0 -747
- data/docs/contributing.md +0 -386
- data/docs/directives-reference.md +0 -1145
- data/docs/examples/index.md +0 -277
- data/docs/examples/mcp/index.md +0 -475
- data/docs/examples/prompts/analysis/index.md +0 -78
- data/docs/examples/prompts/automation/index.md +0 -109
- data/docs/examples/prompts/development/index.md +0 -125
- data/docs/examples/prompts/index.md +0 -333
- data/docs/examples/prompts/learning/index.md +0 -127
- data/docs/examples/prompts/writing/index.md +0 -62
- data/docs/examples/tools/index.md +0 -282
- data/docs/faq.md +0 -578
- data/docs/guides/available-models.md +0 -366
- data/docs/guides/basic-usage.md +0 -478
- data/docs/guides/chat.md +0 -680
- data/docs/guides/crew.md +0 -239
- data/docs/guides/executable-prompts.md +0 -331
- data/docs/guides/first-prompt.md +0 -454
- data/docs/guides/getting-started.md +0 -455
- data/docs/guides/image-generation.md +0 -507
- data/docs/guides/index.md +0 -48
- data/docs/guides/local-models.md +0 -306
- data/docs/guides/migrate-prompts.md +0 -335
- data/docs/guides/models.md +0 -1017
- data/docs/guides/shared-tools.md +0 -254
- data/docs/guides/tools.md +0 -831
- data/docs/index.md +0 -259
- data/docs/installation.md +0 -274
- data/docs/mcp-integration.md +0 -603
- data/docs/prompt_management.md +0 -665
- data/docs/security.md +0 -674
- data/docs/special_projects_guide.md +0 -386
- data/docs/tools-and-mcp-examples.md +0 -1211
- data/docs/workflows-and-pipelines.md +0 -636
- data/examples/.gitignore +0 -2
- data/examples/00_setup_aia.sh +0 -111
- data/examples/01_basic_usage.sh +0 -23
- data/examples/02_frontmatter.sh +0 -33
- data/examples/03_shell_integration.sh +0 -55
- data/examples/04_erb_templating.sh +0 -56
- data/examples/05_shell_then_erb.sh +0 -38
- data/examples/06_prompt_chaining.sh +0 -59
- data/examples/07_pipeline.sh +0 -46
- data/examples/08_context_files.sh +0 -43
- data/examples/09_roles.sh +0 -67
- data/examples/10_stdin_piping.sh +0 -49
- data/examples/11_multi_model.sh +0 -65
- data/examples/12_token_usage.sh +0 -52
- data/examples/13_cost_tracking.sh +0 -68
- data/examples/14_output_file.sh +0 -91
- data/examples/15_parameters.sh +0 -68
- data/examples/16_directives.sh +0 -113
- data/examples/17_require_and_conditionals.sh +0 -68
- data/examples/18_tools.sh +0 -61
- data/examples/19_local_tools.sh +0 -34
- data/examples/20_mcp_servers.sh +0 -102
- data/examples/21_executable_prompts.sh +0 -78
- data/examples/22_chat_mode.sh +0 -217
- data/examples/23_verify.sh +0 -139
- data/examples/24_decompose.sh +0 -139
- data/examples/25_spawn.sh +0 -139
- data/examples/26_debate.sh +0 -97
- data/examples/27_mention_routing.sh +0 -157
- data/examples/28_model_switching.sh +0 -106
- data/examples/29_agent_harness.sh +0 -177
- data/examples/README.md +0 -321
- data/examples/advanced_multi_robot_capabilities_without_examples.md +0 -106
- data/examples/aia_config.yml +0 -22
- data/examples/aia_config_orchestrator.yml +0 -45
- data/examples/aia_config_with_mcp.yml +0 -21
- data/examples/common.sh +0 -39
- data/examples/context/project_goals.md +0 -6
- data/examples/context/tech_stack.md +0 -7
- data/examples/directives/timestamp_directive.rb +0 -22
- data/examples/mcp/filesystem.json +0 -9
- data/examples/prompts_dir/analyze.md +0 -2
- data/examples/prompts_dir/brainstorm.md +0 -2
- data/examples/prompts_dir/conditional.md +0 -17
- data/examples/prompts_dir/creative.md +0 -4
- data/examples/prompts_dir/erbinfo.md +0 -5
- data/examples/prompts_dir/erbinfo_raw.md +0 -8
- data/examples/prompts_dir/evaluate.md +0 -2
- data/examples/prompts_dir/explain_joke.md +0 -1
- data/examples/prompts_dir/explain_recursion.md +0 -1
- data/examples/prompts_dir/fun_fact +0 -3
- data/examples/prompts_dir/greeting.md +0 -8
- data/examples/prompts_dir/greeting_required.md +0 -7
- data/examples/prompts_dir/hello.md +0 -1
- data/examples/prompts_dir/includes/ruby_facts.md +0 -4
- data/examples/prompts_dir/limerick.md +0 -1
- data/examples/prompts_dir/list_with_mcp.md +0 -3
- data/examples/prompts_dir/pick_best.md +0 -2
- data/examples/prompts_dir/project_summary +0 -12
- data/examples/prompts_dir/quiz_with_include.md +0 -6
- data/examples/prompts_dir/require_demo.md +0 -5
- data/examples/prompts_dir/roles/formal.md +0 -3
- data/examples/prompts_dir/roles/orchestrator.md +0 -21
- data/examples/prompts_dir/roles/pirate.md +0 -3
- data/examples/prompts_dir/shell_then_erb.md +0 -6
- data/examples/prompts_dir/sort_compare.md +0 -2
- data/examples/prompts_dir/summarize_context.md +0 -2
- data/examples/prompts_dir/sysinfo.md +0 -5
- data/examples/prompts_dir/sysinfo_raw.md +0 -8
- data/examples/prompts_dir/tagline.md +0 -1
- data/examples/prompts_dir/tell_joke.md +0 -1
- data/examples/prompts_dir/tell_joke_with_next.md +0 -4
- data/examples/prompts_dir/use_local_tool.md +0 -8
- data/examples/prompts_dir/use_tools.md +0 -8
- data/examples/prompts_dir/weather.md +0 -2
- data/examples/prompts_dir/whats_new.md +0 -2
- data/examples/prompts_dir/with_timestamp.md +0 -5
- data/examples/requirements/sinatra_taskflow_app.md +0 -139
- data/examples/rules/01_classify_ruby.rb +0 -16
- data/examples/rules/02_prefer_claude_for_code.rb +0 -19
- data/examples/rules/03_gate_prompt_length.rb +0 -19
- data/examples/rules/04_tool_selection.rb +0 -41
- data/examples/rules/README.md +0 -30
- data/examples/run_all.sh +0 -294
- data/examples/tools/word_count_tool.rb +0 -30
- data/lib/AGENTS.md +0 -57
- data/lib/aia/model_switch_handler.rb +0 -100
- data/mcp_servers/README.md +0 -110
- data/mcp_servers/apple-mcp.json +0 -8
- data/mcp_servers/filesystem.json +0 -9
- data/mcp_servers/mcp_server_chart.json +0 -11
- data/mcp_servers/playwright_one.json +0 -8
- data/mcp_servers/playwright_server_definition.json +0 -9
- data/mcp_servers/playwright_two.json +0 -8
- data/mcp_servers/tavily_mcp_server.json +0 -8
- data/mkdocs.yml +0 -169
data/lib/aia/mcp_utility.rb
CHANGED
|
@@ -14,7 +14,6 @@ module AIA
|
|
|
14
14
|
def mcp_server_names
|
|
15
15
|
connected = AIA.config&.connected_mcp_servers
|
|
16
16
|
return connected unless connected.nil?
|
|
17
|
-
return RubyLLM::MCP.clients.keys if defined?(RubyLLM::MCP) && RubyLLM::MCP.clients.any?
|
|
18
17
|
effective_mcp_server_names
|
|
19
18
|
end
|
|
20
19
|
|
|
@@ -27,31 +26,40 @@ module AIA
|
|
|
27
26
|
end
|
|
28
27
|
|
|
29
28
|
def effective_mcp_server_names
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return [] if servers.empty?
|
|
29
|
+
cfg = AIA.config
|
|
30
|
+
return [] if cfg&.flags&.no_mcp
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
skip_list = Array(AIA.config.mcp_skip)
|
|
32
|
+
servers = cfg&.mcp_servers || []
|
|
33
|
+
return [] if servers.empty?
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
names.select { |n| use_list.include?(n) }
|
|
40
|
-
elsif skip_list.any?
|
|
41
|
-
names.reject { |n| skip_list.include?(n) }
|
|
42
|
-
else
|
|
43
|
-
names
|
|
44
|
-
end
|
|
35
|
+
MCPDiscovery.select(servers, use: cfg.mcp_use, skip: cfg.mcp_skip).map { server_name(it) }.compact
|
|
45
36
|
end
|
|
46
37
|
|
|
38
|
+
# The name a configured server is known by: a Hash's :name, a server
|
|
39
|
+
# instance's #name, or for a RubyLLM::MCP subclass (or its constant name,
|
|
40
|
+
# e.g. "SharedTools::MCP::GitHub") the server's default name ("github").
|
|
41
|
+
# A constant name whose class is not loaded yet is returned as given.
|
|
47
42
|
def server_name(s)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
else
|
|
53
|
-
s.to_s
|
|
43
|
+
case s
|
|
44
|
+
when Hash then s[:name] || s['name']
|
|
45
|
+
when Class then s.respond_to?(:default_name) ? s.default_name : s.name
|
|
46
|
+
when String then mcp_class_name?(s) ? class_server_name(s) : s
|
|
47
|
+
else s.respond_to?(:name) ? s.name : s.to_s
|
|
54
48
|
end
|
|
55
49
|
end
|
|
50
|
+
|
|
51
|
+
# True when +value+ is shaped like a Ruby constant path ("Foo::Bar"),
|
|
52
|
+
# the form an mcp_servers: entry takes to name a RubyLLM::MCP subclass.
|
|
53
|
+
def mcp_class_name?(value)
|
|
54
|
+
value.is_a?(String) && value.match?(/\A(::)?[A-Z]\w*(::[A-Z]\w*)*\z/)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def class_server_name(constant_name)
|
|
60
|
+
RobotLab::MCP.name_of(constant_name)
|
|
61
|
+
rescue RobotLab::MCPError
|
|
62
|
+
constant_name
|
|
63
|
+
end
|
|
56
64
|
end
|
|
57
65
|
end
|
data/lib/aia/mention_router.rb
CHANGED
|
@@ -10,10 +10,15 @@ module AIA
|
|
|
10
10
|
class MentionRouter
|
|
11
11
|
include ContentExtractor
|
|
12
12
|
include HandlerProtocol
|
|
13
|
+
include Speech
|
|
13
14
|
|
|
14
15
|
# Reserved @mention that broadcasts the message to every crew member.
|
|
15
16
|
BROADCAST_TOKEN = 'crew'
|
|
16
17
|
|
|
18
|
+
# An @name at the start of a word. The look-behind leaves e-mail
|
|
19
|
+
# addresses (bob@example.com) and dotted names alone.
|
|
20
|
+
MENTION = /(?<![\w.@])@(\w+)/
|
|
21
|
+
|
|
17
22
|
def initialize(ui_presenter:, tracker:, streaming_runner:)
|
|
18
23
|
@ui_presenter = ui_presenter
|
|
19
24
|
@tracker = tracker
|
|
@@ -25,18 +30,23 @@ module AIA
|
|
|
25
30
|
#
|
|
26
31
|
# @param context [HandlerContext] — reads context.robot and context.prompt
|
|
27
32
|
# @return [Boolean]
|
|
33
|
+
# :reek:TooManyStatements -- mention routing: scan, resolve, report unknowns, dispatch; one decision chain
|
|
28
34
|
def handle(context) # rubocop:disable Naming/PredicateMethod
|
|
29
35
|
robot = context.robot
|
|
30
36
|
prompt = context.prompt
|
|
31
37
|
return false unless robot.network?
|
|
32
38
|
|
|
33
|
-
mention_tokens = prompt.scan(
|
|
39
|
+
mention_tokens = prompt.scan(MENTION).flatten
|
|
34
40
|
return false if mention_tokens.empty?
|
|
35
41
|
|
|
36
42
|
all_robots = robot.crew
|
|
37
43
|
matched = resolve_mentions(mention_tokens, all_robots)
|
|
38
44
|
|
|
45
|
+
# No crew member named: ordinary text for the model, unless the message
|
|
46
|
+
# opens with an @address -- most likely a mistyped name.
|
|
39
47
|
if matched.empty?
|
|
48
|
+
return false unless addressed?(prompt)
|
|
49
|
+
|
|
40
50
|
report_unknown_mentions(mention_tokens, all_robots)
|
|
41
51
|
return true
|
|
42
52
|
end
|
|
@@ -58,11 +68,16 @@ module AIA
|
|
|
58
68
|
prompt.sub(/\A(?:\s*@\w+)+\s*/i, '').strip
|
|
59
69
|
end
|
|
60
70
|
|
|
71
|
+
# True when the message opens with an @address.
|
|
72
|
+
def addressed?(prompt)
|
|
73
|
+
prompt.match?(/\A\s*@\w/)
|
|
74
|
+
end
|
|
75
|
+
|
|
61
76
|
# True when every @mention is part of the leading address — i.e. nothing but
|
|
62
77
|
# @mentions before the message — so it's a broadcast to its addressees and
|
|
63
78
|
# runs concurrently. A @mention woven into the body makes it sequential.
|
|
64
79
|
def leading_address_only?(prompt)
|
|
65
|
-
!strip_addressing_prefix(prompt).match?(
|
|
80
|
+
!strip_addressing_prefix(prompt).match?(MENTION)
|
|
66
81
|
end
|
|
67
82
|
|
|
68
83
|
# Resolve @mention tokens to robots. The reserved @crew token broadcasts to
|
|
@@ -120,10 +135,11 @@ module AIA
|
|
|
120
135
|
|
|
121
136
|
# A single addressed robot streams its reply token-by-token.
|
|
122
137
|
def run_streamed(bot, prompt)
|
|
138
|
+
name = bot.name
|
|
123
139
|
result, streamed_content, elapsed = @streaming_runner.run(
|
|
124
140
|
bot, prompt,
|
|
125
|
-
header: "\nAI (#{
|
|
126
|
-
spinner_message: "#{
|
|
141
|
+
header: "\nAI (#{name}):\n ",
|
|
142
|
+
spinner_message: "#{name} processing..."
|
|
127
143
|
)
|
|
128
144
|
content = streamed_content || extract_content(result)
|
|
129
145
|
|
|
@@ -137,7 +153,7 @@ module AIA
|
|
|
137
153
|
finalize_reply(bot, prompt, result, content, elapsed)
|
|
138
154
|
content
|
|
139
155
|
rescue StandardError => e
|
|
140
|
-
@ui_presenter.display_info("Error from #{
|
|
156
|
+
@ui_presenter.display_info("Error from #{name}: #{e.class}: #{e.message}")
|
|
141
157
|
nil
|
|
142
158
|
end
|
|
143
159
|
|
|
@@ -156,6 +172,7 @@ module AIA
|
|
|
156
172
|
|
|
157
173
|
# Run one crew member to completion (off the streaming path), in a worker
|
|
158
174
|
# thread. Returns [bot, result, elapsed, error] — no shared state touched.
|
|
175
|
+
# :reek:DuplicateMethodCall -- each clock_gettime must read the clock at that moment (start, success end, failure end)
|
|
159
176
|
def run_member(bot, prompt)
|
|
160
177
|
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
161
178
|
result = bot.run(prompt, mcp: :inherit, tools: :inherit)
|
|
@@ -209,52 +226,5 @@ module AIA
|
|
|
209
226
|
return message.model if message.respond_to?(:model) && message.model
|
|
210
227
|
nil
|
|
211
228
|
end
|
|
212
|
-
|
|
213
|
-
def speak(content)
|
|
214
|
-
return unless AIA.speak?
|
|
215
|
-
|
|
216
|
-
audio = AIA.config.audio
|
|
217
|
-
command = audio.speak_command || 'say'
|
|
218
|
-
env = {}
|
|
219
|
-
env['SPEECH_MODEL'] = audio.speech_model if audio.speech_model
|
|
220
|
-
|
|
221
|
-
if command == 'say'
|
|
222
|
-
run_with_spinner("Speaking...") do
|
|
223
|
-
if audio.voice && !audio.voice.to_s.strip.empty?
|
|
224
|
-
system(env, command, '-v', audio.voice, content.to_s)
|
|
225
|
-
else
|
|
226
|
-
system(env, command, content.to_s)
|
|
227
|
-
end
|
|
228
|
-
end
|
|
229
|
-
else
|
|
230
|
-
require 'tempfile'
|
|
231
|
-
tmpfile = Tempfile.new(['aia-tts-', '.mp3'])
|
|
232
|
-
tmpfile.close
|
|
233
|
-
begin
|
|
234
|
-
run_with_spinner("Converting to audio...") do
|
|
235
|
-
system(env, command, content.to_s, tmpfile.path)
|
|
236
|
-
end
|
|
237
|
-
if File.size?(tmpfile.path)
|
|
238
|
-
run_with_spinner("Speaking...") do
|
|
239
|
-
system('afplay', tmpfile.path)
|
|
240
|
-
end
|
|
241
|
-
end
|
|
242
|
-
ensure
|
|
243
|
-
tmpfile.unlink
|
|
244
|
-
end
|
|
245
|
-
end
|
|
246
|
-
rescue StandardError => e
|
|
247
|
-
$stderr.puts "Warning: Speech failed: #{e.message}"
|
|
248
|
-
end
|
|
249
|
-
|
|
250
|
-
def run_with_spinner(message)
|
|
251
|
-
spinner = TTY::Spinner.new("[:spinner] #{message}", format: :bouncing_ball, output: $stderr)
|
|
252
|
-
spinner.auto_spin
|
|
253
|
-
begin
|
|
254
|
-
yield
|
|
255
|
-
ensure
|
|
256
|
-
spinner.stop
|
|
257
|
-
end
|
|
258
|
-
end
|
|
259
229
|
end
|
|
260
230
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# lib/aia/modality_query.rb
|
|
4
|
+
#
|
|
5
|
+
# Matches a model's input/output modalities against an "INPUT_to_OUTPUT"
|
|
6
|
+
# search term such as "text_to_image" (as used by --available-models and
|
|
7
|
+
# /available_models). RubyLLM 2.x exposes modalities as plain input/output
|
|
8
|
+
# lists, so the term is split and each side is looked up in its list.
|
|
9
|
+
|
|
10
|
+
module AIA
|
|
11
|
+
module ModalityQuery
|
|
12
|
+
SEPARATOR = '_to_'
|
|
13
|
+
|
|
14
|
+
module_function
|
|
15
|
+
|
|
16
|
+
# @param term [String]
|
|
17
|
+
# @return [Boolean] true when +term+ has the INPUT_to_OUTPUT form
|
|
18
|
+
def modality_term?(term)
|
|
19
|
+
term.to_s.include?(SEPARATOR)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# @param modalities [#input, #output] a model's modalities
|
|
23
|
+
# @param term [String] e.g. "text_to_image" or ":image_to_text"
|
|
24
|
+
# @return [Boolean]
|
|
25
|
+
def matches?(modalities, term)
|
|
26
|
+
input, output = term.to_s.delete_prefix(':').downcase.split(SEPARATOR, 2)
|
|
27
|
+
return false if input.to_s.empty? || output.to_s.empty?
|
|
28
|
+
|
|
29
|
+
names(modalities.input).include?(input) && names(modalities.output).include?(output)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def names(list)
|
|
33
|
+
Array(list).map { it.to_s.downcase }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -9,28 +9,28 @@ module AIA
|
|
|
9
9
|
class ModelAliasRegistry
|
|
10
10
|
DEFAULT_ALIASES = {
|
|
11
11
|
# Short names
|
|
12
|
-
"claude" => "claude-sonnet-4-
|
|
13
|
-
"sonnet" => "claude-sonnet-4-
|
|
14
|
-
"opus" => "claude-opus-
|
|
12
|
+
"claude" => "claude-sonnet-4-5",
|
|
13
|
+
"sonnet" => "claude-sonnet-4-5",
|
|
14
|
+
"opus" => "claude-opus-5",
|
|
15
15
|
"haiku" => "claude-haiku-4-5-20251001",
|
|
16
16
|
"gpt4" => "gpt-4o",
|
|
17
17
|
"gpt4o" => "gpt-4o",
|
|
18
18
|
"gpt4mini" => "gpt-4o-mini",
|
|
19
|
-
"gemini" => "gemini-
|
|
20
|
-
"flash" => "gemini-
|
|
21
|
-
"llama" => "llama-
|
|
19
|
+
"gemini" => "gemini-3.8-flash",
|
|
20
|
+
"flash" => "gemini-3.8-flash",
|
|
21
|
+
"llama" => "meta-llama/llama-4-maverick",
|
|
22
22
|
|
|
23
23
|
# Provider names (resolve to default model for provider)
|
|
24
|
-
"anthropic" => "claude-sonnet-4-
|
|
24
|
+
"anthropic" => "claude-sonnet-4-5",
|
|
25
25
|
"openai" => "gpt-4o",
|
|
26
|
-
"google" => "gemini-
|
|
27
|
-
"meta" => "llama-
|
|
26
|
+
"google" => "gemini-3.8-flash",
|
|
27
|
+
"meta" => "meta-llama/llama-4-maverick",
|
|
28
28
|
|
|
29
29
|
# Capability descriptors
|
|
30
30
|
"fast" => "claude-haiku-4-5-20251001",
|
|
31
31
|
"cheap" => "gpt-4o-mini",
|
|
32
|
-
"best" => "claude-opus-
|
|
33
|
-
"coding" => "claude-sonnet-4-
|
|
32
|
+
"best" => "claude-opus-5",
|
|
33
|
+
"coding" => "claude-sonnet-4-5",
|
|
34
34
|
"vision" => "gpt-4o"
|
|
35
35
|
}.freeze
|
|
36
36
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# lib/aia/model_registry.rb
|
|
4
|
+
#
|
|
5
|
+
# AIA's local copy of the RubyLLM model list, kept at
|
|
6
|
+
# <paths.aia_dir>/models.json and refreshed from the provider APIs every
|
|
7
|
+
# registry.refresh days (--refresh DAYS; 0 turns refreshing off).
|
|
8
|
+
|
|
9
|
+
require 'date'
|
|
10
|
+
require 'fileutils'
|
|
11
|
+
|
|
12
|
+
module AIA
|
|
13
|
+
module ModelRegistry
|
|
14
|
+
DEFAULT_REFRESH_DAYS = 7
|
|
15
|
+
|
|
16
|
+
module_function
|
|
17
|
+
|
|
18
|
+
# Point RubyLLM at AIA's models.json, refreshing it first when it is due.
|
|
19
|
+
#
|
|
20
|
+
# @param config [AIA::Config]
|
|
21
|
+
def prepare(config)
|
|
22
|
+
path = registry_path(config.paths&.aia_dir)
|
|
23
|
+
return unless path
|
|
24
|
+
|
|
25
|
+
days = refresh_days(config.registry&.refresh)
|
|
26
|
+
if refresh_due?(path, days)
|
|
27
|
+
refresh(path)
|
|
28
|
+
elsif File.exist?(path)
|
|
29
|
+
use(path)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @return [String, nil] the models.json path, or nil without an aia_dir
|
|
34
|
+
def registry_path(aia_dir)
|
|
35
|
+
return nil if aia_dir.to_s.strip.empty?
|
|
36
|
+
|
|
37
|
+
File.join(File.expand_path(aia_dir), 'models.json')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# The refresh interval as a whole number of days; nil means the default.
|
|
41
|
+
def refresh_days(value)
|
|
42
|
+
return DEFAULT_REFRESH_DAYS if value.nil?
|
|
43
|
+
|
|
44
|
+
[Integer(value.to_s, exception: false) || DEFAULT_REFRESH_DAYS, 0].max
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Whether +path+ is missing or more than +days+ days old. Never due when
|
|
48
|
+
# +days+ is 0.
|
|
49
|
+
def refresh_due?(path, days, today: Date.today)
|
|
50
|
+
return false if days.zero?
|
|
51
|
+
return true unless File.exist?(path)
|
|
52
|
+
|
|
53
|
+
today > File.mtime(path).to_date + days
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Load the model list from +path+.
|
|
57
|
+
def use(path)
|
|
58
|
+
RubyLLM.config.model_registry_file = path
|
|
59
|
+
RubyLLM.models.load_from_json(path)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Refresh the model list from the provider APIs and save it to +path+.
|
|
63
|
+
# On failure RubyLLM keeps the list it already had.
|
|
64
|
+
def refresh(path)
|
|
65
|
+
llm_config = RubyLLM.config
|
|
66
|
+
previous = llm_config.model_registry_file
|
|
67
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
68
|
+
llm_config.model_registry_file = path
|
|
69
|
+
Speech.run_with_spinner("Refreshing the model list...") { RubyLLM.models.refresh }
|
|
70
|
+
rescue StandardError => e
|
|
71
|
+
llm_config&.model_registry_file = previous
|
|
72
|
+
$stderr.puts "Warning: Could not refresh the model list (#{e.message}). Using the existing list."
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
data/lib/aia/network_builder.rb
CHANGED
|
@@ -15,11 +15,12 @@ module AIA
|
|
|
15
15
|
# @param config [AIA::Config]
|
|
16
16
|
# @param namer [RobotNamer]
|
|
17
17
|
# @return [RobotLab::Network]
|
|
18
|
+
# :reek:TooManyStatements -- gathers shared robot inputs then declares one network task per pipeline step
|
|
18
19
|
def build_pipeline_network(config, namer)
|
|
19
20
|
prompts = config.pipeline
|
|
20
21
|
run_config = RobotFactory.build_run_config(config)
|
|
21
22
|
tools = ToolLoader.filtered_tools(config)
|
|
22
|
-
mcp = RobotFactory.
|
|
23
|
+
mcp = RobotFactory.mcp_servers(config)
|
|
23
24
|
model_spec = config.models.first
|
|
24
25
|
|
|
25
26
|
RobotLab.create_network(name: "aia-pipeline") do
|
|
@@ -31,7 +32,7 @@ module AIA
|
|
|
31
32
|
name: "#{namer.name_for(model_spec.name)}-s#{i}",
|
|
32
33
|
system_prompt: nil,
|
|
33
34
|
local_tools: tools,
|
|
34
|
-
|
|
35
|
+
mcp: mcp,
|
|
35
36
|
config: run_config
|
|
36
37
|
)
|
|
37
38
|
task task_name, robot, depends_on: prev ? [prev] : :none
|
|
@@ -48,7 +49,7 @@ module AIA
|
|
|
48
49
|
def build_parallel_network(config, namer)
|
|
49
50
|
run_config = RobotFactory.build_run_config(config)
|
|
50
51
|
tools = ToolLoader.filtered_tools(config)
|
|
51
|
-
mcp = RobotFactory.
|
|
52
|
+
mcp = RobotFactory.mcp_servers(config)
|
|
52
53
|
aia_config = config
|
|
53
54
|
roster = config.models.map { |spec| { name: namer.name_for(spec.name), spec: spec } }
|
|
54
55
|
build_robot = ->(entry) { build_roster_robot(entry, roster, tools, mcp, run_config, aia_config) }
|
|
@@ -66,13 +67,15 @@ module AIA
|
|
|
66
67
|
# @param config [AIA::Config]
|
|
67
68
|
# @param namer [RobotNamer]
|
|
68
69
|
# @return [RobotLab::Network]
|
|
70
|
+
# :reek:TooManyStatements -- gathers shared robot inputs, declares one task per roster member plus the synthesizer
|
|
69
71
|
def build_consensus_network(config, namer)
|
|
70
72
|
run_config = RobotFactory.build_run_config(config)
|
|
71
|
-
tools
|
|
72
|
-
mcp
|
|
73
|
-
|
|
73
|
+
tools = ToolLoader.filtered_tools(config)
|
|
74
|
+
mcp = RobotFactory.mcp_servers(config)
|
|
75
|
+
models = config.models
|
|
76
|
+
primary = models.first
|
|
74
77
|
aia_config = config
|
|
75
|
-
roster =
|
|
78
|
+
roster = models.map { |spec| { name: namer.name_for(spec.name), spec: spec } }
|
|
76
79
|
build_robot = ->(entry) { build_roster_robot(entry, roster, tools, mcp, run_config, aia_config) }
|
|
77
80
|
|
|
78
81
|
RobotLab.create_network(name: "aia-consensus") do
|
|
@@ -89,11 +92,12 @@ module AIA
|
|
|
89
92
|
config: run_config
|
|
90
93
|
)
|
|
91
94
|
task :consensus, synthesizer,
|
|
92
|
-
depends_on:
|
|
95
|
+
depends_on: models.map { |s| s.internal_id.to_sym }
|
|
93
96
|
end
|
|
94
97
|
end
|
|
95
98
|
|
|
96
99
|
# Shared helper: builds a single roster robot (used by parallel and consensus networks).
|
|
100
|
+
# :reek:LongParameterList { max_params: 6 } -- pass-through of the shared per-network build inputs
|
|
97
101
|
def build_roster_robot(entry, roster, tools, mcp, run_config, aia_config)
|
|
98
102
|
spec = entry[:spec]
|
|
99
103
|
identity = SystemPromptAssembler.build_identity_prompt(entry[:name], spec, roster)
|
|
@@ -104,7 +108,7 @@ module AIA
|
|
|
104
108
|
name: entry[:name],
|
|
105
109
|
system_prompt: system_prompt,
|
|
106
110
|
local_tools: tools,
|
|
107
|
-
|
|
111
|
+
mcp: mcp,
|
|
108
112
|
config: run_config
|
|
109
113
|
)
|
|
110
114
|
end
|
|
@@ -116,20 +120,22 @@ module AIA
|
|
|
116
120
|
# @param namer [RobotNamer]
|
|
117
121
|
# @param server_groups [Array<Array<Hash>>]
|
|
118
122
|
# @return [RobotLab::Network]
|
|
123
|
+
# :reek:TooManyStatements -- gathers shared robot inputs, declares one task per server group plus the synthesizer
|
|
119
124
|
def build_concurrent_mcp_network(config, namer, server_groups)
|
|
120
125
|
run_config = RobotFactory.build_run_config(config)
|
|
121
126
|
tools = ToolLoader.filtered_tools(config)
|
|
122
127
|
model_spec = config.models.first
|
|
123
128
|
system_prompt = SystemPromptAssembler.resolve_system_prompt(config, model_spec)
|
|
129
|
+
group_servers = server_groups.map { RobotFactory.mcp_servers(config, it) }
|
|
124
130
|
|
|
125
131
|
network = RobotLab.create_network(name: "aia-concurrent-mcp") do
|
|
126
|
-
|
|
132
|
+
group_servers.each_with_index do |servers, i|
|
|
127
133
|
robot = RobotFactory.build_robot(
|
|
128
134
|
model_spec,
|
|
129
135
|
name: "#{namer.name_for(model_spec.name)}-w#{i}",
|
|
130
136
|
system_prompt: system_prompt,
|
|
131
137
|
local_tools: tools,
|
|
132
|
-
|
|
138
|
+
mcp: servers,
|
|
133
139
|
config: run_config
|
|
134
140
|
)
|
|
135
141
|
task :"mcp_worker_#{i}", robot, depends_on: :none
|
|
@@ -16,12 +16,12 @@ module AIA
|
|
|
16
16
|
def initialize_memory(network, config)
|
|
17
17
|
return network unless network.respond_to?(:memory)
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
data = network.memory.data
|
|
20
|
+
data.session_id = SecureRandom.hex(8)
|
|
21
|
+
data.model_count = config.models.size
|
|
22
|
+
data.model_names = config.models.map(&:name)
|
|
23
|
+
data.mode = config.flags.consensus ? :consensus : :parallel
|
|
24
|
+
data.turn_count = 0
|
|
25
25
|
|
|
26
26
|
network
|
|
27
27
|
end
|
|
@@ -20,8 +20,9 @@
|
|
|
20
20
|
# ruby_llm's own private parse_error_from_json. Guarded against API drift: if
|
|
21
21
|
# parse_error_from_json is renamed/removed the patch is skipped with a warning.
|
|
22
22
|
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
23
|
+
# ruby_llm >= 2.0 moved the module to RubyLLM::Protocol::Streaming and fixed
|
|
24
|
+
# the bug upstream (nil-safe data-line access plus SSE event buffering), so on
|
|
25
|
+
# 2.0+ this patch deliberately does not apply. It stays for the 1.x line only.
|
|
25
26
|
|
|
26
27
|
module AIA
|
|
27
28
|
module RubyLLMStreamingError
|
|
@@ -35,8 +36,24 @@ module AIA
|
|
|
35
36
|
end
|
|
36
37
|
end
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
# ruby_llm is Zeitwerk-managed, so the constants must be referenced (not
|
|
40
|
+
# defined?-probed) to trigger their autoload; NameError means "not this version".
|
|
41
|
+
streaming =
|
|
42
|
+
begin
|
|
43
|
+
RubyLLM::Streaming # ruby_llm 1.x
|
|
44
|
+
rescue NameError
|
|
45
|
+
nil
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
if streaming.nil?
|
|
49
|
+
begin
|
|
50
|
+
RubyLLM::Protocol::Streaming # ruby_llm >= 2.0: fixed upstream, no patch needed
|
|
51
|
+
rescue NameError
|
|
52
|
+
$stderr.puts "WARNING: [AIA] ruby_llm patch skipped: no streaming module found " \
|
|
53
|
+
"(ruby_llm #{RubyLLM::VERSION}). Streaming error messages may be cryptic."
|
|
54
|
+
end
|
|
55
|
+
elsif streaming.private_method_defined?(:parse_error_from_json)
|
|
56
|
+
streaming.prepend(AIA::RubyLLMStreamingError)
|
|
40
57
|
else
|
|
41
58
|
$stderr.puts "WARNING: [AIA] ruby_llm patch skipped: RubyLLM::Streaming#parse_error_from_json " \
|
|
42
59
|
"not found (ruby_llm #{RubyLLM::VERSION}). Streaming error messages may be cryptic."
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# lib/aia/patches/ruby_llm_tool_param_compat.rb
|
|
2
|
+
#
|
|
3
|
+
# ruby_llm 1.x tools declare arguments with `param ... desc:`; ruby_llm 2.0
|
|
4
|
+
# renamed the DSL to `parameter ... description:`. AIA's tool classes are
|
|
5
|
+
# written in the 2.0 style. On a 1.x runtime this shim translates the 2.0
|
|
6
|
+
# declaration back onto the 1.x `param` DSL so the same tool classes load on
|
|
7
|
+
# both lines. Retire together with ruby_llm 1.x support.
|
|
8
|
+
|
|
9
|
+
module AIA
|
|
10
|
+
module RubyLLMToolParamCompat
|
|
11
|
+
def parameter(name, **options)
|
|
12
|
+
options[:desc] = options.delete(:description) if options.key?(:description)
|
|
13
|
+
param(name, **options)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
RubyLLM::Tool.extend(AIA::RubyLLMToolParamCompat) unless RubyLLM::Tool.respond_to?(:parameter)
|