aia 1.1.1 → 2.0.0.0.pre.alpha

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.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +5 -1
  3. data/.loki +231 -0
  4. data/.quality/flay_baseline.txt +1 -0
  5. data/.quality/flog_baseline.txt +29 -0
  6. data/.quality/reek_baseline.txt +80 -0
  7. data/.rubocop.yml +116 -0
  8. data/.version +1 -1
  9. data/CHANGELOG.md +259 -50
  10. data/IMPLEMENTATION_PLAN.md +506 -0
  11. data/README.md +266 -238
  12. data/Rakefile +118 -5
  13. data/architecture_review.md +314 -0
  14. data/bin/aia +16 -0
  15. data/docs/AGENTS.md +40 -0
  16. data/docs/advanced-prompting.md +67 -3
  17. data/docs/cli-reference.md +312 -56
  18. data/docs/configuration.md +130 -19
  19. data/docs/contributing.md +56 -2
  20. data/docs/directives-reference.md +593 -78
  21. data/docs/faq.md +85 -3
  22. data/docs/guides/available-models.md +1 -1
  23. data/docs/guides/basic-usage.md +6 -6
  24. data/docs/guides/chat.md +40 -16
  25. data/docs/guides/crew.md +239 -0
  26. data/docs/guides/executable-prompts.md +1 -1
  27. data/docs/guides/index.md +1 -0
  28. data/docs/guides/models.md +15 -0
  29. data/docs/index.md +29 -2
  30. data/docs/installation.md +44 -17
  31. data/docs/mcp-integration.md +40 -0
  32. data/docs/prompt_management.md +85 -86
  33. data/docs/security.md +47 -0
  34. data/docs/special_projects_guide.md +386 -0
  35. data/docs/tools-and-mcp-examples.md +23 -0
  36. data/docs/workflows-and-pipelines.md +84 -7
  37. data/examples/.gitignore +1 -0
  38. data/examples/00_setup_aia.sh +27 -44
  39. data/examples/11_multi_model.sh +4 -14
  40. data/examples/12_token_usage.sh +3 -12
  41. data/examples/18_tools.sh +10 -2
  42. data/examples/22_chat_mode.sh +0 -10
  43. data/examples/23_verify.sh +139 -0
  44. data/examples/24_decompose.sh +139 -0
  45. data/examples/25_spawn.sh +139 -0
  46. data/examples/26_debate.sh +97 -0
  47. data/examples/27_mention_routing.sh +157 -0
  48. data/examples/28_model_switching.sh +106 -0
  49. data/examples/29_agent_harness.sh +177 -0
  50. data/examples/README.md +65 -0
  51. data/examples/advanced_multi_robot_capabilities_without_examples.md +106 -0
  52. data/examples/aia_config.yml +1 -1
  53. data/examples/aia_config_orchestrator.yml +45 -0
  54. data/examples/common.sh +18 -6
  55. data/examples/context/tech_stack.md +2 -2
  56. data/examples/prompts_dir/roles/orchestrator.md +21 -0
  57. data/examples/requirements/sinatra_taskflow_app.md +139 -0
  58. data/examples/rules/01_classify_ruby.rb +16 -0
  59. data/examples/rules/02_prefer_claude_for_code.rb +19 -0
  60. data/examples/rules/03_gate_prompt_length.rb +19 -0
  61. data/examples/rules/04_tool_selection.rb +41 -0
  62. data/examples/rules/README.md +30 -0
  63. data/examples/run_all.sh +48 -15
  64. data/examples/tools/word_count_tool.rb +1 -1
  65. data/lib/AGENTS.md +57 -0
  66. data/lib/aia/chat_loop.rb +304 -164
  67. data/lib/aia/config/cli_parser.rb +174 -111
  68. data/lib/aia/config/defaults.yml +62 -33
  69. data/lib/aia/config/mcp_parser.rb +39 -46
  70. data/lib/aia/config/model_spec.rb +34 -2
  71. data/lib/aia/config/validator.rb +108 -142
  72. data/lib/aia/config.rb +110 -145
  73. data/lib/aia/content_extractor.rb +153 -0
  74. data/lib/aia/cost_calculator.rb +38 -0
  75. data/lib/aia/crew.rb +164 -0
  76. data/lib/aia/debate_handler.rb +166 -0
  77. data/lib/aia/delegate_handler.rb +112 -0
  78. data/lib/aia/directive.rb +33 -18
  79. data/lib/aia/directive_processor.rb +16 -7
  80. data/lib/aia/directives/configuration_directives.rb +160 -20
  81. data/lib/aia/directives/context_directives.rb +38 -26
  82. data/lib/aia/directives/execution_directives.rb +136 -4
  83. data/lib/aia/directives/model_directives.rb +76 -34
  84. data/lib/aia/directives/trakflow_directives.rb +44 -0
  85. data/lib/aia/directives/utility_directives.rb +203 -6
  86. data/lib/aia/directives/web_and_file_directives.rb +96 -60
  87. data/lib/aia/errors.rb +15 -0
  88. data/lib/aia/fact_asserter.rb +27 -0
  89. data/lib/aia/fzf.rb +9 -31
  90. data/lib/aia/handler_context.rb +17 -0
  91. data/lib/aia/handler_protocol.rb +19 -0
  92. data/lib/aia/history_transfer.rb +55 -0
  93. data/lib/aia/input_collector.rb +3 -3
  94. data/lib/aia/layered_orchestrator.rb +448 -0
  95. data/lib/aia/logger.rb +24 -4
  96. data/lib/aia/mcp_config_normalizer.rb +35 -0
  97. data/lib/aia/mcp_connection_manager.rb +305 -0
  98. data/lib/aia/mcp_discovery.rb +44 -0
  99. data/lib/aia/mcp_grouper.rb +33 -0
  100. data/lib/aia/mcp_utility.rb +57 -0
  101. data/lib/aia/mention_router.rb +260 -0
  102. data/lib/aia/model_alias_registry.rb +97 -0
  103. data/lib/aia/model_switch_handler.rb +100 -0
  104. data/lib/aia/network_builder.rb +155 -0
  105. data/lib/aia/network_memory_manager.rb +55 -0
  106. data/lib/aia/patches/ruby_llm_streaming_error.rb +43 -0
  107. data/lib/aia/patches/ruby_llm_tool_error.rb +96 -0
  108. data/lib/aia/pipeline_orchestrator.rb +262 -0
  109. data/lib/aia/plugin_loader.rb +170 -0
  110. data/lib/aia/plugin_monitor.rb +208 -0
  111. data/lib/aia/prompt_decomposer.rb +157 -0
  112. data/lib/aia/prompt_handler.rb +19 -39
  113. data/lib/aia/robot_builder.rb +51 -0
  114. data/lib/aia/robot_factory.rb +334 -0
  115. data/lib/aia/robot_namer.rb +116 -0
  116. data/lib/aia/session.rb +83 -17
  117. data/lib/aia/session_tracker.rb +209 -0
  118. data/lib/aia/similarity_scorer.rb +39 -0
  119. data/lib/aia/skill_utils.rb +105 -1
  120. data/lib/aia/spawn_handler.rb +129 -0
  121. data/lib/aia/spawn_spec_parser.rb +65 -0
  122. data/lib/aia/special_mode_handler.rb +302 -0
  123. data/lib/aia/startup_coordinator.rb +150 -0
  124. data/lib/aia/streaming_runner.rb +169 -0
  125. data/lib/aia/system_prompt_assembler.rb +88 -0
  126. data/lib/aia/task_coordinator.rb +202 -0
  127. data/lib/aia/task_decomposer.rb +57 -0
  128. data/lib/aia/task_executor.rb +51 -0
  129. data/lib/aia/tfidf_math.rb +27 -0
  130. data/lib/aia/tool_filter/tfidf.rb +116 -0
  131. data/lib/aia/tool_filter/wordnet_expander.rb +127 -0
  132. data/lib/aia/tool_filter.rb +82 -0
  133. data/lib/aia/tool_filter_registry.rb +30 -0
  134. data/lib/aia/tool_filter_strategy.rb +143 -0
  135. data/lib/aia/tool_loader.rb +210 -0
  136. data/lib/aia/tool_utility.rb +30 -0
  137. data/lib/aia/tools/delegate_to_foreman_tool.rb +70 -0
  138. data/lib/aia/tools/recruit_robot_tool.rb +60 -0
  139. data/lib/aia/tools/reskill_robot_tool.rb +44 -0
  140. data/lib/aia/tools/task_board_tool.rb +114 -0
  141. data/lib/aia/trakflow_bridge.rb +173 -0
  142. data/lib/aia/turn_state.rb +94 -0
  143. data/lib/aia/ui_presenter.rb +166 -198
  144. data/lib/aia/utility.rb +134 -87
  145. data/lib/aia/{history_manager.rb → variable_input_collector.rb} +8 -9
  146. data/lib/aia/verification_network.rb +58 -0
  147. data/lib/aia.rb +108 -63
  148. data/mkdocs.yml +1 -0
  149. metadata +179 -56
  150. data/justfile +0 -215
  151. data/lib/aia/adapter/chat_execution.rb +0 -242
  152. data/lib/aia/adapter/error_handler.rb +0 -68
  153. data/lib/aia/adapter/gem_activator.rb +0 -57
  154. data/lib/aia/adapter/mcp_connector.rb +0 -274
  155. data/lib/aia/adapter/modality_handlers.rb +0 -167
  156. data/lib/aia/adapter/model_registry.rb +0 -81
  157. data/lib/aia/adapter/multi_model_chat.rb +0 -218
  158. data/lib/aia/adapter/provider_configurator.rb +0 -59
  159. data/lib/aia/adapter/tool_filter.rb +0 -85
  160. data/lib/aia/adapter/tool_loader.rb +0 -90
  161. data/lib/aia/chat_processor_service.rb +0 -178
  162. data/lib/aia/prompt_pipeline.rb +0 -183
  163. data/lib/aia/ruby_llm_adapter.rb +0 -95
  164. data/lib/extensions/openstruct_merge.rb +0 -48
  165. data/lib/extensions/ruby_llm/.irbrc +0 -56
  166. data/lib/extensions/ruby_llm/modalities.rb +0 -36
  167. data/lib/extensions/ruby_llm/provider_fix.rb +0 -79
  168. data/lib/refinements/string.rb +0 -16
  169. data/main.just +0 -76
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env bash
2
+ # examples/25_spawn.sh
3
+ #
4
+ # Demonstrates /spawn mode: SpawnHandler.
5
+ #
6
+ # Dynamically creates a specialist robot on demand. You can name
7
+ # the specialist type (/spawn ruby-expert) or let AIA auto-detect
8
+ # from the content of your next prompt (/spawn with no args).
9
+ # Spawned specialists are cached and reused within the session.
10
+ #
11
+ # How it works in chat:
12
+ # 1. Type /spawn [optional type] → AIA sets spawn mode
13
+ # 2. Type your question → specialist robot answers
14
+ #
15
+ # Prerequisites: Run 00_setup_aia.sh first
16
+ # Usage: cd examples && bash 25_spawn.sh
17
+
18
+ set -euo pipefail
19
+ source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
20
+
21
+ if ! command -v expect &>/dev/null; then
22
+ echo "ERROR: expect is not installed."
23
+ echo " Install with: brew install expect"
24
+ exit 1
25
+ fi
26
+
27
+ echo "=== Demo 25: Spawn Mode (SpawnHandler) ==="
28
+ echo
29
+ echo "The /spawn directive creates a specialist robot to answer"
30
+ echo "a domain-specific question. Specialists are cached for the"
31
+ echo "session so repeated questions in the same domain reuse the"
32
+ echo "same specialist robot."
33
+ echo
34
+ echo "Directive mechanics: /spawn [type] sets the mode for the NEXT"
35
+ echo "prompt. Named type: /spawn security-expert. Auto-detect: /spawn"
36
+ echo
37
+
38
+ # --- Part 1: Explicit specialist type ---
39
+
40
+ echo "--- Part 1: Explicit specialist (/spawn security-expert) ---"
41
+ echo
42
+ echo "We'll explicitly request a security expert to review a"
43
+ echo "common code vulnerability pattern."
44
+ echo
45
+ echo "Running: aia -c ${CONFIG} --chat"
46
+ echo
47
+
48
+ expect <<'EXPECT_SCRIPT'
49
+ set timeout 300
50
+ log_user 1
51
+
52
+ spawn aia -c aia_config.yml --chat
53
+
54
+ expect {
55
+ "#=> " {}
56
+ timeout { puts "\n*** Timed out waiting for chat prompt ***"; exit 1 }
57
+ }
58
+
59
+ send "/spawn security-expert\r"
60
+
61
+ expect {
62
+ "#=> " {}
63
+ timeout { puts "\n*** Timed out waiting for directive confirmation ***"; exit 1 }
64
+ }
65
+
66
+ send "What are the top 3 SQL injection prevention techniques and how does parameterized query binding work?\r"
67
+
68
+ expect {
69
+ "#=> " {}
70
+ timeout { puts "\n*** Timed out waiting for specialist response ***"; exit 1 }
71
+ }
72
+
73
+ send "exit\r"
74
+ expect eof
75
+ EXPECT_SCRIPT
76
+
77
+ drain_terminal
78
+ echo
79
+ echo
80
+
81
+ # --- Part 2: Auto-detect specialist ---
82
+
83
+ echo "--- Part 2: Auto-detect specialist (/spawn with no args) ---"
84
+ echo
85
+ echo "Without a type, AIA asks the primary robot to determine what"
86
+ echo "kind of specialist would best answer the next question."
87
+ echo "The primary robot chooses the role and writes the specialist's"
88
+ echo "system prompt automatically."
89
+ echo
90
+ echo "Running: aia -c ${CONFIG} --chat"
91
+ echo
92
+
93
+ expect <<'EXPECT_SCRIPT'
94
+ set timeout 300
95
+ log_user 1
96
+
97
+ spawn aia -c aia_config.yml --chat
98
+
99
+ expect {
100
+ "#=> " {}
101
+ timeout { puts "\n*** Timed out waiting for chat prompt ***"; exit 1 }
102
+ }
103
+
104
+ send "/spawn\r"
105
+
106
+ expect {
107
+ "#=> " {}
108
+ timeout { puts "\n*** Timed out waiting for directive confirmation ***"; exit 1 }
109
+ }
110
+
111
+ send "What database indexing strategies should I consider for a write-heavy time-series workload in PostgreSQL?\r"
112
+
113
+ expect {
114
+ "#=> " {}
115
+ timeout { puts "\n*** Timed out waiting for specialist response ***"; exit 1 }
116
+ }
117
+
118
+ send "exit\r"
119
+ expect eof
120
+ EXPECT_SCRIPT
121
+
122
+ drain_terminal
123
+ echo
124
+ echo
125
+
126
+ # --- Part 3: Your turn ---
127
+
128
+ echo "--- Part 3: Your turn ---"
129
+ echo
130
+ echo "Try /spawn ruby-expert, /spawn data-scientist, /spawn devops,"
131
+ echo "or just /spawn and let AIA decide. Ask domain-specific questions"
132
+ echo "that benefit from a focused specialist perspective."
133
+ echo
134
+
135
+ if [[ "${BATCH_MODE:-}" == "true" ]]; then
136
+ echo "(Skipping interactive session in batch mode)"
137
+ else
138
+ aia -c "${CONFIG}" --chat
139
+ fi
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env bash
2
+ # examples/26_debate_fixed.sh
3
+ #
4
+ # Fixed version of the debate demonstration script
5
+ #
6
+ # Demonstrates /debate mode: DebateHandler.
7
+ #
8
+ # Two robots debate a topic across multiple rounds. Each round,
9
+ # every robot responds to the previous arguments. Stops when any
10
+ # robot says CONVERGED or after 5 rounds. Uses SimilarityScorer
11
+ # to also detect convergence when responses become too similar.
12
+ #
13
+ # Requires a 2-model network (-m MODEL_A,MODEL_B).
14
+
15
+ set -euo pipefail
16
+ source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
17
+
18
+ if ! command -v expect &>/dev/null; then
19
+ echo "ERROR: expect is not installed."
20
+ echo " Install with: brew install expect"
21
+ exit 1
22
+ fi
23
+
24
+ MODEL_A="gpt-4.1"
25
+ MODEL_B="gpt-4.1-mini"
26
+
27
+ echo "=== Demo 26: Debate Mode (DebateHandler) ==="
28
+ echo
29
+ echo "The /debate directive pits two robots against each other in"
30
+ echo "a structured multi-round debate. Each robot sees what the"
31
+ echo "other said in the previous round and responds. The debate"
32
+ echo "ends when a robot says CONVERGED or after 5 rounds."
33
+ echo
34
+ echo "Using models: ${MODEL_A} vs ${MODEL_B}"
35
+ echo "Robot names: Tobor (gpt-4.1) and Vanguard (gpt-4.1-mini)"
36
+ echo
37
+
38
+ # --- Part 1: A technical debate ---
39
+
40
+ echo "--- Part 1: Technical debate ---"
41
+ echo
42
+ echo "Both models will debate the best approach to API design."
43
+ echo "Watch how their positions evolve across rounds."
44
+ echo
45
+ echo "Running: aia -c ${CONFIG} -m ${MODEL_A},${MODEL_B} --chat"
46
+ echo
47
+
48
+ # Create the expect script with proper variable substitution
49
+ expect -c "
50
+ set timeout 600
51
+ log_user 1
52
+
53
+ spawn aia -c ${CONFIG} -m ${MODEL_A},${MODEL_B} --chat
54
+
55
+ expect {
56
+ \"#=> \" {}
57
+ timeout { puts \"\n*** Timed out waiting for chat prompt ***\"; exit 1 }
58
+ }
59
+
60
+ send \"/debate\r\"
61
+
62
+ expect {
63
+ \"#=> \" {}
64
+ timeout { puts \"\n*** Timed out waiting for directive confirmation ***\"; exit 1 }
65
+ }
66
+
67
+ send \"REST vs GraphQL: which is the better default choice for a new web API in 2025, and why?\r\"
68
+
69
+ expect {
70
+ \"#=> \" {}
71
+ timeout { puts \"\n*** Timed out waiting for debate results ***\"; exit 1 }
72
+ }
73
+
74
+ send \"exit\r\"
75
+ expect eof
76
+ "
77
+
78
+ drain_terminal
79
+ echo
80
+ echo
81
+
82
+ # --- Part 2: Your turn ---
83
+
84
+ echo "--- Part 2: Your turn ---"
85
+ echo
86
+ echo "Try /debate on any topic where two perspectives are valuable:"
87
+ echo "architecture decisions, tradeoffs, design choices, or even"
88
+ echo "open-ended questions where you want multiple viewpoints stress-tested."
89
+ echo
90
+ echo "Running: aia -c ${CONFIG} -m ${MODEL_A},${MODEL_B} --chat"
91
+ echo
92
+
93
+ if [[ "${BATCH_MODE:-}" == "true" ]]; then
94
+ echo "(Skipping interactive session in batch mode)"
95
+ else
96
+ aia -c "${CONFIG}" -m "${MODEL_A},${MODEL_B}" --chat
97
+ fi
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env bash
2
+ # examples/27_mention_routing.sh
3
+ #
4
+ # Demonstrates @mention routing in a multi-model network.
5
+ #
6
+ # In a 2-model chat session, prefix any message with @RobotName
7
+ # to direct it to a specific robot. Only that robot responds.
8
+ # Robot names are assigned by AIA based on the model:
9
+ # gpt-4.1 → Tobor (first robot always gets the name "Tobor")
10
+ # gpt-4.1-mini → Vanguard
11
+ #
12
+ # If the @name is not recognized, AIA lists available robot names.
13
+ #
14
+ # Requires a 2-model network (-m MODEL_A,MODEL_B).
15
+ #
16
+ # Prerequisites: Run 00_setup_aia.sh first (OPENAI_API_KEY must be set).
17
+ # Usage: cd examples && bash 27_mention_routing.sh
18
+
19
+ set -euo pipefail
20
+ source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
21
+
22
+ if ! command -v expect &>/dev/null; then
23
+ echo "ERROR: expect is not installed."
24
+ echo " Install with: brew install expect"
25
+ exit 1
26
+ fi
27
+
28
+ MODEL_A="gpt-4.1"
29
+ MODEL_B="gpt-4.1-mini"
30
+
31
+ echo "=== Demo 27: @mention Routing ==="
32
+ echo
33
+ echo "In a multi-model network, prefix your message with @RobotName"
34
+ echo "to direct it to a specific robot. Only that robot responds."
35
+ echo
36
+ echo "Using models: ${MODEL_A} vs ${MODEL_B}"
37
+ echo "Robot names: Tobor (gpt-4.1) and Vanguard (gpt-4.1-mini)"
38
+ echo
39
+
40
+ # --- Part 1: Route to Tobor (gpt-4.1) ---
41
+
42
+ echo "--- Part 1: Direct a question to @Tobor ---"
43
+ echo
44
+ echo "Running: aia -c ${CONFIG} -m ${MODEL_A},${MODEL_B} --chat"
45
+ echo
46
+
47
+ expect <<'EXPECT_SCRIPT'
48
+ set timeout 180
49
+ log_user 1
50
+
51
+ spawn aia -c aia_config.yml -m gpt-4.1,gpt-4.1-mini --chat
52
+
53
+ expect {
54
+ "#=> " {}
55
+ timeout { puts "\n*** Timed out waiting for chat prompt ***"; exit 1 }
56
+ }
57
+
58
+ send "@Tobor What is your favorite metaphor for explaining recursion?\r"
59
+
60
+ expect {
61
+ "#=> " {}
62
+ timeout { puts "\n*** Timed out waiting for response ***"; exit 1 }
63
+ }
64
+
65
+ send "exit\r"
66
+ expect eof
67
+ EXPECT_SCRIPT
68
+
69
+ drain_terminal
70
+ echo
71
+ echo
72
+
73
+ # --- Part 2: Route to Vanguard (gpt-4.1-mini) ---
74
+
75
+ echo "--- Part 2: Direct a question to @Vanguard ---"
76
+ echo
77
+ echo "Running: aia -c ${CONFIG} -m ${MODEL_A},${MODEL_B} --chat"
78
+ echo
79
+
80
+ expect <<'EXPECT_SCRIPT'
81
+ set timeout 180
82
+ log_user 1
83
+
84
+ spawn aia -c aia_config.yml -m gpt-4.1,gpt-4.1-mini --chat
85
+
86
+ expect {
87
+ "#=> " {}
88
+ timeout { puts "\n*** Timed out waiting for chat prompt ***"; exit 1 }
89
+ }
90
+
91
+ send "@Vanguard Describe the CAP theorem in one sentence.\r"
92
+
93
+ expect {
94
+ "#=> " {}
95
+ timeout { puts "\n*** Timed out waiting for response ***"; exit 1 }
96
+ }
97
+
98
+ send "exit\r"
99
+ expect eof
100
+ EXPECT_SCRIPT
101
+
102
+ drain_terminal
103
+ echo
104
+ echo
105
+
106
+ # --- Part 3: Unknown @mention lists available robots ---
107
+
108
+ echo "--- Part 3: Unknown @mention shows available robots ---"
109
+ echo
110
+ echo "If you @mention a name that doesn't match any robot,"
111
+ echo "AIA lists the available robot names so you can correct it."
112
+ echo
113
+ echo "Running: aia -c ${CONFIG} -m ${MODEL_A},${MODEL_B} --chat"
114
+ echo
115
+
116
+ expect <<'EXPECT_SCRIPT'
117
+ set timeout 60
118
+ log_user 1
119
+
120
+ spawn aia -c aia_config.yml -m gpt-4.1,gpt-4.1-mini --chat
121
+
122
+ expect {
123
+ "#=> " {}
124
+ timeout { puts "\n*** Timed out waiting for chat prompt ***"; exit 1 }
125
+ }
126
+
127
+ send "@nonexistent What is 2 + 2?\r"
128
+
129
+ expect {
130
+ "#=> " {}
131
+ timeout { puts "\n*** Timed out waiting for response ***"; exit 1 }
132
+ }
133
+
134
+ send "exit\r"
135
+ expect eof
136
+ EXPECT_SCRIPT
137
+
138
+ drain_terminal
139
+ echo
140
+ echo
141
+
142
+ # --- Part 4: Mix @mention and normal turns ---
143
+
144
+ echo "--- Part 4: Mix directed and undirected turns ---"
145
+ echo
146
+ echo "In a session you can freely mix @mention turns (one robot)"
147
+ echo "with normal turns (all robots). This shows how to hold a"
148
+ echo "selective conversation across a network."
149
+ echo
150
+ echo "Running: aia -c ${CONFIG} -m ${MODEL_A},${MODEL_B} --chat"
151
+ echo
152
+
153
+ if [[ "${BATCH_MODE:-}" == "true" ]]; then
154
+ echo "(Skipping interactive session in batch mode)"
155
+ else
156
+ aia -c "${CONFIG}" -m "${MODEL_A},${MODEL_B}" --chat
157
+ fi
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env bash
2
+ # examples/28_model_switching.sh
3
+ #
4
+ # Demonstrates /model directive: switching models mid-conversation.
5
+ #
6
+ # The /model directive rebuilds the active robot with a new model
7
+ # while preserving the full conversation history. Context is
8
+ # transferred so the new model can see everything discussed so far.
9
+ #
10
+ # Note: Natural language model switching ("use gpt-4.1-mini instead")
11
+ # is detected by ModelSwitchHandler but currently stubbed. Use
12
+ # /model directly for reliable in-session model changes.
13
+ #
14
+ # Prerequisites:
15
+ # - Run 00_setup_aia.sh first (OPENAI_API_KEY must be set)
16
+ # Usage: cd examples && bash 28_model_switching.sh
17
+
18
+ set -euo pipefail
19
+ source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
20
+
21
+ if ! command -v expect &>/dev/null; then
22
+ echo "ERROR: expect is not installed."
23
+ echo " Install with: brew install expect"
24
+ exit 1
25
+ fi
26
+
27
+ MODEL_A="gpt-4.1"
28
+ MODEL_B="gpt-4.1-mini"
29
+
30
+ echo "=== Demo 28: Model Switching (/model directive) ==="
31
+ echo
32
+ echo "The /model directive switches the active model mid-conversation."
33
+ echo "Conversation history is transferred so the new model has"
34
+ echo "full context of everything discussed before the switch."
35
+ echo
36
+ echo "Starting model: ${MODEL_A}"
37
+ echo "Switch target: ${MODEL_B}"
38
+ echo
39
+
40
+ # --- Part 1: Ask a question, switch models, ask a follow-up ---
41
+
42
+ echo "--- Part 1: Ask a question, switch models, ask a follow-up ---"
43
+ echo
44
+ echo "We'll ask a question with ${MODEL_A}, switch to ${MODEL_B},"
45
+ echo "then ask a follow-up. The second model should reference the"
46
+ echo "first exchange because history is preserved across the switch."
47
+ echo
48
+ echo "Running: aia -c ${CONFIG} --chat"
49
+ echo
50
+
51
+ expect <<'EXPECT_SCRIPT'
52
+ set timeout 180
53
+ log_user 1
54
+
55
+ spawn aia -c aia_config.yml --chat
56
+
57
+ expect {
58
+ "#=> " {}
59
+ timeout { puts "\n*** Timed out waiting for chat prompt ***"; exit 1 }
60
+ }
61
+
62
+ send "Name three key differences between a process and a thread.\r"
63
+
64
+ expect {
65
+ "#=> " {}
66
+ timeout { puts "\n*** Timed out waiting for first response ***"; exit 1 }
67
+ }
68
+
69
+ send "/model gpt-4.1-mini\r"
70
+
71
+ expect {
72
+ "#=> " {}
73
+ timeout { puts "\n*** Timed out waiting for model switch ***"; exit 1 }
74
+ }
75
+
76
+ send "Based on what you just said, which is more appropriate for a CPU-bound image processing pipeline?\r"
77
+
78
+ expect {
79
+ "#=> " {}
80
+ timeout { puts "\n*** Timed out waiting for follow-up response ***"; exit 1 }
81
+ }
82
+
83
+ send "exit\r"
84
+ expect eof
85
+ EXPECT_SCRIPT
86
+
87
+ drain_terminal
88
+ echo
89
+ echo
90
+
91
+ # --- Part 2: Your turn ---
92
+
93
+ echo "--- Part 2: Your turn ---"
94
+ echo
95
+ echo "Use /model <name> any time during a chat to switch models."
96
+ echo "The new model picks up the full conversation history."
97
+ echo "You can switch back and forth as many times as you like."
98
+ echo
99
+ echo "Running: aia -c ${CONFIG} --chat"
100
+ echo
101
+
102
+ if [[ "${BATCH_MODE:-}" == "true" ]]; then
103
+ echo "(Skipping interactive session in batch mode)"
104
+ else
105
+ aia -c "${CONFIG}" --chat
106
+ fi
@@ -0,0 +1,177 @@
1
+ #!/usr/bin/env bash
2
+ # examples/29_agent_harness.sh
3
+ #
4
+ # Demonstrates AIA as a full agent harness using 3-tier layered orchestration.
5
+ #
6
+ # A complete application requirements document is fed to the /orchestrate
7
+ # directive. AIA runs a three-tier execution:
8
+ #
9
+ # Tier 1 — Tobor (orchestrator)
10
+ # Reads the full requirements and decomposes them into independent
11
+ # architectural layers (e.g. Infrastructure, Data Models, Auth, Routes, Views).
12
+ #
13
+ # Tier 2 — Lead agents (one per layer)
14
+ # Each lead agent receives its layer's requirements and further decomposes
15
+ # them into specific implementation tasks, assigning a specialist type to
16
+ # each task (e.g. sequel-migration-writer, sinatra-route-builder).
17
+ #
18
+ # Tier 3 — Specialist robots (one per task)
19
+ # Each specialist receives a focused, concrete task and produces an actual
20
+ # implementation artifact: a code file, migration, route handler, or spec.
21
+ #
22
+ # Synthesis
23
+ # Each lead agent synthesizes its layer's artifacts into a summary.
24
+ # Tobor then synthesizes all layer summaries into a final integration report.
25
+ #
26
+ # The application being built: TaskFlow — a multi-user project and task
27
+ # management web app using Ruby, Sinatra, Sequel (SQLite), and ERB templates.
28
+ # Full requirements: examples/requirements/sinatra_taskflow_app.md
29
+ #
30
+ # Prerequisites: Run 00_setup_aia.sh first (OPENAI_API_KEY must be set)
31
+ # Requires: expect (brew install expect)
32
+ # Usage: cd examples && bash 29_agent_harness.sh
33
+
34
+ set -euo pipefail
35
+ source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
36
+
37
+ if ! command -v expect &>/dev/null; then
38
+ echo "ERROR: expect is not installed."
39
+ echo " Install with: brew install expect"
40
+ exit 1
41
+ fi
42
+
43
+ MODEL_A="gpt-4.1"
44
+ MODEL_B="gpt-4.1-mini"
45
+ ORCH_CONFIG="aia_config_orchestrator.yml"
46
+ REQUIREMENTS="requirements/sinatra_taskflow_app.md"
47
+
48
+ echo "=== Demo 29: AIA Agent Harness — 3-Tier Layered Orchestration ==="
49
+ echo
50
+ echo "Application being built:"
51
+ echo " TaskFlow — a multi-user project and task management web app"
52
+ echo " Stack: Ruby + Sinatra + Sequel (SQLite) + ERB + Bootstrap 5"
53
+ echo
54
+ echo "Execution model:"
55
+ echo " Tier 1 Tobor (orchestrator) decomposes requirements into layers"
56
+ echo " Tier 2 One lead agent per layer decomposes into specialist tasks"
57
+ echo " Tier 3 One specialist per task produces the implementation artifact"
58
+ echo
59
+
60
+ if [[ ! -f "${REQUIREMENTS}" ]]; then
61
+ echo "ERROR: Requirements file not found: ${REQUIREMENTS}"
62
+ echo " Expected at: examples/requirements/sinatra_taskflow_app.md"
63
+ exit 1
64
+ fi
65
+
66
+ # --- Orchestration run ---
67
+
68
+ echo "--- Orchestrated build: /orchestrate ---"
69
+ echo
70
+ echo "The directive /orchestrate enables 3-tier mode for the next prompt."
71
+ echo "The next message is the full application requirements document."
72
+ echo "AIA will:"
73
+ echo " 1. Decompose requirements into architectural layers"
74
+ echo " 2. Spawn a lead agent for each layer"
75
+ echo " 3. Have each lead spawn specialists for its tasks"
76
+ echo " 4. Collect artifacts and synthesize across all layers"
77
+ echo
78
+ echo "Requirements document: ${REQUIREMENTS}"
79
+ echo "Running: aia -c ${ORCH_CONFIG} -m ${MODEL_A},${MODEL_B} --chat"
80
+ echo
81
+ echo "Note: This demonstration runs 3+ tiers of agents in sequence."
82
+ echo " Each layer spawns 2-4 specialists. Allow 10-20 minutes"
83
+ echo " depending on OpenAI API response times."
84
+ echo
85
+
86
+ REQUIREMENTS_CONTENT=$(cat "${REQUIREMENTS}")
87
+
88
+ expect <<EXPECT_SCRIPT
89
+ set timeout 1800
90
+ log_user 1
91
+
92
+ spawn aia -c aia_config_orchestrator.yml -m gpt-4.1,gpt-4.1-mini --chat
93
+
94
+ expect {
95
+ "#=> " {}
96
+ timeout { puts "\n*** Timed out waiting for chat prompt ***"; exit 1 }
97
+ }
98
+
99
+ send "/orchestrate\r"
100
+
101
+ expect {
102
+ "#=> " {}
103
+ timeout { puts "\n*** Timed out waiting for directive confirmation ***"; exit 1 }
104
+ }
105
+
106
+ send {${REQUIREMENTS_CONTENT}}
107
+ send "\r"
108
+
109
+ expect {
110
+ "#=> " {}
111
+ timeout { puts "\n*** Timed out waiting for orchestration to complete ***"; exit 1 }
112
+ }
113
+
114
+ send "exit\r"
115
+ expect eof
116
+ EXPECT_SCRIPT
117
+
118
+ drain_terminal
119
+ echo
120
+ echo
121
+
122
+ # --- Show what was built ---
123
+
124
+ echo "--- Generated application files ---"
125
+ echo
126
+
127
+ BUILD_DIR=$(ls -dt orchestrated_build_* 2>/dev/null | head -1)
128
+
129
+ if [[ -z "${BUILD_DIR}" ]]; then
130
+ echo "No build directory found. The orchestration may not have completed."
131
+ else
132
+ echo "Build directory: ${BUILD_DIR}"
133
+ echo
134
+ echo "Files produced by the agent team:"
135
+ find "${BUILD_DIR}" -type f | sort | grep -v INTEGRATION_REPORT.md | while read -r f; do
136
+ rel="${f#${BUILD_DIR}/}"
137
+ lines=$(wc -l < "${f}" 2>/dev/null | tr -d ' ' || echo "?")
138
+ printf " %-50s (%s lines)\n" "${rel}" "${lines}"
139
+ done
140
+ echo
141
+ REPORT="${BUILD_DIR}/INTEGRATION_REPORT.md"
142
+ if [[ -f "${REPORT}" ]]; then
143
+ echo "--- INTEGRATION_REPORT.md ---"
144
+ echo
145
+ cat "${REPORT}"
146
+ echo
147
+ fi
148
+
149
+ # Show a sample generated file (first non-report Ruby file found)
150
+ SAMPLE=$(find "${BUILD_DIR}" -type f -name "*.rb" | sort | head -1)
151
+ if [[ -n "${SAMPLE}" ]]; then
152
+ echo "--- Sample artifact: ${SAMPLE#${BUILD_DIR}/} ---"
153
+ echo
154
+ cat "${SAMPLE}"
155
+ echo
156
+ fi
157
+ fi
158
+
159
+ # --- Interactive session ---
160
+
161
+ echo "--- Interactive orchestration session ---"
162
+ echo
163
+ echo "The same session is now open for you to:"
164
+ echo " /orchestrate run 3-tier orchestration on any requirements prompt"
165
+ echo " /spawn <type> create a specialist lead agent for a focused task"
166
+ echo " /decompose parallel workstreams for multi-part questions"
167
+ echo " @Tobor address the orchestrator directly"
168
+ echo " @Quark address the specialist network robot directly"
169
+ echo
170
+ echo "Running: aia -c ${ORCH_CONFIG} -m ${MODEL_A},${MODEL_B} --chat"
171
+ echo
172
+
173
+ if [[ "${BATCH_MODE:-}" == "true" ]]; then
174
+ echo "(Skipping interactive session in batch mode)"
175
+ else
176
+ aia -c "${ORCH_CONFIG}" -m "${MODEL_A},${MODEL_B}" --chat
177
+ fi