a2a-ruby 1.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.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +137 -0
  4. data/.simplecov +46 -0
  5. data/.yardopts +10 -0
  6. data/CHANGELOG.md +33 -0
  7. data/CODE_OF_CONDUCT.md +128 -0
  8. data/CONTRIBUTING.md +165 -0
  9. data/Gemfile +43 -0
  10. data/Guardfile +34 -0
  11. data/LICENSE.txt +21 -0
  12. data/PUBLISHING_CHECKLIST.md +214 -0
  13. data/README.md +171 -0
  14. data/Rakefile +165 -0
  15. data/docs/agent_execution.md +309 -0
  16. data/docs/api_reference.md +792 -0
  17. data/docs/configuration.md +780 -0
  18. data/docs/events.md +475 -0
  19. data/docs/getting_started.md +668 -0
  20. data/docs/integration.md +262 -0
  21. data/docs/server_apps.md +621 -0
  22. data/docs/troubleshooting.md +765 -0
  23. data/lib/a2a/client/api_methods.rb +263 -0
  24. data/lib/a2a/client/auth/api_key.rb +161 -0
  25. data/lib/a2a/client/auth/interceptor.rb +288 -0
  26. data/lib/a2a/client/auth/jwt.rb +189 -0
  27. data/lib/a2a/client/auth/oauth2.rb +146 -0
  28. data/lib/a2a/client/auth.rb +137 -0
  29. data/lib/a2a/client/base.rb +316 -0
  30. data/lib/a2a/client/config.rb +210 -0
  31. data/lib/a2a/client/connection_pool.rb +233 -0
  32. data/lib/a2a/client/http_client.rb +524 -0
  33. data/lib/a2a/client/json_rpc_handler.rb +136 -0
  34. data/lib/a2a/client/middleware/circuit_breaker_interceptor.rb +245 -0
  35. data/lib/a2a/client/middleware/logging_interceptor.rb +371 -0
  36. data/lib/a2a/client/middleware/rate_limit_interceptor.rb +142 -0
  37. data/lib/a2a/client/middleware/retry_interceptor.rb +161 -0
  38. data/lib/a2a/client/middleware.rb +116 -0
  39. data/lib/a2a/client/performance_tracker.rb +60 -0
  40. data/lib/a2a/configuration/defaults.rb +34 -0
  41. data/lib/a2a/configuration/environment_loader.rb +76 -0
  42. data/lib/a2a/configuration/file_loader.rb +115 -0
  43. data/lib/a2a/configuration/inheritance.rb +101 -0
  44. data/lib/a2a/configuration/validator.rb +180 -0
  45. data/lib/a2a/configuration.rb +201 -0
  46. data/lib/a2a/errors.rb +291 -0
  47. data/lib/a2a/modules.rb +50 -0
  48. data/lib/a2a/monitoring/alerting.rb +490 -0
  49. data/lib/a2a/monitoring/distributed_tracing.rb +398 -0
  50. data/lib/a2a/monitoring/health_endpoints.rb +204 -0
  51. data/lib/a2a/monitoring/metrics_collector.rb +438 -0
  52. data/lib/a2a/monitoring.rb +463 -0
  53. data/lib/a2a/plugin.rb +358 -0
  54. data/lib/a2a/plugin_manager.rb +159 -0
  55. data/lib/a2a/plugins/example_auth.rb +81 -0
  56. data/lib/a2a/plugins/example_middleware.rb +118 -0
  57. data/lib/a2a/plugins/example_transport.rb +76 -0
  58. data/lib/a2a/protocol/agent_card.rb +8 -0
  59. data/lib/a2a/protocol/agent_card_server.rb +584 -0
  60. data/lib/a2a/protocol/capability.rb +496 -0
  61. data/lib/a2a/protocol/json_rpc.rb +254 -0
  62. data/lib/a2a/protocol/message.rb +8 -0
  63. data/lib/a2a/protocol/task.rb +8 -0
  64. data/lib/a2a/rails/a2a_controller.rb +258 -0
  65. data/lib/a2a/rails/controller_helpers.rb +499 -0
  66. data/lib/a2a/rails/engine.rb +167 -0
  67. data/lib/a2a/rails/generators/agent_generator.rb +311 -0
  68. data/lib/a2a/rails/generators/install_generator.rb +209 -0
  69. data/lib/a2a/rails/generators/migration_generator.rb +232 -0
  70. data/lib/a2a/rails/generators/templates/add_a2a_indexes.rb +57 -0
  71. data/lib/a2a/rails/generators/templates/agent_controller.rb +122 -0
  72. data/lib/a2a/rails/generators/templates/agent_controller_spec.rb +160 -0
  73. data/lib/a2a/rails/generators/templates/agent_readme.md +200 -0
  74. data/lib/a2a/rails/generators/templates/create_a2a_push_notification_configs.rb +68 -0
  75. data/lib/a2a/rails/generators/templates/create_a2a_tasks.rb +83 -0
  76. data/lib/a2a/rails/generators/templates/example_agent_controller.rb +228 -0
  77. data/lib/a2a/rails/generators/templates/initializer.rb +108 -0
  78. data/lib/a2a/rails/generators/templates/push_notification_config_model.rb +228 -0
  79. data/lib/a2a/rails/generators/templates/task_model.rb +200 -0
  80. data/lib/a2a/rails/tasks/a2a.rake +228 -0
  81. data/lib/a2a/server/a2a_methods.rb +520 -0
  82. data/lib/a2a/server/agent.rb +537 -0
  83. data/lib/a2a/server/agent_execution/agent_executor.rb +279 -0
  84. data/lib/a2a/server/agent_execution/request_context.rb +219 -0
  85. data/lib/a2a/server/apps/rack_app.rb +311 -0
  86. data/lib/a2a/server/apps/sinatra_app.rb +261 -0
  87. data/lib/a2a/server/default_request_handler.rb +350 -0
  88. data/lib/a2a/server/events/event_consumer.rb +116 -0
  89. data/lib/a2a/server/events/event_queue.rb +226 -0
  90. data/lib/a2a/server/example_agent.rb +248 -0
  91. data/lib/a2a/server/handler.rb +281 -0
  92. data/lib/a2a/server/middleware/authentication_middleware.rb +212 -0
  93. data/lib/a2a/server/middleware/cors_middleware.rb +171 -0
  94. data/lib/a2a/server/middleware/logging_middleware.rb +362 -0
  95. data/lib/a2a/server/middleware/rate_limit_middleware.rb +382 -0
  96. data/lib/a2a/server/middleware.rb +213 -0
  97. data/lib/a2a/server/push_notification_manager.rb +327 -0
  98. data/lib/a2a/server/request_handler.rb +136 -0
  99. data/lib/a2a/server/storage/base.rb +141 -0
  100. data/lib/a2a/server/storage/database.rb +266 -0
  101. data/lib/a2a/server/storage/memory.rb +274 -0
  102. data/lib/a2a/server/storage/redis.rb +320 -0
  103. data/lib/a2a/server/storage.rb +38 -0
  104. data/lib/a2a/server/task_manager.rb +534 -0
  105. data/lib/a2a/transport/grpc.rb +481 -0
  106. data/lib/a2a/transport/http.rb +415 -0
  107. data/lib/a2a/transport/sse.rb +499 -0
  108. data/lib/a2a/types/agent_card.rb +540 -0
  109. data/lib/a2a/types/artifact.rb +99 -0
  110. data/lib/a2a/types/base_model.rb +223 -0
  111. data/lib/a2a/types/events.rb +117 -0
  112. data/lib/a2a/types/message.rb +106 -0
  113. data/lib/a2a/types/part.rb +288 -0
  114. data/lib/a2a/types/push_notification.rb +139 -0
  115. data/lib/a2a/types/security.rb +167 -0
  116. data/lib/a2a/types/task.rb +154 -0
  117. data/lib/a2a/types.rb +88 -0
  118. data/lib/a2a/utils/helpers.rb +245 -0
  119. data/lib/a2a/utils/message_buffer.rb +278 -0
  120. data/lib/a2a/utils/performance.rb +247 -0
  121. data/lib/a2a/utils/rails_detection.rb +97 -0
  122. data/lib/a2a/utils/structured_logger.rb +306 -0
  123. data/lib/a2a/utils/time_helpers.rb +167 -0
  124. data/lib/a2a/utils/validation.rb +8 -0
  125. data/lib/a2a/version.rb +6 -0
  126. data/lib/a2a-rails.rb +58 -0
  127. data/lib/a2a.rb +198 -0
  128. metadata +437 -0
