agentic 0.1.0 → 0.2.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/.agentic.yml +2 -0
- data/.architecture/decisions/ArchitecturalFeatureBuilder.md +136 -0
- data/.architecture/decisions/ArchitectureConsiderations.md +200 -0
- data/.architecture/decisions/adr_001_observer_pattern_implementation.md +196 -0
- data/.architecture/decisions/adr_002_plan_orchestrator.md +320 -0
- data/.architecture/decisions/adr_003_plan_orchestrator_interface.md +179 -0
- data/.architecture/decisions/adrs/ADR-001-dependency-management.md +147 -0
- data/.architecture/decisions/adrs/ADR-002-system-boundaries.md +162 -0
- data/.architecture/decisions/adrs/ADR-003-content-safety.md +158 -0
- data/.architecture/decisions/adrs/ADR-004-agent-permissions.md +161 -0
- data/.architecture/decisions/adrs/ADR-005-adaptation-engine.md +127 -0
- data/.architecture/decisions/adrs/ADR-006-extension-system.md +273 -0
- data/.architecture/decisions/adrs/ADR-007-learning-system.md +156 -0
- data/.architecture/decisions/adrs/ADR-008-prompt-generation.md +325 -0
- data/.architecture/decisions/adrs/ADR-009-task-failure-handling.md +353 -0
- data/.architecture/decisions/adrs/ADR-010-task-input-handling.md +251 -0
- data/.architecture/decisions/adrs/ADR-011-task-observable-pattern.md +391 -0
- data/.architecture/decisions/adrs/ADR-012-task-output-handling.md +205 -0
- data/.architecture/decisions/adrs/ADR-013-architecture-alignment.md +211 -0
- data/.architecture/decisions/adrs/ADR-014-agent-capability-registry.md +80 -0
- data/.architecture/decisions/adrs/ADR-015-persistent-agent-store.md +100 -0
- data/.architecture/decisions/adrs/ADR-016-agent-assembly-engine.md +117 -0
- data/.architecture/decisions/adrs/ADR-017-streaming-observability.md +171 -0
- data/.architecture/decisions/capability_tools_distinction.md +150 -0
- data/.architecture/decisions/cli_command_structure.md +61 -0
- data/.architecture/implementation/agent_self_assembly_implementation.md +267 -0
- data/.architecture/implementation/agent_self_assembly_summary.md +138 -0
- data/.architecture/members.yml +187 -0
- data/.architecture/planning/self_implementation_exercise.md +295 -0
- data/.architecture/planning/session_compaction_rule.md +43 -0
- data/.architecture/planning/streaming_observability_feature.md +223 -0
- data/.architecture/principles.md +151 -0
- data/.architecture/recalibration/0-2-0.md +92 -0
- data/.architecture/recalibration/agent_self_assembly.md +238 -0
- data/.architecture/recalibration/cli_command_structure.md +91 -0
- data/.architecture/recalibration/implementation_roadmap_0-2-0.md +301 -0
- data/.architecture/recalibration/progress_tracking_0-2-0.md +114 -0
- data/.architecture/recalibration_process.md +127 -0
- data/.architecture/reviews/0-2-0.md +181 -0
- data/.architecture/reviews/cli_command_duplication.md +98 -0
- data/.architecture/templates/adr.md +105 -0
- data/.architecture/templates/implementation_roadmap.md +125 -0
- data/.architecture/templates/progress_tracking.md +89 -0
- data/.architecture/templates/recalibration_plan.md +70 -0
- data/.architecture/templates/version_comparison.md +124 -0
- data/.claude/settings.local.json +13 -0
- data/.claude-sessions/001-task-class-architecture-implementation.md +129 -0
- data/.claude-sessions/002-plan-orchestrator-interface-review.md +105 -0
- data/.claude-sessions/architecture-governance-implementation.md +37 -0
- data/.claude-sessions/architecture-review-session.md +27 -0
- data/ArchitecturalFeatureBuilder.md +136 -0
- data/ArchitectureConsiderations.md +229 -0
- data/CHANGELOG.md +57 -2
- data/CLAUDE.md +111 -0
- data/CONTRIBUTING.md +286 -0
- data/MAINTAINING.md +301 -0
- data/README.md +582 -28
- data/docs/agent_capabilities_api.md +259 -0
- data/docs/artifact_extension_points.md +757 -0
- data/docs/artifact_generation_architecture.md +323 -0
- data/docs/artifact_implementation_plan.md +596 -0
- data/docs/artifact_integration_points.md +345 -0
- data/docs/artifact_verification_strategies.md +581 -0
- data/docs/streaming_observability_architecture.md +510 -0
- data/exe/agentic +6 -1
- data/lefthook.yml +5 -0
- data/lib/agentic/adaptation_engine.rb +124 -0
- data/lib/agentic/agent.rb +181 -4
- data/lib/agentic/agent_assembly_engine.rb +442 -0
- data/lib/agentic/agent_capability_registry.rb +260 -0
- data/lib/agentic/agent_config.rb +63 -0
- data/lib/agentic/agent_specification.rb +46 -0
- data/lib/agentic/capabilities/examples.rb +530 -0
- data/lib/agentic/capabilities.rb +14 -0
- data/lib/agentic/capability_provider.rb +146 -0
- data/lib/agentic/capability_specification.rb +118 -0
- data/lib/agentic/cli/agent.rb +31 -0
- data/lib/agentic/cli/capabilities.rb +191 -0
- data/lib/agentic/cli/config.rb +134 -0
- data/lib/agentic/cli/execution_observer.rb +796 -0
- data/lib/agentic/cli.rb +1068 -0
- data/lib/agentic/default_agent_provider.rb +35 -0
- data/lib/agentic/errors/llm_error.rb +184 -0
- data/lib/agentic/execution_plan.rb +53 -0
- data/lib/agentic/execution_result.rb +91 -0
- data/lib/agentic/expected_answer_format.rb +46 -0
- data/lib/agentic/extension/domain_adapter.rb +109 -0
- data/lib/agentic/extension/plugin_manager.rb +163 -0
- data/lib/agentic/extension/protocol_handler.rb +116 -0
- data/lib/agentic/extension.rb +45 -0
- data/lib/agentic/factory_methods.rb +9 -1
- data/lib/agentic/generation_stats.rb +61 -0
- data/lib/agentic/learning/README.md +84 -0
- data/lib/agentic/learning/capability_optimizer.rb +613 -0
- data/lib/agentic/learning/execution_history_store.rb +251 -0
- data/lib/agentic/learning/pattern_recognizer.rb +500 -0
- data/lib/agentic/learning/strategy_optimizer.rb +706 -0
- data/lib/agentic/learning.rb +131 -0
- data/lib/agentic/llm_assisted_composition_strategy.rb +188 -0
- data/lib/agentic/llm_client.rb +215 -15
- data/lib/agentic/llm_config.rb +65 -1
- data/lib/agentic/llm_response.rb +163 -0
- data/lib/agentic/logger.rb +1 -1
- data/lib/agentic/observable.rb +51 -0
- data/lib/agentic/persistent_agent_store.rb +385 -0
- data/lib/agentic/plan_execution_result.rb +129 -0
- data/lib/agentic/plan_orchestrator.rb +464 -0
- data/lib/agentic/plan_orchestrator_config.rb +57 -0
- data/lib/agentic/retry_config.rb +63 -0
- data/lib/agentic/retry_handler.rb +125 -0
- data/lib/agentic/structured_outputs.rb +1 -1
- data/lib/agentic/task.rb +193 -0
- data/lib/agentic/task_definition.rb +39 -0
- data/lib/agentic/task_execution_result.rb +92 -0
- data/lib/agentic/task_failure.rb +66 -0
- data/lib/agentic/task_output_schemas.rb +112 -0
- data/lib/agentic/task_planner.rb +54 -19
- data/lib/agentic/task_result.rb +48 -0
- data/lib/agentic/ui.rb +244 -0
- data/lib/agentic/verification/critic_framework.rb +116 -0
- data/lib/agentic/verification/llm_verification_strategy.rb +60 -0
- data/lib/agentic/verification/schema_verification_strategy.rb +47 -0
- data/lib/agentic/verification/verification_hub.rb +62 -0
- data/lib/agentic/verification/verification_result.rb +50 -0
- data/lib/agentic/verification/verification_strategy.rb +26 -0
- data/lib/agentic/version.rb +1 -1
- data/lib/agentic.rb +74 -2
- data/plugins/README.md +41 -0
- metadata +245 -6
data/README.md
CHANGED
@@ -1,64 +1,618 @@
|
|
1
1
|
# Agentic
|
2
2
|
|
3
|
-
A
|
3
|
+
A Ruby gem for building and running AI agents in a [plan-and-execute](https://blog.langchain.dev/planning-agents/#plan-and-execute) fashion. Agentic provides a simple command-line tool and library to build, manage, deploy, and run purpose-driven AI agents using OpenAI's LLM API.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Install the gem and add to the application's Gemfile by executing:
|
8
8
|
|
9
|
-
|
9
|
+
```bash
|
10
|
+
$ bundle add agentic
|
11
|
+
```
|
10
12
|
|
11
13
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
12
14
|
|
13
|
-
|
15
|
+
```bash
|
16
|
+
$ gem install agentic
|
17
|
+
```
|
14
18
|
|
15
|
-
|
19
|
+
## Usage
|
16
20
|
|
17
|
-
|
21
|
+
### Command-Line Interface
|
18
22
|
|
19
|
-
|
23
|
+
Agentic comes with a rich command-line interface featuring colored output, spinners for long-running tasks, and progress tracking:
|
20
24
|
|
21
|
-
|
25
|
+
```bash
|
26
|
+
# Display version information
|
27
|
+
$ agentic version
|
22
28
|
|
23
|
-
|
29
|
+
# Configuration Management
|
30
|
+
$ agentic config init # Initialize configuration
|
31
|
+
$ agentic config init --global # Initialize global configuration
|
32
|
+
$ agentic config list # List all configuration settings
|
33
|
+
$ agentic config get model # Get a specific configuration value
|
34
|
+
$ agentic config set api_token=your_openai_api_key # Set your OpenAI API token
|
35
|
+
$ agentic config set model=gpt-4o-mini # Configure the default model
|
24
36
|
|
25
|
-
|
37
|
+
# Plan Creation and Execution
|
38
|
+
$ agentic plan "Generate a market research report on AI trends" # Create a plan
|
39
|
+
$ agentic plan "Write a blog post about Ruby" --save plan.json # Save plan to file
|
40
|
+
$ agentic plan "Research quantum computing" --output json # Output in JSON format
|
41
|
+
$ agentic plan "Analyze market trends" --model gpt-4o # Use a specific model
|
26
42
|
|
27
|
-
|
43
|
+
$ agentic execute --plan plan.json # Execute a saved plan
|
44
|
+
$ agentic execute --async # Execute tasks asynchronously
|
45
|
+
$ agentic execute --max-concurrency 5 # Limit concurrent tasks
|
28
46
|
|
29
|
-
|
47
|
+
# Agent Management
|
48
|
+
$ agentic agent list # List available agents
|
49
|
+
$ agentic agent create "ResearchAgent" \ # Create a new agent
|
50
|
+
--role="Research Assistant" \
|
51
|
+
--purpose="Conduct thorough research" \
|
52
|
+
--capabilities=text_generation,web_search
|
53
|
+
$ agentic agent show "ResearchAgent" # Show agent details
|
54
|
+
$ agentic agent build "ResearchAgent" # Build an agent from storage
|
30
55
|
|
31
|
-
|
56
|
+
# Capability Management
|
57
|
+
$ agentic capabilities list # List available capabilities
|
58
|
+
$ agentic capabilities show text_generation # Show capability details
|
59
|
+
$ agentic capabilities search generation # Search for capabilities
|
60
|
+
```
|
32
61
|
|
33
|
-
|
34
|
-
|
35
|
-
|
62
|
+
The CLI provides real-time feedback with spinners for long-running operations, colored status updates, and detailed progress tracking. It supports both global and project-specific configuration, allowing you to customize the behavior for different projects.
|
63
|
+
|
64
|
+
### Programmatic API
|
65
|
+
|
66
|
+
To use Agentic in your Ruby code:
|
67
|
+
|
68
|
+
#### Basic Usage
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
require 'agentic'
|
72
|
+
|
73
|
+
# Configure your OpenAI API key
|
74
|
+
Agentic.configure do |config|
|
75
|
+
config.access_token = 'your_openai_api_key'
|
76
|
+
end
|
77
|
+
|
78
|
+
# Create a TaskPlanner instance with a goal
|
79
|
+
planner = Agentic::TaskPlanner.new("Write a blog post about Ruby on Rails")
|
80
|
+
|
81
|
+
# Generate the plan
|
82
|
+
plan = planner.plan
|
83
|
+
|
84
|
+
# Display the plan
|
85
|
+
puts plan.to_s
|
86
|
+
|
87
|
+
# Or access the structured data
|
88
|
+
plan.tasks.each do |task|
|
89
|
+
puts "Task: #{task.description}"
|
90
|
+
puts "Agent: #{task.agent.name}"
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
#### Working with Agents
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
# Create an agent with specific configuration
|
98
|
+
agent = Agentic::Agent.build do |a|
|
99
|
+
a.name = "ResearchAgent"
|
100
|
+
a.role = "Research Assistant"
|
101
|
+
a.instructions = "Conduct thorough research on the given topic"
|
102
|
+
end
|
103
|
+
|
104
|
+
# Configure the LLM
|
105
|
+
config = Agentic::LlmConfig.new(
|
106
|
+
model: "gpt-4o-mini",
|
107
|
+
temperature: 0.7
|
108
|
+
)
|
109
|
+
|
110
|
+
# Create a task
|
111
|
+
task = Agentic::Task.new(
|
112
|
+
description: "Research the latest trends in Ruby on Rails",
|
113
|
+
agent_spec: {
|
114
|
+
"name" => "ResearchAgent",
|
115
|
+
"description" => "An agent that performs research",
|
116
|
+
"instructions" => "Research the given topic thoroughly"
|
117
|
+
}
|
118
|
+
)
|
119
|
+
|
120
|
+
# Execute the task with the agent
|
121
|
+
result = task.perform(agent)
|
122
|
+
|
123
|
+
# Check the result
|
124
|
+
if result.successful?
|
125
|
+
puts "Task completed successfully!"
|
126
|
+
puts result.output
|
127
|
+
else
|
128
|
+
puts "Task failed: #{result.failure.message}"
|
129
|
+
end
|
130
|
+
```
|
131
|
+
|
132
|
+
#### Plan Orchestration
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
# Create an orchestrator
|
136
|
+
orchestrator = Agentic::PlanOrchestrator.new(
|
137
|
+
concurrency_limit: 5,
|
138
|
+
continue_on_failure: true
|
139
|
+
)
|
140
|
+
|
141
|
+
# Add tasks to the orchestrator
|
142
|
+
tasks.each do |task|
|
143
|
+
orchestrator.add_task(task)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Create an agent provider
|
147
|
+
agent_provider = Agentic::DefaultAgentProvider.new
|
148
|
+
|
149
|
+
# Execute the plan
|
150
|
+
result = orchestrator.execute_plan(agent_provider)
|
151
|
+
|
152
|
+
# Process the results
|
153
|
+
if result.successful?
|
154
|
+
puts "Plan executed successfully!"
|
155
|
+
else
|
156
|
+
puts "Plan execution had issues: #{result.status}"
|
157
|
+
result.results.each do |task_id, task_result|
|
158
|
+
if task_result.failed?
|
159
|
+
puts "Task #{task_id} failed: #{task_result.failure.message}"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
```
|
164
|
+
|
165
|
+
## Extension System
|
166
|
+
|
167
|
+
Agentic includes a powerful Extension System to help integrate with external systems and customize the framework's behavior. The Extension System consists of three main components:
|
168
|
+
|
169
|
+
### Domain Adapters
|
170
|
+
|
171
|
+
Domain Adapters let you customize Agentic's behavior for specific domains like healthcare, finance, or legal:
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
# Create a domain adapter for healthcare
|
175
|
+
adapter = Agentic::Extension.domain_adapter("healthcare")
|
176
|
+
|
177
|
+
# Add domain-specific knowledge
|
178
|
+
adapter.add_knowledge(:terminology, {
|
179
|
+
terms: ["patient", "diagnosis", "treatment"],
|
180
|
+
specialty: "cardiology"
|
181
|
+
})
|
182
|
+
|
183
|
+
# Create a custom prompt adapter
|
184
|
+
prompt_adapter = ->(prompt, context) {
|
185
|
+
specialty = context[:domain_knowledge][:terminology][:specialty]
|
186
|
+
"#{prompt} [Adapted for #{context[:domain]} #{specialty}]"
|
187
|
+
}
|
188
|
+
|
189
|
+
# Register the adapter
|
190
|
+
adapter.register_adapter(:prompt, prompt_adapter)
|
191
|
+
|
192
|
+
# Apply adaptation to a prompt
|
193
|
+
adapted_prompt = adapter.adapt(:prompt, "Describe the symptoms")
|
194
|
+
# => "Describe the symptoms [Adapted for healthcare cardiology]"
|
195
|
+
```
|
196
|
+
|
197
|
+
### Protocol Handlers
|
198
|
+
|
199
|
+
Protocol Handlers standardize connections to external systems and APIs:
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
# Get the protocol handler
|
203
|
+
handler = Agentic::Extension.protocol_handler(
|
204
|
+
default_headers: { "User-Agent" => "AgenticApp/1.0" }
|
205
|
+
)
|
206
|
+
|
207
|
+
# Create and register a protocol implementation
|
208
|
+
http_protocol = Object.new
|
209
|
+
def http_protocol.send_request(endpoint, options)
|
210
|
+
# Implement HTTP request logic
|
211
|
+
{ status: 200, body: "Response data" }
|
212
|
+
end
|
213
|
+
|
214
|
+
# Register the protocol
|
215
|
+
handler.register_protocol(:http, http_protocol, { timeout: 30 })
|
216
|
+
|
217
|
+
# Send a request
|
218
|
+
response = handler.send_request(:http, "/api/data", {
|
219
|
+
method: "GET",
|
220
|
+
headers: { "Accept" => "application/json" }
|
221
|
+
})
|
222
|
+
```
|
223
|
+
|
224
|
+
### Plugin Manager
|
225
|
+
|
226
|
+
The Plugin Manager handles third-party extensions and their lifecycle:
|
227
|
+
|
228
|
+
```ruby
|
229
|
+
# Get the plugin manager
|
230
|
+
manager = Agentic::Extension.plugin_manager
|
231
|
+
|
232
|
+
# Register a plugin
|
233
|
+
plugin = MyPlugin.new
|
234
|
+
manager.register("my_plugin", plugin, { version: "1.0.0" })
|
235
|
+
|
236
|
+
# Get and use a plugin
|
237
|
+
if plugin = manager.get("my_plugin")
|
238
|
+
result = plugin.call(arg1, arg2)
|
239
|
+
end
|
240
|
+
|
241
|
+
# Disable a plugin
|
242
|
+
manager.disable("my_plugin")
|
243
|
+
```
|
244
|
+
|
245
|
+
## Agent Specification and Task Definition
|
246
|
+
|
247
|
+
Agentic provides structured representations for agents and tasks through several key value objects:
|
248
|
+
|
249
|
+
### Agent Specification
|
250
|
+
|
251
|
+
The AgentSpecification defines the requirements for an agent:
|
252
|
+
|
253
|
+
```ruby
|
254
|
+
# Create an agent specification
|
255
|
+
agent_spec = Agentic::AgentSpecification.new(
|
256
|
+
name: "ResearchAgent",
|
257
|
+
description: "An agent that performs research",
|
258
|
+
instructions: "Research the given topic thoroughly"
|
259
|
+
)
|
260
|
+
|
261
|
+
# Convert to a hash representation
|
262
|
+
hash = agent_spec.to_h
|
263
|
+
|
264
|
+
# Create from a hash representation
|
265
|
+
agent_spec_from_hash = Agentic::AgentSpecification.from_hash(hash)
|
266
|
+
```
|
267
|
+
|
268
|
+
### Task Definition
|
269
|
+
|
270
|
+
The TaskDefinition defines a task to be performed by an agent:
|
271
|
+
|
272
|
+
```ruby
|
273
|
+
# Create a task definition
|
274
|
+
task_def = Agentic::TaskDefinition.new(
|
275
|
+
description: "Research AI trends",
|
276
|
+
agent: agent_spec
|
277
|
+
)
|
278
|
+
|
279
|
+
# Convert to a hash representation
|
280
|
+
hash = task_def.to_h
|
281
|
+
|
282
|
+
# Create from a hash representation
|
283
|
+
task_def_from_hash = Agentic::TaskDefinition.from_hash(hash)
|
284
|
+
```
|
285
|
+
|
286
|
+
### Execution Plan
|
287
|
+
|
288
|
+
The ExecutionPlan represents a plan with tasks and expected answer format:
|
289
|
+
|
290
|
+
```ruby
|
291
|
+
# Create an expected answer format
|
292
|
+
expected_answer = Agentic::ExpectedAnswerFormat.new(
|
293
|
+
format: "PDF",
|
294
|
+
sections: ["Summary", "Trends", "Conclusion"],
|
295
|
+
length: "10 pages"
|
296
|
+
)
|
297
|
+
|
298
|
+
# Create an execution plan
|
299
|
+
plan = Agentic::ExecutionPlan.new([task_def], expected_answer)
|
300
|
+
|
301
|
+
# Convert to a formatted string
|
302
|
+
puts plan.to_s
|
303
|
+
|
304
|
+
# Convert to a hash representation
|
305
|
+
hash = plan.to_h
|
306
|
+
```
|
307
|
+
|
308
|
+
### Agent Configuration
|
309
|
+
|
310
|
+
The AgentConfig provides a configuration object for agents:
|
311
|
+
|
312
|
+
```ruby
|
313
|
+
# Create an agent configuration
|
314
|
+
config = Agentic::AgentConfig.new(
|
315
|
+
name: "ResearchAgent",
|
316
|
+
role: "Research Assistant",
|
317
|
+
backstory: "You are an expert researcher with decades of experience",
|
318
|
+
tools: ["web_search", "document_processor"],
|
319
|
+
llm_config: Agentic::LlmConfig.new(model: "gpt-4o-mini")
|
320
|
+
)
|
321
|
+
|
322
|
+
# Access configuration properties
|
323
|
+
puts config.name
|
324
|
+
puts config.role
|
325
|
+
|
326
|
+
# Convert to a hash representation
|
327
|
+
hash = config.to_h
|
328
|
+
```
|
329
|
+
|
330
|
+
## Agent Capabilities System
|
331
|
+
|
332
|
+
Agentic features a powerful Capability System that enables dynamic agent composition, self-assembly, and persistence. The system allows agents to be constructed with precisely the capabilities they need for specific tasks, and to be stored for future reuse.
|
333
|
+
|
334
|
+
### Capability Registry
|
335
|
+
|
336
|
+
The capability registry manages capability specifications and providers:
|
337
|
+
|
338
|
+
```ruby
|
339
|
+
# Define a capability specification
|
340
|
+
text_gen_capability = Agentic::CapabilitySpecification.new(
|
341
|
+
name: "text_generation",
|
342
|
+
description: "Generates text based on a prompt",
|
343
|
+
version: "1.0.0",
|
344
|
+
inputs: {
|
345
|
+
prompt: { type: "string", required: true, description: "The prompt to generate text from" }
|
346
|
+
},
|
347
|
+
outputs: {
|
348
|
+
response: { type: "string", description: "The generated text" }
|
349
|
+
}
|
350
|
+
)
|
351
|
+
|
352
|
+
# Create a provider for the capability
|
353
|
+
text_gen_provider = Agentic::CapabilityProvider.new(
|
354
|
+
capability: text_gen_capability,
|
355
|
+
implementation: ->(inputs) { { response: "Generated text for: #{inputs[:prompt]}" } }
|
356
|
+
)
|
357
|
+
|
358
|
+
# Register the capability with the system
|
359
|
+
Agentic.register_capability(text_gen_capability, text_gen_provider)
|
360
|
+
```
|
361
|
+
|
362
|
+
### Agent Assembly Engine
|
363
|
+
|
364
|
+
The assembly engine dynamically constructs agents based on task requirements:
|
365
|
+
|
366
|
+
```ruby
|
367
|
+
# Define a task
|
368
|
+
task = Agentic::Task.new(
|
369
|
+
description: "Generate a report on AI trends",
|
370
|
+
agent_spec: Agentic::AgentSpecification.new(
|
371
|
+
name: "Report Generator",
|
372
|
+
description: "An agent that generates reports",
|
373
|
+
instructions: "Generate a comprehensive report on the topic"
|
374
|
+
),
|
375
|
+
input: {
|
376
|
+
topic: "AI trends in 2023",
|
377
|
+
format: "markdown"
|
378
|
+
}
|
379
|
+
)
|
380
|
+
|
381
|
+
# Assemble an agent for the task
|
382
|
+
agent = Agentic.assemble_agent(task)
|
383
|
+
|
384
|
+
# The agent will automatically have capabilities like "text_generation"
|
385
|
+
# based on the task requirements
|
386
|
+
```
|
387
|
+
|
388
|
+
### Agent Persistence
|
389
|
+
|
390
|
+
Agents can be stored and retrieved for future use:
|
391
|
+
|
392
|
+
```ruby
|
393
|
+
# Store an agent for future use
|
394
|
+
agent_id = Agentic.agent_store.store(agent, name: "report_generator")
|
395
|
+
|
396
|
+
# Later, retrieve the agent by name
|
397
|
+
stored_agent = Agentic.agent_store.build_agent("report_generator")
|
398
|
+
|
399
|
+
# Or retrieve by ID
|
400
|
+
stored_agent = Agentic.agent_store.build_agent(agent_id)
|
401
|
+
|
402
|
+
# List all stored agents
|
403
|
+
agents = Agentic.agent_store.all
|
404
|
+
```
|
405
|
+
|
406
|
+
### Capability Composition
|
407
|
+
|
408
|
+
Capabilities can be composed into higher-level capabilities:
|
409
|
+
|
410
|
+
```ruby
|
411
|
+
registry = Agentic.agent_capability_registry
|
412
|
+
|
413
|
+
# Compose multiple capabilities into a new one
|
414
|
+
registry.compose(
|
415
|
+
"comprehensive_report",
|
416
|
+
"Generates a comprehensive report with research and formatting",
|
417
|
+
"1.0.0",
|
418
|
+
[
|
419
|
+
{ name: "text_generation", version: "1.0.0" },
|
420
|
+
{ name: "data_analysis", version: "1.0.0" }
|
421
|
+
],
|
422
|
+
->(providers, inputs) {
|
423
|
+
# Implementation that uses both capabilities
|
424
|
+
analysis = providers[1].execute(data: inputs[:data])
|
425
|
+
report = providers[0].execute(prompt: "Generate a report on: #{analysis[:summary]}")
|
426
|
+
{ report: report[:response], analysis: analysis }
|
427
|
+
}
|
428
|
+
)
|
429
|
+
|
430
|
+
# Use the composed capability
|
431
|
+
agent.add_capability("comprehensive_report")
|
432
|
+
result = agent.execute_capability("comprehensive_report", { data: { ... } })
|
433
|
+
```
|
434
|
+
|
435
|
+
## Learning System
|
436
|
+
|
437
|
+
Agentic features a Learning System that enables agents to improve over time by capturing execution metrics, recognizing patterns, and optimizing strategies. The Learning System consists of three main components:
|
438
|
+
|
439
|
+
### Execution History Store
|
440
|
+
|
441
|
+
The ExecutionHistoryStore captures and stores execution metrics and performance data:
|
442
|
+
|
443
|
+
```ruby
|
444
|
+
# Create a history store
|
445
|
+
history_store = Agentic::Learning::ExecutionHistoryStore.new(
|
446
|
+
storage_path: "~/.agentic/history",
|
447
|
+
anonymize: true,
|
448
|
+
retention_days: 30
|
449
|
+
)
|
450
|
+
|
451
|
+
# Record task execution metrics
|
452
|
+
history_store.record_execution(
|
453
|
+
task_id: "task-123",
|
454
|
+
agent_type: "research_agent",
|
455
|
+
duration_ms: 1500,
|
456
|
+
success: true,
|
457
|
+
metrics: { tokens_used: 2000, quality_score: 0.85 }
|
458
|
+
)
|
459
|
+
|
460
|
+
# Query execution history
|
461
|
+
research_tasks = history_store.get_history(agent_type: "research_agent", success: true)
|
462
|
+
|
463
|
+
# Calculate metrics
|
464
|
+
avg_tokens = history_store.get_metric(:tokens_used, { agent_type: "research_agent" }, :avg)
|
465
|
+
```
|
466
|
+
|
467
|
+
### Pattern Recognizer
|
468
|
+
|
469
|
+
The PatternRecognizer analyzes execution history to identify patterns and optimization opportunities:
|
470
|
+
|
471
|
+
```ruby
|
472
|
+
# Create a pattern recognizer
|
473
|
+
recognizer = Agentic::Learning::PatternRecognizer.new(
|
474
|
+
history_store: history_store,
|
475
|
+
min_sample_size: 10
|
476
|
+
)
|
477
|
+
|
478
|
+
# Analyze agent performance
|
479
|
+
patterns = recognizer.analyze_agent_performance("research_agent")
|
480
|
+
|
481
|
+
# Analyze correlations between properties
|
482
|
+
correlation = recognizer.analyze_correlation(:duration_ms, :tokens_used)
|
483
|
+
|
484
|
+
# Get optimization recommendations
|
485
|
+
recommendations = recognizer.recommend_optimizations("research_agent")
|
486
|
+
```
|
487
|
+
|
488
|
+
### Strategy Optimizer
|
489
|
+
|
490
|
+
The StrategyOptimizer generates improvements for prompts, parameters, and task sequences:
|
491
|
+
|
492
|
+
```ruby
|
493
|
+
# Create a strategy optimizer
|
494
|
+
optimizer = Agentic::Learning::StrategyOptimizer.new(
|
495
|
+
pattern_recognizer: recognizer,
|
496
|
+
history_store: history_store,
|
497
|
+
llm_client: llm_client # Optional, for LLM-enhanced optimizations
|
498
|
+
)
|
499
|
+
|
500
|
+
# Optimize a prompt template
|
501
|
+
improved_prompt = optimizer.optimize_prompt_template(
|
502
|
+
"Research the topic: {topic}",
|
503
|
+
"research_agent"
|
504
|
+
)
|
505
|
+
|
506
|
+
# Optimize LLM parameters
|
507
|
+
improved_params = optimizer.optimize_llm_parameters(
|
508
|
+
{ temperature: 0.7, max_tokens: 2000 },
|
509
|
+
"research_agent",
|
510
|
+
optimization_strategy: :balanced
|
511
|
+
)
|
512
|
+
|
513
|
+
# Generate performance report
|
514
|
+
report = optimizer.generate_performance_report("research_agent")
|
515
|
+
```
|
516
|
+
|
517
|
+
### Integrating with Plan Orchestrator
|
518
|
+
|
519
|
+
The Learning System can be automatically integrated with the PlanOrchestrator:
|
520
|
+
|
521
|
+
```ruby
|
522
|
+
# Create the learning system
|
523
|
+
learning_system = Agentic::Learning.create(
|
524
|
+
storage_path: "~/.agentic/history",
|
525
|
+
llm_client: llm_client,
|
526
|
+
auto_optimize: false
|
527
|
+
)
|
528
|
+
|
529
|
+
# Create a plan orchestrator
|
530
|
+
orchestrator = Agentic::PlanOrchestrator.new
|
531
|
+
|
532
|
+
# Register the learning system with the orchestrator
|
533
|
+
Agentic::Learning.register_with_orchestrator(orchestrator, learning_system)
|
534
|
+
|
535
|
+
# The orchestrator will now automatically record execution metrics
|
536
|
+
```
|
537
|
+
|
538
|
+
## Configuration
|
539
|
+
|
540
|
+
### Setting up the OpenAI API Key
|
541
|
+
|
542
|
+
You can configure the OpenAI API key in several ways:
|
543
|
+
|
544
|
+
1. Environment variable:
|
545
|
+
```bash
|
546
|
+
export OPENAI_ACCESS_TOKEN="your_api_key"
|
547
|
+
```
|
548
|
+
|
549
|
+
2. Configuration file:
|
550
|
+
Create `.agentic.yml` in your project directory or home directory:
|
551
|
+
```yaml
|
552
|
+
api_token: "your_api_key"
|
553
|
+
model: "gpt-4o-mini"
|
36
554
|
```
|
37
555
|
|
38
|
-
|
556
|
+
3. In your Ruby code:
|
39
557
|
```ruby
|
40
558
|
Agentic.configure do |config|
|
41
|
-
config.access_token =
|
559
|
+
config.access_token = "your_api_key"
|
42
560
|
end
|
43
561
|
```
|
44
562
|
|
45
|
-
|
46
|
-
```ruby
|
47
|
-
planner = Agentic::TaskPlanner.new("Write a blog post about Ruby on Rails")
|
48
|
-
```
|
563
|
+
### LLM Configuration
|
49
564
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
565
|
+
You can customize the LLM behavior:
|
566
|
+
|
567
|
+
```ruby
|
568
|
+
config = Agentic::LlmConfig.new(
|
569
|
+
model: "gpt-4o-mini",
|
570
|
+
max_tokens: 500,
|
571
|
+
temperature: 0.7,
|
572
|
+
top_p: 1.0,
|
573
|
+
frequency_penalty: 0,
|
574
|
+
presence_penalty: 0
|
575
|
+
)
|
576
|
+
|
577
|
+
# Use in TaskPlanner
|
578
|
+
planner = Agentic::TaskPlanner.new("Write a blog post", config)
|
55
579
|
|
56
|
-
|
580
|
+
# Or with LlmClient directly
|
581
|
+
client = Agentic::LlmClient.new(config)
|
582
|
+
```
|
57
583
|
|
58
584
|
## Development
|
59
585
|
|
60
586
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
61
587
|
|
588
|
+
### Running Tests
|
589
|
+
|
590
|
+
Agentic includes a comprehensive test suite with both unit tests and integration tests. To run all tests:
|
591
|
+
|
592
|
+
```bash
|
593
|
+
rake spec
|
594
|
+
```
|
595
|
+
|
596
|
+
To run specific test categories:
|
597
|
+
|
598
|
+
```bash
|
599
|
+
# Run just integration tests
|
600
|
+
rspec spec/integration/
|
601
|
+
|
602
|
+
# Run a specific integration test file
|
603
|
+
rspec spec/integration/plan_orchestrator_integration_spec.rb
|
604
|
+
|
605
|
+
# Run with verbose output
|
606
|
+
rspec spec/integration/ --format documentation
|
607
|
+
```
|
608
|
+
|
609
|
+
The integration tests cover real-world scenarios including:
|
610
|
+
- Complex orchestration patterns with dependencies
|
611
|
+
- Learning system's pattern recognition capabilities
|
612
|
+
- Agent specification and task definition interactions
|
613
|
+
- Timeout and retry behaviors
|
614
|
+
- Error handling in complex scenarios
|
615
|
+
|
62
616
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
63
617
|
|
64
618
|
## Contributing
|
@@ -71,4 +625,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
71
625
|
|
72
626
|
## Code of Conduct
|
73
627
|
|
74
|
-
Everyone interacting in the Agentic project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/codenamev/agentic/blob/main/CODE_OF_CONDUCT.md).
|
628
|
+
Everyone interacting in the Agentic project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/codenamev/agentic/blob/main/CODE_OF_CONDUCT.md).
|