agentle 0.9.24__py3-none-any.whl → 0.9.26__py3-none-any.whl
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.
- agentle/agents/apis/api.py +25 -7
- agentle/agents/apis/endpoint.py +14 -8
- agentle/agents/whatsapp/human_delay_calculator.py +462 -0
- agentle/agents/whatsapp/models/audio_message.py +6 -4
- agentle/agents/whatsapp/models/whatsapp_bot_config.py +352 -21
- agentle/agents/whatsapp/v2/__init__.py +0 -0
- agentle/agents/whatsapp/v2/batch_processor_manager.py +4 -0
- agentle/agents/whatsapp/v2/bot_config.py +188 -0
- agentle/agents/whatsapp/v2/in_memory_batch_processor_manager.py +0 -0
- agentle/agents/whatsapp/v2/message_limit.py +9 -0
- agentle/agents/whatsapp/v2/payload.py +0 -0
- agentle/agents/whatsapp/v2/whatsapp_bot.py +13 -0
- agentle/agents/whatsapp/v2/whatsapp_cloud_api_provider.py +0 -0
- agentle/agents/whatsapp/v2/whatsapp_provider.py +0 -0
- agentle/agents/whatsapp/whatsapp_bot.py +559 -12
- agentle/web/extractor.py +282 -165
- {agentle-0.9.24.dist-info → agentle-0.9.26.dist-info}/METADATA +1 -1
- {agentle-0.9.24.dist-info → agentle-0.9.26.dist-info}/RECORD +20 -10
- {agentle-0.9.24.dist-info → agentle-0.9.26.dist-info}/WHEEL +0 -0
- {agentle-0.9.24.dist-info → agentle-0.9.26.dist-info}/licenses/LICENSE +0 -0
|
@@ -10,7 +10,65 @@ from agentle.tts.speech_config import SpeechConfig
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class WhatsAppBotConfig(BaseModel):
|
|
13
|
-
"""Configuration for WhatsApp bot behavior with simplified constructors and better organization.
|
|
13
|
+
"""Configuration for WhatsApp bot behavior with simplified constructors and better organization.
|
|
14
|
+
|
|
15
|
+
This configuration class provides comprehensive control over WhatsApp bot behavior including:
|
|
16
|
+
- Core bot behavior (typing indicators, message reading, quoting)
|
|
17
|
+
- Message batching for handling rapid message sequences
|
|
18
|
+
- Spam protection and rate limiting
|
|
19
|
+
- Human-like delays to simulate realistic human behavior patterns
|
|
20
|
+
- Text-to-speech integration
|
|
21
|
+
- Error handling and retry logic
|
|
22
|
+
- Debug and monitoring settings
|
|
23
|
+
|
|
24
|
+
Human-Like Delays Feature:
|
|
25
|
+
The human-like delays feature simulates realistic human behavior patterns by introducing
|
|
26
|
+
configurable delays at three critical points in message processing:
|
|
27
|
+
|
|
28
|
+
1. Read Delay: Time between receiving a message and marking it as read
|
|
29
|
+
- Simulates the time a human takes to read and comprehend a message
|
|
30
|
+
- Calculated based on message length using realistic reading speeds
|
|
31
|
+
|
|
32
|
+
2. Typing Delay: Time between generating a response and sending it
|
|
33
|
+
- Simulates the time a human takes to compose and type a response
|
|
34
|
+
- Calculated based on response length using realistic typing speeds
|
|
35
|
+
|
|
36
|
+
3. Send Delay: Brief final delay before message transmission
|
|
37
|
+
- Simulates the final review time before a human sends a message
|
|
38
|
+
- Random delay within configured bounds
|
|
39
|
+
|
|
40
|
+
These delays help prevent platform detection and account restrictions while
|
|
41
|
+
maintaining natural interaction timing. All delays support jitter (random variation)
|
|
42
|
+
to prevent detectable patterns.
|
|
43
|
+
|
|
44
|
+
Configuration Presets:
|
|
45
|
+
Use the class methods to create pre-configured instances optimized for specific use cases:
|
|
46
|
+
- development(): Fast iteration with delays disabled
|
|
47
|
+
- production(): Balanced configuration with delays enabled
|
|
48
|
+
- high_volume(): Optimized for throughput with balanced delays
|
|
49
|
+
- customer_service(): Professional timing with thoughtful delays
|
|
50
|
+
- minimal(): Bare minimum configuration with delays disabled
|
|
51
|
+
|
|
52
|
+
Examples:
|
|
53
|
+
>>> # Create a production configuration with default delay settings
|
|
54
|
+
>>> config = WhatsAppBotConfig.production()
|
|
55
|
+
|
|
56
|
+
>>> # Create a custom configuration with specific delay bounds
|
|
57
|
+
>>> config = WhatsAppBotConfig(
|
|
58
|
+
... enable_human_delays=True,
|
|
59
|
+
... min_read_delay_seconds=3.0,
|
|
60
|
+
... max_read_delay_seconds=20.0,
|
|
61
|
+
... min_typing_delay_seconds=5.0,
|
|
62
|
+
... max_typing_delay_seconds=60.0
|
|
63
|
+
... )
|
|
64
|
+
|
|
65
|
+
>>> # Override delay settings on an existing configuration
|
|
66
|
+
>>> prod_config = WhatsAppBotConfig.production()
|
|
67
|
+
>>> custom_config = prod_config.with_overrides(
|
|
68
|
+
... min_read_delay_seconds=5.0,
|
|
69
|
+
... max_typing_delay_seconds=90.0
|
|
70
|
+
... )
|
|
71
|
+
"""
|
|
14
72
|
|
|
15
73
|
# === Core Bot Behavior ===
|
|
16
74
|
typing_indicator: bool = Field(
|
|
@@ -110,6 +168,56 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
110
168
|
default=1.0, description="Delay between retry attempts"
|
|
111
169
|
)
|
|
112
170
|
|
|
171
|
+
# === Human-Like Delays ===
|
|
172
|
+
enable_human_delays: bool = Field(
|
|
173
|
+
default=False,
|
|
174
|
+
description="Enable human-like delays for message processing to simulate realistic human behavior patterns",
|
|
175
|
+
)
|
|
176
|
+
min_read_delay_seconds: float = Field(
|
|
177
|
+
default=2.0,
|
|
178
|
+
ge=0.0,
|
|
179
|
+
description="Minimum delay before marking message as read (seconds). Simulates time to read incoming messages.",
|
|
180
|
+
)
|
|
181
|
+
max_read_delay_seconds: float = Field(
|
|
182
|
+
default=15.0,
|
|
183
|
+
ge=0.0,
|
|
184
|
+
description="Maximum delay before marking message as read (seconds). Prevents excessively long read delays.",
|
|
185
|
+
)
|
|
186
|
+
min_typing_delay_seconds: float = Field(
|
|
187
|
+
default=3.0,
|
|
188
|
+
ge=0.0,
|
|
189
|
+
description="Minimum delay before sending response (seconds). Simulates time to compose a response.",
|
|
190
|
+
)
|
|
191
|
+
max_typing_delay_seconds: float = Field(
|
|
192
|
+
default=45.0,
|
|
193
|
+
ge=0.0,
|
|
194
|
+
description="Maximum delay before sending response (seconds). Prevents excessively long typing delays.",
|
|
195
|
+
)
|
|
196
|
+
min_send_delay_seconds: float = Field(
|
|
197
|
+
default=0.5,
|
|
198
|
+
ge=0.0,
|
|
199
|
+
description="Minimum delay before message transmission (seconds). Simulates final message review time.",
|
|
200
|
+
)
|
|
201
|
+
max_send_delay_seconds: float = Field(
|
|
202
|
+
default=4.0,
|
|
203
|
+
ge=0.0,
|
|
204
|
+
description="Maximum delay before message transmission (seconds). Prevents excessively long send delays.",
|
|
205
|
+
)
|
|
206
|
+
enable_delay_jitter: bool = Field(
|
|
207
|
+
default=True,
|
|
208
|
+
description="Enable random variation (±20%) in delay calculations to prevent detectable patterns and simulate natural human behavior variability",
|
|
209
|
+
)
|
|
210
|
+
show_typing_during_delay: bool = Field(
|
|
211
|
+
default=True,
|
|
212
|
+
description="Show typing indicator during typing delays to provide visual feedback to users while the bot is 'composing' a response",
|
|
213
|
+
)
|
|
214
|
+
batch_read_compression_factor: float = Field(
|
|
215
|
+
default=0.7,
|
|
216
|
+
ge=0.1,
|
|
217
|
+
le=1.0,
|
|
218
|
+
description="Compression factor (0.1-1.0) applied to batch read delays. Lower values simulate faster batch reading (e.g., 0.7 = 30% faster than reading individually)",
|
|
219
|
+
)
|
|
220
|
+
|
|
113
221
|
# === Backward Compatibility (Deprecated) ===
|
|
114
222
|
# These are kept for backward compatibility but map to the simplified parameters
|
|
115
223
|
@property
|
|
@@ -170,6 +278,17 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
170
278
|
# Text-to-Speech
|
|
171
279
|
speech_play_chance: float | None = None,
|
|
172
280
|
speech_config: SpeechConfig | None = None,
|
|
281
|
+
# Human-Like Delays
|
|
282
|
+
enable_human_delays: bool | None = None,
|
|
283
|
+
min_read_delay_seconds: float | None = None,
|
|
284
|
+
max_read_delay_seconds: float | None = None,
|
|
285
|
+
min_typing_delay_seconds: float | None = None,
|
|
286
|
+
max_typing_delay_seconds: float | None = None,
|
|
287
|
+
min_send_delay_seconds: float | None = None,
|
|
288
|
+
max_send_delay_seconds: float | None = None,
|
|
289
|
+
enable_delay_jitter: bool | None = None,
|
|
290
|
+
show_typing_during_delay: bool | None = None,
|
|
291
|
+
batch_read_compression_factor: float | None = None,
|
|
173
292
|
) -> "WhatsAppBotConfig":
|
|
174
293
|
"""
|
|
175
294
|
Create a new configuration instance with specified parameters overridden.
|
|
@@ -208,6 +327,16 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
208
327
|
... base_config=hv_config,
|
|
209
328
|
... welcome_message="Welcome to our high-volume support!"
|
|
210
329
|
... )
|
|
330
|
+
|
|
331
|
+
>>> # Enable human-like delays with custom timing
|
|
332
|
+
>>> prod_config = WhatsAppBotConfig.production()
|
|
333
|
+
>>> natural_config = prod_config.with_overrides(
|
|
334
|
+
... enable_human_delays=True,
|
|
335
|
+
... min_read_delay_seconds=3.0,
|
|
336
|
+
... max_read_delay_seconds=20.0,
|
|
337
|
+
... min_typing_delay_seconds=5.0,
|
|
338
|
+
... max_typing_delay_seconds=60.0
|
|
339
|
+
... )
|
|
211
340
|
"""
|
|
212
341
|
# Determine starting configuration
|
|
213
342
|
if base_config is not None:
|
|
@@ -282,6 +411,28 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
282
411
|
if speech_config is not None:
|
|
283
412
|
overrides["speech_config"] = speech_config
|
|
284
413
|
|
|
414
|
+
# Human-Like Delays
|
|
415
|
+
if enable_human_delays is not None:
|
|
416
|
+
overrides["enable_human_delays"] = enable_human_delays
|
|
417
|
+
if min_read_delay_seconds is not None:
|
|
418
|
+
overrides["min_read_delay_seconds"] = min_read_delay_seconds
|
|
419
|
+
if max_read_delay_seconds is not None:
|
|
420
|
+
overrides["max_read_delay_seconds"] = max_read_delay_seconds
|
|
421
|
+
if min_typing_delay_seconds is not None:
|
|
422
|
+
overrides["min_typing_delay_seconds"] = min_typing_delay_seconds
|
|
423
|
+
if max_typing_delay_seconds is not None:
|
|
424
|
+
overrides["max_typing_delay_seconds"] = max_typing_delay_seconds
|
|
425
|
+
if min_send_delay_seconds is not None:
|
|
426
|
+
overrides["min_send_delay_seconds"] = min_send_delay_seconds
|
|
427
|
+
if max_send_delay_seconds is not None:
|
|
428
|
+
overrides["max_send_delay_seconds"] = max_send_delay_seconds
|
|
429
|
+
if enable_delay_jitter is not None:
|
|
430
|
+
overrides["enable_delay_jitter"] = enable_delay_jitter
|
|
431
|
+
if show_typing_during_delay is not None:
|
|
432
|
+
overrides["show_typing_during_delay"] = show_typing_during_delay
|
|
433
|
+
if batch_read_compression_factor is not None:
|
|
434
|
+
overrides["batch_read_compression_factor"] = batch_read_compression_factor
|
|
435
|
+
|
|
285
436
|
# Update configuration with overrides
|
|
286
437
|
current_config.update(overrides)
|
|
287
438
|
|
|
@@ -302,10 +453,22 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
302
453
|
Create a configuration optimized for development.
|
|
303
454
|
|
|
304
455
|
Features:
|
|
305
|
-
- Debug mode enabled
|
|
306
|
-
- Faster response times
|
|
307
|
-
- Lenient rate limiting
|
|
308
|
-
- Detailed logging
|
|
456
|
+
- Debug mode enabled for comprehensive logging
|
|
457
|
+
- Faster response times for quick iteration
|
|
458
|
+
- Lenient rate limiting (100 messages/minute)
|
|
459
|
+
- Detailed logging and performance tracking
|
|
460
|
+
- Human-like delays DISABLED for fast iteration and testing
|
|
461
|
+
- Fast batching (1s delay, 5s timeout)
|
|
462
|
+
|
|
463
|
+
Delay Settings:
|
|
464
|
+
- enable_human_delays: False (disabled for development speed)
|
|
465
|
+
|
|
466
|
+
Use this preset during development and testing when you need fast feedback
|
|
467
|
+
and don't want to wait for realistic human-like delays.
|
|
468
|
+
|
|
469
|
+
Example:
|
|
470
|
+
>>> config = WhatsAppBotConfig.development()
|
|
471
|
+
>>> bot = WhatsAppBot(agent=agent, provider=provider, config=config)
|
|
309
472
|
"""
|
|
310
473
|
return cls(
|
|
311
474
|
# Core behavior
|
|
@@ -329,6 +492,8 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
329
492
|
# Error handling
|
|
330
493
|
retry_failed_messages=True,
|
|
331
494
|
max_retry_attempts=2,
|
|
495
|
+
# Human-like delays (disabled for development)
|
|
496
|
+
enable_human_delays=False,
|
|
332
497
|
)
|
|
333
498
|
|
|
334
499
|
@classmethod
|
|
@@ -343,10 +508,29 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
343
508
|
Create a configuration optimized for production.
|
|
344
509
|
|
|
345
510
|
Features:
|
|
346
|
-
- Robust spam protection
|
|
347
|
-
- Efficient batching
|
|
348
|
-
- Conservative rate limiting
|
|
349
|
-
- Minimal debug output
|
|
511
|
+
- Robust spam protection (20 messages/minute limit)
|
|
512
|
+
- Efficient batching (10s delay, 60s timeout)
|
|
513
|
+
- Conservative rate limiting with 60s cooldown
|
|
514
|
+
- Minimal debug output for performance
|
|
515
|
+
- Human-like delays ENABLED with recommended baseline values
|
|
516
|
+
- Typing indicators shown during delays for user feedback
|
|
517
|
+
|
|
518
|
+
Delay Settings:
|
|
519
|
+
- enable_human_delays: True
|
|
520
|
+
- Read delays: 2.0s - 15.0s (simulates reading incoming messages)
|
|
521
|
+
- Typing delays: 3.0s - 45.0s (simulates composing responses)
|
|
522
|
+
- Send delays: 0.5s - 4.0s (simulates final review)
|
|
523
|
+
- Jitter enabled: ±20% random variation
|
|
524
|
+
- Typing indicator: Shown during typing delays
|
|
525
|
+
- Batch compression: 0.7x (30% faster batch reading)
|
|
526
|
+
|
|
527
|
+
These delay settings provide a good balance between natural behavior and
|
|
528
|
+
reasonable response times. They help prevent platform detection while
|
|
529
|
+
maintaining acceptable user experience.
|
|
530
|
+
|
|
531
|
+
Example:
|
|
532
|
+
>>> config = WhatsAppBotConfig.production()
|
|
533
|
+
>>> bot = WhatsAppBot(agent=agent, provider=provider, config=config)
|
|
350
534
|
"""
|
|
351
535
|
return cls(
|
|
352
536
|
# Core behavior
|
|
@@ -372,6 +556,17 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
372
556
|
retry_failed_messages=True,
|
|
373
557
|
max_retry_attempts=3,
|
|
374
558
|
retry_delay_seconds=1.0,
|
|
559
|
+
# Human-like delays (enabled with baseline values)
|
|
560
|
+
enable_human_delays=True,
|
|
561
|
+
min_read_delay_seconds=2.0,
|
|
562
|
+
max_read_delay_seconds=15.0,
|
|
563
|
+
min_typing_delay_seconds=3.0,
|
|
564
|
+
max_typing_delay_seconds=45.0,
|
|
565
|
+
min_send_delay_seconds=0.5,
|
|
566
|
+
max_send_delay_seconds=4.0,
|
|
567
|
+
enable_delay_jitter=True,
|
|
568
|
+
show_typing_during_delay=True,
|
|
569
|
+
batch_read_compression_factor=0.7,
|
|
375
570
|
)
|
|
376
571
|
|
|
377
572
|
@classmethod
|
|
@@ -385,10 +580,29 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
385
580
|
Create a configuration optimized for high-volume scenarios.
|
|
386
581
|
|
|
387
582
|
Features:
|
|
388
|
-
- Aggressive batching
|
|
389
|
-
- Strong rate limiting
|
|
390
|
-
- Fast processing
|
|
391
|
-
-
|
|
583
|
+
- Aggressive batching (1s delay, 10s timeout, up to 20 messages)
|
|
584
|
+
- Strong rate limiting (15 messages/minute, 120s cooldown)
|
|
585
|
+
- Fast processing with minimal overhead
|
|
586
|
+
- Typing indicators disabled for performance
|
|
587
|
+
- Human-like delays ENABLED with balanced timing optimized for throughput
|
|
588
|
+
|
|
589
|
+
Delay Settings:
|
|
590
|
+
- enable_human_delays: True
|
|
591
|
+
- Read delays: 1.5s - 12.0s (shorter for faster processing)
|
|
592
|
+
- Typing delays: 2.5s - 35.0s (shorter for faster responses)
|
|
593
|
+
- Send delays: 0.3s - 3.0s (shorter for faster transmission)
|
|
594
|
+
- Jitter enabled: ±20% random variation
|
|
595
|
+
- Typing indicator: DISABLED for performance
|
|
596
|
+
- Batch compression: 0.7x (30% faster batch reading)
|
|
597
|
+
|
|
598
|
+
These delay settings are optimized for high-volume scenarios where throughput
|
|
599
|
+
is important but you still want to maintain natural behavior patterns to
|
|
600
|
+
prevent platform detection. Delays are shorter than production but still
|
|
601
|
+
provide realistic timing.
|
|
602
|
+
|
|
603
|
+
Example:
|
|
604
|
+
>>> config = WhatsAppBotConfig.high_volume()
|
|
605
|
+
>>> bot = WhatsAppBot(agent=agent, provider=provider, config=config)
|
|
392
606
|
"""
|
|
393
607
|
return cls(
|
|
394
608
|
# Fast core behavior
|
|
@@ -413,6 +627,17 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
413
627
|
retry_failed_messages=True,
|
|
414
628
|
max_retry_attempts=2, # Fewer retries
|
|
415
629
|
retry_delay_seconds=0.5, # Faster retries
|
|
630
|
+
# Human-like delays (enabled with balanced timing)
|
|
631
|
+
enable_human_delays=True,
|
|
632
|
+
min_read_delay_seconds=1.5,
|
|
633
|
+
max_read_delay_seconds=12.0,
|
|
634
|
+
min_typing_delay_seconds=2.5,
|
|
635
|
+
max_typing_delay_seconds=35.0,
|
|
636
|
+
min_send_delay_seconds=0.3,
|
|
637
|
+
max_send_delay_seconds=3.0,
|
|
638
|
+
enable_delay_jitter=True,
|
|
639
|
+
show_typing_during_delay=False, # Disabled for performance
|
|
640
|
+
batch_read_compression_factor=0.7,
|
|
416
641
|
)
|
|
417
642
|
|
|
418
643
|
@classmethod
|
|
@@ -427,10 +652,30 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
427
652
|
Create a configuration optimized for customer service.
|
|
428
653
|
|
|
429
654
|
Features:
|
|
430
|
-
- Message quoting for context
|
|
431
|
-
- Moderate batching
|
|
432
|
-
- Professional response times
|
|
433
|
-
- Welcome message
|
|
655
|
+
- Message quoting enabled for conversation context
|
|
656
|
+
- Moderate batching (5s delay, 20s timeout, up to 8 messages)
|
|
657
|
+
- Professional response times with thoughtful delays
|
|
658
|
+
- Welcome message for first-time users
|
|
659
|
+
- Human-like delays ENABLED with thoughtful, professional timing
|
|
660
|
+
- Typing indicators shown for premium user experience
|
|
661
|
+
|
|
662
|
+
Delay Settings:
|
|
663
|
+
- enable_human_delays: True
|
|
664
|
+
- Read delays: 5.0s - 30.0s (longer for thoughtful reading)
|
|
665
|
+
- Typing delays: 10.0s - 90.0s (longer for careful composition)
|
|
666
|
+
- Send delays: 1.0s - 5.0s (longer for final review)
|
|
667
|
+
- Jitter enabled: ±20% random variation
|
|
668
|
+
- Typing indicator: Shown during typing delays
|
|
669
|
+
- Batch compression: 0.7x (30% faster batch reading)
|
|
670
|
+
|
|
671
|
+
These delay settings are optimized for customer service scenarios where
|
|
672
|
+
users expect thoughtful, professional responses. Longer delays give the
|
|
673
|
+
impression of careful consideration and attention to detail, which can
|
|
674
|
+
improve perceived service quality.
|
|
675
|
+
|
|
676
|
+
Example:
|
|
677
|
+
>>> config = WhatsAppBotConfig.customer_service()
|
|
678
|
+
>>> bot = WhatsAppBot(agent=agent, provider=provider, config=config)
|
|
434
679
|
"""
|
|
435
680
|
return cls(
|
|
436
681
|
# Professional behavior
|
|
@@ -459,6 +704,17 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
459
704
|
# Custom error message for customer service
|
|
460
705
|
error_message=support_hours_message
|
|
461
706
|
or "I apologize for the inconvenience. Please try again, or contact our support team if the issue persists.",
|
|
707
|
+
# Human-like delays (enabled with thoughtful timing)
|
|
708
|
+
enable_human_delays=True,
|
|
709
|
+
min_read_delay_seconds=5.0,
|
|
710
|
+
max_read_delay_seconds=30.0,
|
|
711
|
+
min_typing_delay_seconds=10.0,
|
|
712
|
+
max_typing_delay_seconds=90.0,
|
|
713
|
+
min_send_delay_seconds=1.0,
|
|
714
|
+
max_send_delay_seconds=5.0,
|
|
715
|
+
enable_delay_jitter=True,
|
|
716
|
+
show_typing_during_delay=True,
|
|
717
|
+
batch_read_compression_factor=0.7,
|
|
462
718
|
)
|
|
463
719
|
|
|
464
720
|
@classmethod
|
|
@@ -471,10 +727,25 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
471
727
|
Create a minimal configuration with basic functionality.
|
|
472
728
|
|
|
473
729
|
Features:
|
|
474
|
-
- No batching
|
|
730
|
+
- No batching for immediate processing
|
|
475
731
|
- No spam protection
|
|
476
|
-
- Immediate responses
|
|
477
|
-
- Minimal overhead
|
|
732
|
+
- Immediate responses with no delays
|
|
733
|
+
- Minimal overhead and resource usage
|
|
734
|
+
- Human-like delays DISABLED for minimal configuration
|
|
735
|
+
- No typing indicators
|
|
736
|
+
- No retry logic
|
|
737
|
+
|
|
738
|
+
Delay Settings:
|
|
739
|
+
- enable_human_delays: False (disabled for minimal overhead)
|
|
740
|
+
|
|
741
|
+
This preset provides the absolute minimum configuration with no delays,
|
|
742
|
+
batching, or spam protection. Use this only when you need the fastest
|
|
743
|
+
possible responses and don't care about natural behavior patterns or
|
|
744
|
+
platform detection.
|
|
745
|
+
|
|
746
|
+
Example:
|
|
747
|
+
>>> config = WhatsAppBotConfig.minimal()
|
|
748
|
+
>>> bot = WhatsAppBot(agent=agent, provider=provider, config=config)
|
|
478
749
|
"""
|
|
479
750
|
return cls(
|
|
480
751
|
# Basic behavior
|
|
@@ -492,14 +763,36 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
492
763
|
# Basic error handling
|
|
493
764
|
retry_failed_messages=False,
|
|
494
765
|
max_retry_attempts=1,
|
|
766
|
+
# Human-like delays (disabled for minimal overhead)
|
|
767
|
+
enable_human_delays=False,
|
|
495
768
|
)
|
|
496
769
|
|
|
497
770
|
def validate_config(self) -> list[str]:
|
|
498
771
|
"""
|
|
499
772
|
Validate configuration and return list of warnings/issues.
|
|
500
773
|
|
|
774
|
+
This method performs comprehensive validation of all configuration parameters,
|
|
775
|
+
including timing conflicts, rate limiting settings, retry configuration, and
|
|
776
|
+
human-like delay parameters.
|
|
777
|
+
|
|
778
|
+
Delay Validation:
|
|
779
|
+
When human-like delays are enabled, this method validates:
|
|
780
|
+
- All minimum delay values are non-negative (>= 0.0)
|
|
781
|
+
- All maximum delay values are >= their corresponding minimum values
|
|
782
|
+
- Batch read compression factor is between 0.1 and 1.0
|
|
783
|
+
|
|
501
784
|
Returns:
|
|
502
|
-
List of validation messages (empty if
|
|
785
|
+
List of validation messages (empty if configuration is valid).
|
|
786
|
+
Each message describes a specific configuration issue or warning.
|
|
787
|
+
|
|
788
|
+
Example:
|
|
789
|
+
>>> config = WhatsAppBotConfig.production()
|
|
790
|
+
>>> issues = config.validate_config()
|
|
791
|
+
>>> if issues:
|
|
792
|
+
... for issue in issues:
|
|
793
|
+
... print(f"Warning: {issue}")
|
|
794
|
+
... else:
|
|
795
|
+
... print("Configuration is valid")
|
|
503
796
|
"""
|
|
504
797
|
issues = []
|
|
505
798
|
|
|
@@ -542,6 +835,44 @@ class WhatsAppBotConfig(BaseModel):
|
|
|
542
835
|
+ "Messages will be truncated."
|
|
543
836
|
)
|
|
544
837
|
|
|
838
|
+
# Check human-like delay configuration
|
|
839
|
+
if self.enable_human_delays:
|
|
840
|
+
# Validate read delays
|
|
841
|
+
if self.min_read_delay_seconds < 0.0:
|
|
842
|
+
issues.append(
|
|
843
|
+
f"min_read_delay_seconds ({self.min_read_delay_seconds}) must be non-negative (>= 0.0)."
|
|
844
|
+
)
|
|
845
|
+
if self.max_read_delay_seconds < self.min_read_delay_seconds:
|
|
846
|
+
issues.append(
|
|
847
|
+
f"max_read_delay_seconds ({self.max_read_delay_seconds}) must be >= min_read_delay_seconds ({self.min_read_delay_seconds})."
|
|
848
|
+
)
|
|
849
|
+
|
|
850
|
+
# Validate typing delays
|
|
851
|
+
if self.min_typing_delay_seconds < 0.0:
|
|
852
|
+
issues.append(
|
|
853
|
+
f"min_typing_delay_seconds ({self.min_typing_delay_seconds}) must be non-negative (>= 0.0)."
|
|
854
|
+
)
|
|
855
|
+
if self.max_typing_delay_seconds < self.min_typing_delay_seconds:
|
|
856
|
+
issues.append(
|
|
857
|
+
f"max_typing_delay_seconds ({self.max_typing_delay_seconds}) must be >= min_typing_delay_seconds ({self.min_typing_delay_seconds})."
|
|
858
|
+
)
|
|
859
|
+
|
|
860
|
+
# Validate send delays
|
|
861
|
+
if self.min_send_delay_seconds < 0.0:
|
|
862
|
+
issues.append(
|
|
863
|
+
f"min_send_delay_seconds ({self.min_send_delay_seconds}) must be non-negative (>= 0.0)."
|
|
864
|
+
)
|
|
865
|
+
if self.max_send_delay_seconds < self.min_send_delay_seconds:
|
|
866
|
+
issues.append(
|
|
867
|
+
f"max_send_delay_seconds ({self.max_send_delay_seconds}) must be >= min_send_delay_seconds ({self.min_send_delay_seconds})."
|
|
868
|
+
)
|
|
869
|
+
|
|
870
|
+
# Validate batch read compression factor
|
|
871
|
+
if not (0.1 <= self.batch_read_compression_factor <= 1.0):
|
|
872
|
+
issues.append(
|
|
873
|
+
f"batch_read_compression_factor ({self.batch_read_compression_factor}) must be between 0.1 and 1.0."
|
|
874
|
+
)
|
|
875
|
+
|
|
545
876
|
return issues
|
|
546
877
|
|
|
547
878
|
def __str__(self) -> str:
|
|
File without changes
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from rsb.models.base_model import BaseModel
|
|
4
|
+
from rsb.models.field import Field
|
|
5
|
+
|
|
6
|
+
from agentle.agents.whatsapp.v2.message_limit import MessageLimit
|
|
7
|
+
from agentle.tts.speech_config import SpeechConfig
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class BotConfig(BaseModel):
|
|
11
|
+
"""Configuration for WhatsApp bot behavior with simplified constructors and better organization.
|
|
12
|
+
|
|
13
|
+
This configuration class provides comprehensive control over WhatsApp bot behavior including:
|
|
14
|
+
- Core bot behavior (typing indicators, message reading, quoting)
|
|
15
|
+
- Message batching for handling rapid message sequences
|
|
16
|
+
- Spam protection and rate limiting
|
|
17
|
+
- Human-like delays to simulate realistic human behavior patterns
|
|
18
|
+
- Text-to-speech integration
|
|
19
|
+
- Error handling and retry logic
|
|
20
|
+
- Debug and monitoring settings
|
|
21
|
+
|
|
22
|
+
Human-Like Delays Feature:
|
|
23
|
+
The human-like delays feature simulates realistic human behavior patterns by introducing
|
|
24
|
+
configurable delays at three critical points in message processing:
|
|
25
|
+
|
|
26
|
+
1. Read Delay: Time between receiving a message and marking it as read
|
|
27
|
+
- Simulates the time a human takes to read and comprehend a message
|
|
28
|
+
- Calculated based on message length using realistic reading speeds
|
|
29
|
+
|
|
30
|
+
2. Typing Delay: Time between generating a response and sending it
|
|
31
|
+
- Simulates the time a human takes to compose and type a response
|
|
32
|
+
- Calculated based on response length using realistic typing speeds
|
|
33
|
+
|
|
34
|
+
3. Send Delay: Brief final delay before message transmission
|
|
35
|
+
- Simulates the final review time before a human sends a message
|
|
36
|
+
- Random delay within configured bounds
|
|
37
|
+
|
|
38
|
+
These delays help prevent platform detection and account restrictions while
|
|
39
|
+
maintaining natural interaction timing. All delays support jitter (random variation)
|
|
40
|
+
to prevent detectable patterns.
|
|
41
|
+
|
|
42
|
+
Configuration Presets:
|
|
43
|
+
Use the class methods to create pre-configured instances optimized for specific use cases:
|
|
44
|
+
- development(): Fast iteration with delays disabled
|
|
45
|
+
- production(): Balanced configuration with delays enabled
|
|
46
|
+
- high_volume(): Optimized for throughput with balanced delays
|
|
47
|
+
- customer_service(): Professional timing with thoughtful delays
|
|
48
|
+
- minimal(): Bare minimum configuration with delays disabled
|
|
49
|
+
|
|
50
|
+
Examples:
|
|
51
|
+
>>> # Create a production configuration with default delay settings
|
|
52
|
+
>>> config = BotConfig.production()
|
|
53
|
+
|
|
54
|
+
>>> # Create a custom configuration with specific delay bounds
|
|
55
|
+
>>> config = BotConfig(
|
|
56
|
+
... enable_human_delays=True,
|
|
57
|
+
... min_read_delay_seconds=3.0,
|
|
58
|
+
... max_read_delay_seconds=20.0,
|
|
59
|
+
... min_typing_delay_seconds=5.0,
|
|
60
|
+
... max_typing_delay_seconds=60.0
|
|
61
|
+
... )
|
|
62
|
+
|
|
63
|
+
>>> # Override delay settings on an existing configuration
|
|
64
|
+
>>> prod_config = BotConfig.production()
|
|
65
|
+
>>> custom_config = prod_config.with_overrides(
|
|
66
|
+
... min_read_delay_seconds=5.0,
|
|
67
|
+
... max_typing_delay_seconds=90.0
|
|
68
|
+
... )
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
quote_messages: bool = Field(
|
|
72
|
+
default=False, description="Whether to quote user messages in replies"
|
|
73
|
+
)
|
|
74
|
+
session_timeout_minutes: int = Field(
|
|
75
|
+
default=30, description="Minutes of inactivity before session reset"
|
|
76
|
+
)
|
|
77
|
+
max_message_length: MessageLimit = Field(
|
|
78
|
+
default=MessageLimit.NEWLY_CREATED,
|
|
79
|
+
description="Maximum message length (WhatsApp limit)",
|
|
80
|
+
)
|
|
81
|
+
max_split_messages: int = Field(
|
|
82
|
+
default=5,
|
|
83
|
+
description="Maximum number of split messages to send (remaining will be grouped)",
|
|
84
|
+
)
|
|
85
|
+
error_message: str = Field(
|
|
86
|
+
default="Sorry, I encountered an error processing your message. Please try again.",
|
|
87
|
+
description="Default error message",
|
|
88
|
+
)
|
|
89
|
+
welcome_message: str | None = Field(
|
|
90
|
+
default=None, description="Message to send on first interaction"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
# === Message Batching (Simplified) ===
|
|
94
|
+
enable_message_batching: bool = Field(
|
|
95
|
+
default=True, description="Enable message batching to prevent spam"
|
|
96
|
+
)
|
|
97
|
+
batch_delay_seconds: float = Field(
|
|
98
|
+
default=15.0,
|
|
99
|
+
description="Time to wait for additional messages before processing batch",
|
|
100
|
+
)
|
|
101
|
+
max_batch_size: int = Field(
|
|
102
|
+
default=10, description="Maximum number of messages to batch together"
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# === Spam Protection ===
|
|
106
|
+
spam_protection_enabled: bool = Field(
|
|
107
|
+
default=True, description="Enable spam protection mechanisms"
|
|
108
|
+
)
|
|
109
|
+
min_message_interval_seconds: float = Field(
|
|
110
|
+
default=1,
|
|
111
|
+
description="Minimum interval between processing messages from same user",
|
|
112
|
+
)
|
|
113
|
+
max_messages_per_minute: int = Field(
|
|
114
|
+
default=20,
|
|
115
|
+
description="Maximum messages per minute per user before rate limiting",
|
|
116
|
+
)
|
|
117
|
+
rate_limit_cooldown_seconds: int = Field(
|
|
118
|
+
default=60, description="Cooldown period after rate limit is triggered"
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
# === Text-to-Speech (TTS) ===
|
|
122
|
+
speech_play_chance: float = Field(
|
|
123
|
+
default=0.0,
|
|
124
|
+
ge=0.0,
|
|
125
|
+
le=1.0,
|
|
126
|
+
description="Probability (0.0-1.0) of sending audio response instead of text",
|
|
127
|
+
)
|
|
128
|
+
speech_config: SpeechConfig | None = Field(
|
|
129
|
+
default=None,
|
|
130
|
+
description="Optional SpeechConfig for TTS provider customization",
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
# === Error Handling ===
|
|
134
|
+
retry_failed_messages: bool = Field(
|
|
135
|
+
default=True, description="Retry processing failed messages"
|
|
136
|
+
)
|
|
137
|
+
max_retry_attempts: int = Field(
|
|
138
|
+
default=3, description="Maximum number of retry attempts for failed messages"
|
|
139
|
+
)
|
|
140
|
+
retry_delay_seconds: float = Field(
|
|
141
|
+
default=1.0, description="Delay between retry attempts"
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
# === Human-Like Delays ===
|
|
145
|
+
enable_human_delays: bool = Field(
|
|
146
|
+
default=False,
|
|
147
|
+
description="Enable human-like delays for message processing to simulate realistic human behavior patterns",
|
|
148
|
+
)
|
|
149
|
+
min_read_delay_seconds: float = Field(
|
|
150
|
+
default=2.0,
|
|
151
|
+
ge=0.0,
|
|
152
|
+
description="Minimum delay before marking message as read (seconds). Simulates time to read incoming messages.",
|
|
153
|
+
)
|
|
154
|
+
max_read_delay_seconds: float = Field(
|
|
155
|
+
default=15.0,
|
|
156
|
+
ge=0.0,
|
|
157
|
+
description="Maximum delay before marking message as read (seconds). Prevents excessively long read delays.",
|
|
158
|
+
)
|
|
159
|
+
min_typing_delay_seconds: float = Field(
|
|
160
|
+
default=3.0,
|
|
161
|
+
ge=0.0,
|
|
162
|
+
description="Minimum delay before sending response (seconds). Simulates time to compose a response.",
|
|
163
|
+
)
|
|
164
|
+
max_typing_delay_seconds: float = Field(
|
|
165
|
+
default=45.0,
|
|
166
|
+
ge=0.0,
|
|
167
|
+
description="Maximum delay before sending response (seconds). Prevents excessively long typing delays.",
|
|
168
|
+
)
|
|
169
|
+
min_send_delay_seconds: float = Field(
|
|
170
|
+
default=0.5,
|
|
171
|
+
ge=0.0,
|
|
172
|
+
description="Minimum delay before message transmission (seconds). Simulates final message review time.",
|
|
173
|
+
)
|
|
174
|
+
max_send_delay_seconds: float = Field(
|
|
175
|
+
default=4.0,
|
|
176
|
+
ge=0.0,
|
|
177
|
+
description="Maximum delay before message transmission (seconds). Prevents excessively long send delays.",
|
|
178
|
+
)
|
|
179
|
+
enable_delay_jitter: bool = Field(
|
|
180
|
+
default=True,
|
|
181
|
+
description="Enable random variation (±20%) in delay calculations to prevent detectable patterns and simulate natural human behavior variability",
|
|
182
|
+
)
|
|
183
|
+
batch_read_compression_factor: float = Field(
|
|
184
|
+
default=0.7,
|
|
185
|
+
ge=0.1,
|
|
186
|
+
le=1.0,
|
|
187
|
+
description="Compression factor (0.1-1.0) applied to batch read delays. Lower values simulate faster batch reading (e.g., 0.7 = 30% faster than reading individually)",
|
|
188
|
+
)
|
|
File without changes
|