@@ -0,0 +1,780 @@
1
+ # Configuration Reference
2
+
3
+ This document provides comprehensive configuration options for the A2A Ruby SDK.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Global Configuration](#global-configuration)
8
+ - [Client Configuration](#client-configuration)
9
+ - [Server Configuration](#server-configuration)
10
+ - [Transport Configuration](#transport-configuration)
11
+ - [Authentication Configuration](#authentication-configuration)
12
+ - [Storage Configuration](#storage-configuration)
13
+ - [Logging Configuration](#logging-configuration)
14
+ - [Performance Configuration](#performance-configuration)
15
+ - [Environment Variables](#environment-variables)
16
+
17
+ ## Global Configuration
18
+
19
+ Configure the A2A SDK globally using the `A2A.configure` method:
20
+
21
+ ```ruby
22
+ # config/initializers/a2a.rb (Rails)
23
+ # or at the top of your application
24
+
25
+ A2A.configure do |config|
26
+ # Protocol settings
27
+ config.protocol_version = "0.3.0"
28
+ config.default_transport = "JSONRPC"
29
+
30
+ # Feature flags
31
+ config.streaming_enabled = true
32
+ config.push_notifications_enabled = true
33
+
34
+ # Timeouts
35
+ config.default_timeout = 30
36
+ config.connect_timeout = 10
37
+
38
+ # Security
39
+ config.force_ssl = true
40
+ config.ssl_verify = true
41
+ end
42
+ ```
43
+
44
+ ### Protocol Settings
45
+
46
+ #### protocol_version
47
+ - **Type:** String
48
+ - **Default:** `"0.3.0"`
49
+ - **Description:** A2A protocol version to use
50
+
51
+ ```ruby
52
+ config.protocol_version = "0.3.0"
53
+ ```
54
+
55
+ #### default_transport
56
+ - **Type:** String
57
+ - **Default:** `"JSONRPC"`
58
+ - **Options:** `"JSONRPC"`, `"GRPC"`, `"HTTP+JSON"`
59
+ - **Description:** Default transport protocol for clients
60
+
61
+ ```ruby
62
+ config.default_transport = "JSONRPC"
63
+ ```
64
+
65
+ ### Feature Flags
66
+
67
+ #### streaming_enabled
68
+ - **Type:** Boolean
69
+ - **Default:** `true`
70
+ - **Description:** Enable streaming responses globally
71
+
72
+ ```ruby
73
+ config.streaming_enabled = true
74
+ ```
75
+
76
+ #### push_notifications_enabled
77
+ - **Type:** Boolean
78
+ - **Default:** `true`
79
+ - **Description:** Enable push notification support
80
+
81
+ ```ruby
82
+ config.push_notifications_enabled = true
83
+ ```
84
+
85
+ #### rails_integration
86
+ - **Type:** Boolean
87
+ - **Default:** `true` (when Rails is detected)
88
+ - **Description:** Enable Rails-specific features
89
+
90
+ ```ruby
91
+ config.rails_integration = true
92
+ ```
93
+
94
+ ### Timeout Settings
95
+
96
+ #### default_timeout
97
+ - **Type:** Integer
98
+ - **Default:** `30`
99
+ - **Unit:** Seconds
100
+ - **Description:** Default request timeout
101
+
102
+ ```ruby
103
+ config.default_timeout = 60 # 1 minute
104
+ ```
105
+
106
+ #### connect_timeout
107
+ - **Type:** Integer
108
+ - **Default:** `10`
109
+ - **Unit:** Seconds
110
+ - **Description:** Connection establishment timeout
111
+
112
+ ```ruby
113
+ config.connect_timeout = 5 # 5 seconds
114
+ ```
115
+
116
+ #### read_timeout
117
+ - **Type:** Integer
118
+ - **Default:** `30`
119
+ - **Unit:** Seconds
120
+ - **Description:** Response read timeout
121
+
122
+ ```ruby
123
+ config.read_timeout = 45 # 45 seconds
124
+ ```
125
+
126
+ ### Security Settings
127
+
128
+ #### force_ssl
129
+ - **Type:** Boolean
130
+ - **Default:** `true` (production), `false` (development)
131
+ - **Description:** Require HTTPS for all connections
132
+
133
+ ```ruby
134
+ config.force_ssl = Rails.env.production?
135
+ ```
136
+
137
+ #### ssl_verify
138
+ - **Type:** Boolean
139
+ - **Default:** `true`
140
+ - **Description:** Verify SSL certificates
141
+
142
+ ```ruby
143
+ config.ssl_verify = true
144
+ ```
145
+
146
+ #### allowed_hosts
147
+ - **Type:** Array<String>
148
+ - **Default:** `[]` (no restrictions)
149
+ - **Description:** Restrict connections to specific hosts
150
+
151
+ ```ruby
152
+ config.allowed_hosts = ["agent1.example.com", "agent2.example.com"]
153
+ ```
154
+
155
+ ## Client Configuration
156
+
157
+ Configure individual clients using `A2A::Client::Config`:
158
+
159
+ ```ruby
160
+ config = A2A::Client::Config.new
161
+
162
+ # Streaming settings
163
+ config.streaming = true
164
+ config.polling = false
165
+ config.polling_interval = 5
166
+
167
+ # Transport settings
168
+ config.supported_transports = ['JSONRPC', 'GRPC']
169
+ config.use_client_preference = true
170
+
171
+ # Output settings
172
+ config.accepted_output_modes = ['text', 'structured']
173
+
174
+ # Timeout settings
175
+ config.timeout = 60
176
+ config.connect_timeout = 10
177
+
178
+ # Retry settings
179
+ config.max_retries = 3
180
+ config.retry_delay = 1
181
+ config.retry_backoff = 2
182
+
183
+ client = A2A::Client::HttpClient.new(url, config: config)
184
+ ```
185
+
186
+ ### Streaming Configuration
187
+
188
+ #### streaming
189
+ - **Type:** Boolean
190
+ - **Default:** `true`
191
+ - **Description:** Enable streaming responses for this client
192
+
193
+ #### polling
194
+ - **Type:** Boolean
195
+ - **Default:** `false`
196
+ - **Description:** Enable polling fallback when streaming fails
197
+
198
+ #### polling_interval
199
+ - **Type:** Integer
200
+ - **Default:** `5`
201
+ - **Unit:** Seconds
202
+ - **Description:** Polling interval for task status updates
203
+
204
+ ### Transport Configuration
205
+
206
+ #### supported_transports
207
+ - **Type:** Array<String>
208
+ - **Default:** `['JSONRPC']`
209
+ - **Options:** `'JSONRPC'`, `'GRPC'`, `'HTTP+JSON'`
210
+ - **Description:** Transport protocols supported by client
211
+
212
+ #### use_client_preference
213
+ - **Type:** Boolean
214
+ - **Default:** `true`
215
+ - **Description:** Use client transport preference in negotiation
216
+
217
+ ### Output Configuration
218
+
219
+ #### accepted_output_modes
220
+ - **Type:** Array<String>
221
+ - **Default:** `['text', 'structured']`
222
+ - **Options:** `'text'`, `'structured'`, `'binary'`
223
+ - **Description:** Output modes accepted by client
224
+
225
+ ### Retry Configuration
226
+
227
+ #### max_retries
228
+ - **Type:** Integer
229
+ - **Default:** `3`
230
+ - **Description:** Maximum number of retry attempts
231
+
232
+ #### retry_delay
233
+ - **Type:** Integer
234
+ - **Default:** `1`
235
+ - **Unit:** Seconds
236
+ - **Description:** Initial delay between retries
237
+
238
+ #### retry_backoff
239
+ - **Type:** Float
240
+ - **Default:** `2.0`
241
+ - **Description:** Backoff multiplier for retry delays
242
+
243
+ ## Server Configuration
244
+
245
+ Configure A2A servers and agents:
246
+
247
+ ```ruby
248
+ class MyAgent
249
+ include A2A::Server::Agent
250
+
251
+ # Agent metadata
252
+ a2a_config(
253
+ name: "My Agent",
254
+ description: "A sample A2A agent",
255
+ version: "1.0.0",
256
+ url: "https://myagent.example.com/a2a",
257
+ provider: {
258
+ name: "My Company",
259
+ url: "https://mycompany.com"
260
+ }
261
+ )
262
+
263
+ # Global agent settings
264
+ a2a_settings do |settings|
265
+ settings.max_concurrent_tasks = 10
266
+ settings.task_timeout = 300
267
+ settings.enable_task_history = true
268
+ settings.history_length = 100
269
+ end
270
+ end
271
+ ```
272
+
273
+ ### Agent Metadata
274
+
275
+ #### name
276
+ - **Type:** String
277
+ - **Required:** Yes
278
+ - **Description:** Human-readable agent name
279
+
280
+ #### description
281
+ - **Type:** String
282
+ - **Required:** Yes
283
+ - **Description:** Agent description
284
+
285
+ #### version
286
+ - **Type:** String
287
+ - **Required:** Yes
288
+ - **Description:** Agent version (semantic versioning recommended)
289
+
290
+ #### url
291
+ - **Type:** String
292
+ - **Required:** No
293
+ - **Description:** Agent endpoint URL
294
+
295
+ #### provider
296
+ - **Type:** Hash
297
+ - **Required:** No
298
+ - **Description:** Provider information
299
+ - `name` (String) - Provider name
300
+ - `url` (String) - Provider URL
301
+
302
+ ### Agent Settings
303
+
304
+ #### max_concurrent_tasks
305
+ - **Type:** Integer
306
+ - **Default:** `10`
307
+ - **Description:** Maximum concurrent tasks per agent
308
+
309
+ #### task_timeout
310
+ - **Type:** Integer
311
+ - **Default:** `300`
312
+ - **Unit:** Seconds
313
+ - **Description:** Default task timeout
314
+
315
+ #### enable_task_history
316
+ - **Type:** Boolean
317
+ - **Default:** `true`
318
+ - **Description:** Store task message history
319
+
320
+ #### history_length
321
+ - **Type:** Integer
322
+ - **Default:** `100`
323
+ - **Description:** Maximum messages in task history
324
+
325
+ ## Transport Configuration
326
+
327
+ ### HTTP Transport
328
+
329
+ ```ruby
330
+ A2A.configure do |config|
331
+ config.http_adapter = :net_http_persistent
332
+ config.http_pool_size = 5
333
+ config.http_keep_alive = 30
334
+ config.http_user_agent = "A2A-Ruby/#{A2A::VERSION}"
335
+ end
336
+ ```
337
+
338
+ #### http_adapter
339
+ - **Type:** Symbol
340
+ - **Default:** `:net_http`
341
+ - **Options:** `:net_http`, `:net_http_persistent`, `:typhoeus`
342
+ - **Description:** Faraday adapter for HTTP transport
343
+
344
+ #### http_pool_size
345
+ - **Type:** Integer
346
+ - **Default:** `5`
347
+ - **Description:** HTTP connection pool size
348
+
349
+ #### http_keep_alive
350
+ - **Type:** Integer
351
+ - **Default:** `30`
352
+ - **Unit:** Seconds
353
+ - **Description:** HTTP keep-alive timeout
354
+
355
+ ### gRPC Transport
356
+
357
+ ```ruby
358
+ A2A.configure do |config|
359
+ config.grpc_enabled = true
360
+ config.grpc_pool_size = 5
361
+ config.grpc_keepalive_time = 30
362
+ config.grpc_keepalive_timeout = 5
363
+ end
364
+ ```
365
+
366
+ #### grpc_enabled
367
+ - **Type:** Boolean
368
+ - **Default:** `false`
369
+ - **Description:** Enable gRPC transport support
370
+
371
+ #### grpc_pool_size
372
+ - **Type:** Integer
373
+ - **Default:** `5`
374
+ - **Description:** gRPC connection pool size
375
+
376
+ ### Server-Sent Events
377
+
378
+ ```ruby
379
+ A2A.configure do |config|
380
+ config.sse_heartbeat_interval = 30
381
+ config.sse_reconnect_delay = 5
382
+ config.sse_max_reconnects = 10
383
+ end
384
+ ```
385
+
386
+ #### sse_heartbeat_interval
387
+ - **Type:** Integer
388
+ - **Default:** `30`
389
+ - **Unit:** Seconds
390
+ - **Description:** SSE heartbeat interval
391
+
392
+ #### sse_reconnect_delay
393
+ - **Type:** Integer
394
+ - **Default:** `5`
395
+ - **Unit:** Seconds
396
+ - **Description:** Delay before SSE reconnection
397
+
398
+ ## Authentication Configuration
399
+
400
+ ### OAuth 2.0
401
+
402
+ ```ruby
403
+ auth = A2A::Client::Auth::OAuth2.new(
404
+ client_id: ENV['A2A_CLIENT_ID'],
405
+ client_secret: ENV['A2A_CLIENT_SECRET'],
406
+ token_url: ENV['A2A_TOKEN_URL'],
407
+ scope: "a2a:read a2a:write",
408
+ audience: "https://api.example.com"
409
+ )
410
+ ```
411
+
412
+ ### JWT
413
+
414
+ ```ruby
415
+ auth = A2A::Client::Auth::JWT.new(
416
+ token: ENV['A2A_JWT_TOKEN'],
417
+ header: "Authorization", # or custom header
418
+ prefix: "Bearer" # token prefix
419
+ )
420
+ ```
421
+
422
+ ### API Key
423
+
424
+ ```ruby
425
+ # Header-based
426
+ auth = A2A::Client::Auth::ApiKey.new(
427
+ key: ENV['A2A_API_KEY'],
428
+ header: "X-API-Key"
429
+ )
430
+
431
+ # Query parameter
432
+ auth = A2A::Client::Auth::ApiKey.new(
433
+ key: ENV['A2A_API_KEY'],
434
+ parameter: "api_key"
435
+ )
436
+ ```
437
+
438
+ ### Server Authentication
439
+
440
+ ```ruby
441
+ # config/initializers/a2a.rb
442
+ A2A.configure do |config|
443
+ config.server_auth_strategy = :jwt
444
+ config.jwt_secret = ENV['JWT_SECRET']
445
+ config.jwt_algorithm = 'HS256'
446
+ config.jwt_issuer = 'your-app'
447
+ config.jwt_audience = 'a2a-agents'
448
+ end
449
+ ```
450
+
451
+ ## Storage Configuration
452
+
453
+ ### Database Storage
454
+
455
+ ```ruby
456
+ A2A.configure do |config|
457
+ config.storage_backend = :database
458
+ config.database_url = ENV['DATABASE_URL']
459
+ config.database_pool_size = 5
460
+ config.database_timeout = 5000
461
+ end
462
+ ```
463
+
464
+ ### Redis Storage
465
+
466
+ ```ruby
467
+ A2A.configure do |config|
468
+ config.storage_backend = :redis
469
+ config.redis_url = ENV['REDIS_URL']
470
+ config.redis_pool_size = 5
471
+ config.redis_timeout = 5
472
+ config.redis_namespace = 'a2a'
473
+ end
474
+ ```
475
+
476
+ ### Memory Storage
477
+
478
+ ```ruby
479
+ A2A.configure do |config|
480
+ config.storage_backend = :memory
481
+ config.memory_max_tasks = 1000
482
+ config.memory_cleanup_interval = 300
483
+ end
484
+ ```
485
+
486
+ ## Logging Configuration
487
+
488
+ ```ruby
489
+ A2A.configure do |config|
490
+ # Log level
491
+ config.log_level = :info # :debug, :info, :warn, :error
492
+
493
+ # Request/response logging
494
+ config.log_requests = false
495
+ config.log_responses = false
496
+ config.log_request_bodies = false
497
+ config.log_response_bodies = false
498
+
499
+ # Custom logger
500
+ config.logger = Rails.logger # or custom logger
501
+
502
+ # Log format
503
+ config.log_format = :json # :text, :json
504
+
505
+ # Structured logging
506
+ config.structured_logging = true
507
+ config.log_correlation_id = true
508
+ end
509
+ ```
510
+
511
+ ### Log Levels
512
+
513
+ - `debug` - Detailed debugging information
514
+ - `info` - General information messages
515
+ - `warn` - Warning messages
516
+ - `error` - Error messages only
517
+
518
+ ### Custom Logger
519
+
520
+ ```ruby
521
+ require 'logger'
522
+
523
+ custom_logger = Logger.new(STDOUT)
524
+ custom_logger.formatter = proc do |severity, datetime, progname, msg|
525
+ "[#{datetime}] #{severity}: #{msg}\n"
526
+ end
527
+
528
+ A2A.configure do |config|
529
+ config.logger = custom_logger
530
+ end
531
+ ```
532
+
533
+ ## Performance Configuration
534
+
535
+ ### Metrics
536
+
537
+ ```ruby
538
+ A2A.configure do |config|
539
+ config.enable_metrics = true
540
+ config.metrics_backend = :prometheus # :prometheus, :statsd, :custom
541
+ config.metrics_namespace = 'a2a'
542
+ config.metrics_tags = { service: 'my-agent' }
543
+ end
544
+ ```
545
+
546
+ ### Rate Limiting
547
+
548
+ ```ruby
549
+ A2A.configure do |config|
550
+ config.rate_limit_enabled = true
551
+ config.rate_limit_requests = 100
552
+ config.rate_limit_window = 60
553
+ config.rate_limit_storage = :redis # :memory, :redis
554
+ end
555
+ ```
556
+
557
+ ### Caching
558
+
559
+ ```ruby
560
+ A2A.configure do |config|
561
+ config.enable_caching = true
562
+ config.cache_backend = :redis # :memory, :redis, :rails
563
+ config.cache_ttl = 300 # 5 minutes
564
+ config.cache_namespace = 'a2a_cache'
565
+ end
566
+ ```
567
+
568
+ ### Connection Pooling
569
+
570
+ ```ruby
571
+ A2A.configure do |config|
572
+ config.connection_pool_size = 10
573
+ config.connection_pool_timeout = 5
574
+ config.connection_keep_alive = 30
575
+ end
576
+ ```
577
+
578
+ ## Environment Variables
579
+
580
+ The A2A SDK supports configuration via environment variables:
581
+
582
+ ### General Settings
583
+
584
+ ```bash
585
+ # Protocol
586
+ A2A_PROTOCOL_VERSION=0.3.0
587
+ A2A_DEFAULT_TRANSPORT=JSONRPC
588
+
589
+ # Timeouts
590
+ A2A_DEFAULT_TIMEOUT=30
591
+ A2A_CONNECT_TIMEOUT=10
592
+
593
+ # Security
594
+ A2A_FORCE_SSL=true
595
+ A2A_SSL_VERIFY=true
596
+ ```
597
+
598
+ ### Authentication
599
+
600
+ ```bash
601
+ # OAuth 2.0
602
+ A2A_CLIENT_ID=your-client-id
603
+ A2A_CLIENT_SECRET=your-client-secret
604
+ A2A_TOKEN_URL=https://auth.example.com/token
605
+ A2A_SCOPE=a2a:read a2a:write
606
+
607
+ # JWT
608
+ A2A_JWT_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
609
+ A2A_JWT_SECRET=your-jwt-secret
610
+
611
+ # API Key
612
+ A2A_API_KEY=your-api-key
613
+ ```
614
+
615
+ ### Storage
616
+
617
+ ```bash
618
+ # Database
619
+ A2A_STORAGE_BACKEND=database
620
+ DATABASE_URL=postgresql://user:pass@localhost/db
621
+
622
+ # Redis
623
+ A2A_STORAGE_BACKEND=redis
624
+ REDIS_URL=redis://localhost:6379/0
625
+ ```
626
+
627
+ ### Logging
628
+
629
+ ```bash
630
+ A2A_LOG_LEVEL=info
631
+ A2A_LOG_REQUESTS=false
632
+ A2A_LOG_RESPONSES=false
633
+ A2A_LOG_FORMAT=json
634
+ ```
635
+
636
+ ### Performance
637
+
638
+ ```bash
639
+ A2A_ENABLE_METRICS=true
640
+ A2A_METRICS_BACKEND=prometheus
641
+ A2A_RATE_LIMIT_ENABLED=true
642
+ A2A_RATE_LIMIT_REQUESTS=100
643
+ ```
644
+
645
+ ## Configuration Validation
646
+
647
+ The SDK validates configuration at startup:
648
+
649
+ ```ruby
650
+ A2A.configure do |config|
651
+ config.protocol_version = "invalid" # Will raise error
652
+ end
653
+
654
+ # Raises A2A::Errors::InvalidConfiguration
655
+ ```
656
+
657
+ ### Validation Rules
658
+
659
+ - `protocol_version` must be a valid semantic version
660
+ - `default_transport` must be a supported transport
661
+ - Timeout values must be positive integers
662
+ - Storage backend must be available
663
+ - Authentication credentials must be valid format
664
+
665
+ ## Configuration Precedence
666
+
667
+ Configuration is resolved in this order (highest to lowest priority):
668
+
669
+ 1. Explicit configuration in code
670
+ 2. Environment variables
671
+ 3. Configuration files
672
+ 4. Default values
673
+
674
+ ```ruby
675
+ # 1. Explicit (highest priority)
676
+ A2A.configure { |c| c.timeout = 60 }
677
+
678
+ # 2. Environment variable
679
+ ENV['A2A_DEFAULT_TIMEOUT'] = '45'
680
+
681
+ # 3. Configuration file
682
+ # config/a2a.yml: timeout: 30
683
+
684
+ # 4. Default value: 30
685
+
686
+ # Result: timeout = 60 (explicit wins)
687
+ ```
688
+
689
+ ## Configuration Files
690
+
691
+ ### YAML Configuration
692
+
693
+ ```yaml
694
+ # config/a2a.yml
695
+ development:
696
+ protocol_version: "0.3.0"
697
+ default_transport: "JSONRPC"
698
+ streaming_enabled: true
699
+ log_level: debug
700
+ storage_backend: memory
701
+
702
+ production:
703
+ protocol_version: "0.3.0"
704
+ default_transport: "JSONRPC"
705
+ streaming_enabled: true
706
+ log_level: info
707
+ storage_backend: database
708
+ force_ssl: true
709
+ ```
710
+
711
+ Load configuration:
712
+
713
+ ```ruby
714
+ config_file = Rails.root.join('config', 'a2a.yml')
715
+ config_data = YAML.load_file(config_file)[Rails.env]
716
+
717
+ A2A.configure do |config|
718
+ config_data.each do |key, value|
719
+ config.send("#{key}=", value)
720
+ end
721
+ end
722
+ ```
723
+
724
+ ## Dynamic Configuration
725
+
726
+ Some settings can be changed at runtime:
727
+
728
+ ```ruby
729
+ # Change log level
730
+ A2A.configuration.log_level = :debug
731
+
732
+ # Enable/disable features
733
+ A2A.configuration.streaming_enabled = false
734
+
735
+ # Update timeouts
736
+ A2A.configuration.default_timeout = 60
737
+ ```
738
+
739
+ Note: Some settings (like storage backend) require restart to take effect.
740
+
741
+ ## Configuration Best Practices
742
+
743
+ 1. **Use environment variables** for sensitive data (API keys, secrets)
744
+ 2. **Set appropriate timeouts** based on your use case
745
+ 3. **Enable SSL verification** in production
746
+ 4. **Use structured logging** for better observability
747
+ 5. **Configure rate limiting** to protect your services
748
+ 6. **Enable metrics** for monitoring and debugging
749
+ 7. **Use connection pooling** for better performance
750
+ 8. **Validate configuration** in your deployment pipeline
751
+
752
+ ## Troubleshooting Configuration
753
+
754
+ ### Common Issues
755
+
756
+ **SSL Certificate Errors:**
757
+ ```ruby
758
+ # Temporary fix for development
759
+ A2A.configure { |c| c.ssl_verify = false }
760
+ ```
761
+
762
+ **Timeout Issues:**
763
+ ```ruby
764
+ # Increase timeouts for slow networks
765
+ A2A.configure do |config|
766
+ config.default_timeout = 120
767
+ config.connect_timeout = 30
768
+ end
769
+ ```
770
+
771
+ **Authentication Failures:**
772
+ ```ruby
773
+ # Enable request logging to debug
774
+ A2A.configure do |config|
775
+ config.log_requests = true
776
+ config.log_level = :debug
777
+ end
778
+ ```
779
+
780
+ For more configuration help, see the [Troubleshooting Guide](troubleshooting.md).