flock-core 0.5.21__py3-none-any.whl → 0.5.23__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.

Potentially problematic release.


This version of flock-core might be problematic. Click here for more details.

@@ -0,0 +1,976 @@
1
+ Metadata-Version: 2.4
2
+ Name: flock-core
3
+ Version: 0.5.23
4
+ Summary: Flock: A declrative framework for building and orchestrating AI agents.
5
+ Author-email: Andre Ratzenberger <andre.ratzenberger@whiteduck.de>
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.12
9
+ Requires-Dist: aiosqlite>=0.20.0
10
+ Requires-Dist: devtools>=0.12.2
11
+ Requires-Dist: dspy==3.0.3
12
+ Requires-Dist: duckdb>=1.1.0
13
+ Requires-Dist: fastapi>=0.117.1
14
+ Requires-Dist: hanging-threads>=2.0.7
15
+ Requires-Dist: httpx>=0.28.1
16
+ Requires-Dist: litellm==1.78.0
17
+ Requires-Dist: loguru>=0.7.3
18
+ Requires-Dist: mcp>=1.7.1
19
+ Requires-Dist: opentelemetry-api>=1.30.0
20
+ Requires-Dist: opentelemetry-exporter-jaeger-proto-grpc>=1.21.0
21
+ Requires-Dist: opentelemetry-exporter-jaeger>=1.21.0
22
+ Requires-Dist: opentelemetry-exporter-otlp>=1.30.0
23
+ Requires-Dist: opentelemetry-instrumentation-logging>=0.51b0
24
+ Requires-Dist: opentelemetry-sdk>=1.30.0
25
+ Requires-Dist: poethepoet>=0.30.0
26
+ Requires-Dist: pydantic[email]>=2.11.9
27
+ Requires-Dist: rich>=14.1.0
28
+ Requires-Dist: toml>=0.10.2
29
+ Requires-Dist: typer>=0.19.2
30
+ Requires-Dist: uvicorn>=0.37.0
31
+ Requires-Dist: websockets>=15.0.1
32
+ Provides-Extra: semantic
33
+ Requires-Dist: sentence-transformers>=3.0.0; extra == 'semantic'
34
+ Description-Content-Type: text/markdown
35
+
36
+ <p align="center">
37
+ <img alt="Flock Banner" src="docs/assets/images/flock.png" width="800">
38
+ </p>
39
+ <p align="center">
40
+ <a href="https://whiteducksoftware.github.io/flock/" target="_blank"><img alt="Documentation" src="https://img.shields.io/badge/docs-online-blue?style=for-the-badge&logo=readthedocs"></a>
41
+ <a href="https://pypi.org/project/flock-core/" target="_blank"><img alt="PyPI Version" src="https://img.shields.io/pypi/v/flock-core?style=for-the-badge&logo=pypi&label=pip%20version"></a>
42
+ <img alt="Python Version" src="https://img.shields.io/badge/python-3.12%2B-blue?style=for-the-badge&logo=python">
43
+ <a href="LICENSE" target="_blank"><img alt="License" src="https://img.shields.io/github/license/whiteducksoftware/flock?style=for-the-badge"></a>
44
+ <a href="https://whiteduck.de" target="_blank"><img alt="Built by white duck" src="https://img.shields.io/badge/Built%20by-white%20duck%20GmbH-white?style=for-the-badge&labelColor=black"></a>
45
+ <a href="https://codecov.io/gh/whiteducksoftware/flock" target="_blank"><img alt="Test Coverage" src="https://codecov.io/gh/whiteducksoftware/flock/branch/main/graph/badge.svg?token=YOUR_TOKEN_HERE&style=for-the-badge"></a>
46
+ <img alt="Tests" src="https://img.shields.io/badge/tests-1400+-brightgreen?style=for-the-badge">
47
+ </p>
48
+
49
+ ---
50
+
51
+ # Flock 0.5: Declarative Blackboard Multi-Agent Orchestration
52
+
53
+ > **Stop engineering prompts. Start declaring contracts.**
54
+
55
+ Flock is a production-focused framework for orchestrating AI agents through **declarative type contracts** and **blackboard architecture**—proven patterns from distributed systems, decades of microservice experience, and classical AI—now applied to modern LLMs.
56
+
57
+ **📖 [Read the full documentation →](https://whiteducksoftware.github.io/flock)**
58
+
59
+ **Quick links:**
60
+ - **[Getting Started](https://whiteducksoftware.github.io/flock/getting-started/installation/)** - Installation and first steps
61
+ - **[Tutorials](https://whiteducksoftware.github.io/flock/tutorials/)** - Step-by-step learning path
62
+ - **[User Guides](https://whiteducksoftware.github.io/flock/guides/)** - In-depth feature documentation
63
+ - **[API Reference](https://whiteducksoftware.github.io/flock/reference/api/)** - Complete API documentation
64
+ - **[Roadmap](https://whiteducksoftware.github.io/flock/about/roadmap/)** - What's coming in v1.0
65
+ - **[Changelog](https://whiteducksoftware.github.io/flock/about/changelog/)** - Recent new features and version history
66
+
67
+ ---
68
+
69
+ ## The Problem With Current Approaches
70
+
71
+ Building production multi-agent systems today means dealing with:
72
+
73
+ **🔥 Prompt Engineering Hell**
74
+ ```python
75
+ prompt = """You are an expert code reviewer. When you receive code, you should...
76
+ [498 more lines of instructions that the LLM ignores half the time]"""
77
+
78
+ # 500-line prompt that breaks when models update
79
+ # How do I know this is the best prompt? (you don't)
80
+ # Proving 'best possible performance' is impossible
81
+ ```
82
+
83
+ **🧪 Testing Nightmares**
84
+ ```python
85
+ # How do you unit test this?
86
+ result = llm.invoke(prompt) # Hope for valid JSON
87
+ data = json.loads(result.content) # Crashes in production
88
+ ```
89
+
90
+ **📐 Rigid Topology & Tight Coupling**
91
+ ```python
92
+ # Want to add a new agent? Rewrite the entire graph.
93
+ workflow.add_edge("agent_a", "agent_b")
94
+ workflow.add_edge("agent_b", "agent_c")
95
+ # Add agent_d? Start rewiring...
96
+ ```
97
+
98
+ **💀 Single Point of Failure**
99
+ ```python
100
+ # Orchestrator dies? Everything dies.
101
+ ```
102
+
103
+ **🧠 God Object Anti-Pattern**
104
+ ```python
105
+ # One orchestrator needs domain knowledge of 20+ agents to route correctly
106
+ # Orchestrator 'guesses' next agent based on natural language
107
+ # Not suitable for critical systems
108
+ ```
109
+
110
+ These aren't framework limitations—they're **architectural choices** that don't scale. Decades of microservice experience have taught us about decoupling, orchestration, and reliability. Let's apply those lessons!
111
+
112
+ ---
113
+
114
+ ## The Flock Approach
115
+
116
+ Flock combines two proven patterns:
117
+
118
+ ### 1. Declarative Type Contracts (Not Prompts)
119
+
120
+ **Traditional approach:**
121
+ ```python
122
+ prompt = """You are an expert bug analyst. Analyze bug reports and provide structured diagnostics.
123
+
124
+ INSTRUCTIONS:
125
+ 1. Read the bug report carefully
126
+ 2. Determine severity (Critical|High|Medium|Low)
127
+ 3. Classify bug category
128
+ 4. Formulate root cause hypothesis (minimum 50 characters)
129
+ 5. Assign confidence score (0.0-1.0)
130
+
131
+ OUTPUT FORMAT:
132
+ You MUST return valid JSON with this exact structure:
133
+ {
134
+ "severity": "string (Critical|High|Medium|Low)",
135
+ "category": "string",
136
+ "root_cause_hypothesis": "string (minimum 50 characters)",
137
+ "confidence_score": "number (0.0 to 1.0)"
138
+ }
139
+
140
+ VALIDATION RULES:
141
+ - severity: Must be exactly one of: Critical, High, Medium, Low
142
+ - category: Must be a single word or short phrase
143
+ - root_cause_hypothesis: Must be at least 50 characters
144
+ - confidence_score: Must be between 0.0 and 1.0
145
+
146
+ [...hundreds more lines...]"""
147
+
148
+ result = llm.invoke(prompt) # 500-line prompt that breaks
149
+ data = json.loads(result.content) # Crashes in production 🔥
150
+ ```
151
+
152
+ **The Flock way:**
153
+ ```python
154
+ @flock_type
155
+ class BugDiagnosis(BaseModel):
156
+ severity: str = Field(pattern="^(Critical|High|Medium|Low)$")
157
+ category: str = Field(description="Bug category")
158
+ root_cause_hypothesis: str = Field(min_length=50)
159
+ confidence_score: float = Field(ge=0.0, le=1.0)
160
+
161
+ # The schema IS the instruction. No 500-line prompt needed.
162
+ agent.consumes(BugReport).publishes(BugDiagnosis)
163
+ ```
164
+
165
+ <p align="center">
166
+ <img alt="Bug Diagnosis" src="docs/assets/images/bug_diagnosis.png" width="1000">
167
+ </p>
168
+
169
+ **Why this matters:**
170
+ - ✅ **Survives model upgrades** - GPT-6 will still understand Pydantic schemas
171
+ - ✅ **Runtime validation** - Errors caught at parse time, not in production
172
+ - ✅ **Testable** - Mock inputs/outputs with concrete types
173
+ - ✅ **Self-documenting** - The code tells you what agents do
174
+
175
+ ### 2. Blackboard Architecture (Not Directed Graphs)
176
+
177
+ **Graph-based approach:**
178
+ ```python
179
+ # Explicit workflow with hardcoded edges
180
+ workflow.add_edge("radiologist", "diagnostician")
181
+ workflow.add_edge("lab_tech", "diagnostician")
182
+ # Add performance_analyzer? Rewrite the graph.
183
+ ```
184
+
185
+ **The Flock way (blackboard):**
186
+ ```python
187
+ # Agents subscribe to types, workflows emerge
188
+ radiologist = flock.agent("radiologist").consumes(Scan).publishes(XRayAnalysis)
189
+ lab_tech = flock.agent("lab_tech").consumes(Scan).publishes(LabResults)
190
+ diagnostician = flock.agent("diagnostician").consumes(XRayAnalysis, LabResults).publishes(Diagnosis)
191
+
192
+ # Add performance_analyzer? Just subscribe it:
193
+ performance = flock.agent("perf").consumes(Scan).publishes(PerfAnalysis)
194
+ # Done. No graph rewiring. Diagnostician can optionally consume it.
195
+ ```
196
+
197
+ **What just happened:**
198
+ - ✅ **Parallel execution** - Radiologist and lab_tech run concurrently (automatic)
199
+ - ✅ **Dependency resolution** - Diagnostician waits for both inputs (automatic)
200
+ - ✅ **Loose coupling** - Agents don't know about each other, just data types
201
+ - ✅ **Scalable** - O(n) complexity, not O(n²) edges
202
+
203
+ **This is not a new idea.** Blackboard architecture has powered AI systems since the 1970s (Hearsay-II, HASP/SIAP, BB1). We're applying proven patterns to modern LLMs.
204
+
205
+ ---
206
+
207
+ ## Quick Start (60 Seconds)
208
+
209
+ ```bash
210
+ pip install flock-core
211
+ export OPENAI_API_KEY="sk-..."
212
+ export DEFAULT_MODEL="openai/gpt-4.1" # Optional, has defaults
213
+ ```
214
+
215
+ ```python
216
+ import os
217
+ import asyncio
218
+ from pydantic import BaseModel, Field
219
+ from flock import Flock, flock_type
220
+
221
+ # 1. Define typed artifacts
222
+ @flock_type
223
+ class CodeSubmission(BaseModel):
224
+ code: str
225
+ language: str
226
+
227
+ @flock_type
228
+ class BugAnalysis(BaseModel):
229
+ bugs_found: list[str]
230
+ severity: str = Field(pattern="^(Critical|High|Medium|Low|None)$")
231
+ confidence: float = Field(ge=0.0, le=1.0)
232
+
233
+ @flock_type
234
+ class SecurityAnalysis(BaseModel):
235
+ vulnerabilities: list[str]
236
+ risk_level: str = Field(pattern="^(Critical|High|Medium|Low|None)$")
237
+
238
+ @flock_type
239
+ class FinalReview(BaseModel):
240
+ overall_assessment: str = Field(pattern="^(Approve|Approve with Changes|Reject)$")
241
+ action_items: list[str]
242
+
243
+ # 2. Create the blackboard
244
+ flock = Flock(os.getenv("DEFAULT_MODEL", "openai/gpt-4.1"))
245
+
246
+ # 3. Agents subscribe to types (NO graph wiring!)
247
+ bug_detector = flock.agent("bug_detector").consumes(CodeSubmission).publishes(BugAnalysis)
248
+ security_auditor = flock.agent("security_auditor").consumes(CodeSubmission).publishes(SecurityAnalysis)
249
+
250
+ # AND gate: This agent AUTOMATICALLY waits for BOTH analyses
251
+ final_reviewer = flock.agent("final_reviewer").consumes(BugAnalysis, SecurityAnalysis).publishes(FinalReview)
252
+
253
+ # 4. Run with real-time dashboard
254
+ async def main():
255
+ await flock.serve(dashboard=True)
256
+
257
+ asyncio.run(main())
258
+ ```
259
+
260
+ **What happened:**
261
+ - Bug detector and security auditor ran **in parallel**
262
+ - Final reviewer **automatically waited** for both
263
+ - **Zero prompts written** - types defined the behavior
264
+ - **Zero graph edges** - subscriptions created the workflow
265
+ - **Full type safety** - Pydantic validates all outputs
266
+
267
+ ---
268
+
269
+ ## Core Features
270
+
271
+ ### Typed Artifacts
272
+
273
+ Every piece of data is a validated Pydantic model:
274
+
275
+ ```python
276
+ @flock_type
277
+ class PatientDiagnosis(BaseModel):
278
+ condition: str = Field(min_length=10)
279
+ confidence: float = Field(ge=0.0, le=1.0)
280
+ recommended_treatment: list[str] = Field(min_length=1)
281
+ follow_up_required: bool
282
+ ```
283
+
284
+ **Benefits:**
285
+ - Runtime validation ensures quality
286
+ - Field constraints prevent bad outputs
287
+ - Self-documenting data structures
288
+ - Version-safe (types survive model updates)
289
+
290
+ ### Agent Subscriptions with Logic Gates
291
+
292
+ **AND Gates - Wait for ALL types:**
293
+ ```python
294
+ # Wait for BOTH types before triggering
295
+ diagnostician = flock.agent("diagnostician").consumes(XRayAnalysis, LabResults).publishes(Diagnosis)
296
+ ```
297
+
298
+ **OR Gates - Trigger on ANY type:**
299
+ ```python
300
+ # Trigger when EITHER type arrives (via chaining)
301
+ alert_handler = flock.agent("alerts").consumes(SystemAlert).consumes(UserAlert).publishes(Response)
302
+ ```
303
+
304
+ **Count-Based AND Gates:**
305
+ ```python
306
+ # Wait for THREE Orders
307
+ aggregator = flock.agent("aggregator").consumes(Order, Order, Order).publishes(BatchSummary)
308
+
309
+ # Wait for TWO Images AND ONE Metadata
310
+ validator = flock.agent("validator").consumes(Image, Image, Metadata).publishes(ValidationResult)
311
+ ```
312
+
313
+ ### 🧠 Semantic Subscriptions (New in 0.5!)
314
+
315
+ **Match artifacts by MEANING, not keywords:**
316
+
317
+ ```python
318
+ # Install semantic extras
319
+ pip install flock-core[semantic]
320
+
321
+ # Agents route based on semantic similarity
322
+ security_team = (
323
+ flock.agent("security_team")
324
+ .consumes(SupportTicket, semantic_match="security vulnerability exploit")
325
+ .publishes(SecurityAlert)
326
+ )
327
+
328
+ billing_team = (
329
+ flock.agent("billing_team")
330
+ .consumes(SupportTicket, semantic_match="payment charge refund billing")
331
+ .publishes(BillingResponse)
332
+ )
333
+
334
+ # Tickets route automatically based on MEANING!
335
+ # "SQL injection" → Security Team (no keyword "security" needed!)
336
+ # "charged twice" → Billing Team (semantic match to "payment")
337
+ ```
338
+
339
+ **Advanced semantic filtering:**
340
+ ```python
341
+ # Custom threshold (0.0-1.0, default 0.4)
342
+ .consumes(Ticket, semantic_match="urgent", semantic_threshold=0.7) # Strict
343
+
344
+ # Multiple criteria (ALL must match)
345
+ .consumes(Doc, semantic_match=["security", "compliance"]) # AND logic
346
+
347
+ # Field-specific matching
348
+ .consumes(Article, semantic_match={
349
+ "query": "machine learning",
350
+ "threshold": 0.6,
351
+ "field": "abstract" # Only match this field
352
+ })
353
+ ```
354
+
355
+ **Why this is revolutionary:**
356
+ - ✅ **No keyword brittleness** - "SQL injection" matches "security vulnerability"
357
+ - ✅ **Better recall** - Catches semantically similar content
358
+ - ✅ **Local embeddings** - all-MiniLM-L6-v2 model (~90MB), no external API
359
+ - ✅ **Fast & cached** - LRU cache with 10k entries, ~15ms per embedding
360
+
361
+ **📖 [Full Semantic Guide →](docs/semantic-subscriptions.md)**
362
+
363
+ ### Advanced Subscription Patterns
364
+
365
+ <p align="center">
366
+ <img alt="Event Join" src="docs/assets/images/join.png" width="800">
367
+ </p>
368
+
369
+ **Predicates - Smart Filtering:**
370
+ ```python
371
+ # Only process critical cases
372
+ urgent_care = flock.agent("urgent").consumes(
373
+ Diagnosis,
374
+ where=lambda d: d.severity in ["Critical", "High"]
375
+ )
376
+ ```
377
+
378
+ **BatchSpec - Cost Optimization:**
379
+ ```python
380
+ # Process 25 at once = 96% cheaper API calls!
381
+ payment_processor = flock.agent("payments").consumes(
382
+ Transaction,
383
+ batch=BatchSpec(size=25, timeout=timedelta(seconds=30))
384
+ )
385
+ ```
386
+
387
+ **JoinSpec - Data Correlation:**
388
+ ```python
389
+ # Match orders + shipments by ID
390
+ customer_service = flock.agent("notifications").consumes(
391
+ Order,
392
+ Shipment,
393
+ join=JoinSpec(by=lambda x: x.order_id, within=timedelta(hours=24))
394
+ )
395
+ ```
396
+
397
+ **Combined - Production Pipelines:**
398
+ ```python
399
+ # Correlate sensors, THEN batch for analysis
400
+ quality_control = flock.agent("qc").consumes(
401
+ TemperatureSensor,
402
+ PressureSensor,
403
+ join=JoinSpec(by=lambda x: x.device_id, within=timedelta(seconds=30)),
404
+ batch=BatchSpec(size=5, timeout=timedelta(seconds=45))
405
+ )
406
+ ```
407
+
408
+ <p align="center">
409
+ <img alt="Event Batch" src="docs/assets/images/batch.png" width="800">
410
+ </p>
411
+
412
+ ### 🌟 Fan-Out Publishing
413
+
414
+ **Produce multiple outputs from a single execution:**
415
+
416
+ ```python
417
+ # Generate 10 diverse product ideas from one brief
418
+ idea_generator = (
419
+ flock.agent("generator")
420
+ .consumes(ProductBrief)
421
+ .publishes(ProductIdea, fan_out=10)
422
+ )
423
+
424
+ # With quality filtering
425
+ idea_generator = (
426
+ flock.agent("generator")
427
+ .consumes(ProductBrief)
428
+ .publishes(
429
+ ProductIdea,
430
+ fan_out=20, # Generate 20 candidates
431
+ where=lambda idea: idea.score >= 8.0 # Only publish score >= 8
432
+ )
433
+ )
434
+ ```
435
+
436
+ **Multi-Output Fan-Out (The Mind-Blowing Part):**
437
+
438
+ ```python
439
+ # Generate 3 of EACH type = 9 total artifacts in ONE LLM call!
440
+ multi_master = (
441
+ flock.agent("multi_master")
442
+ .consumes(Idea)
443
+ .publishes(Movie, MovieScript, MovieCampaign, fan_out=3)
444
+ )
445
+
446
+ # Single execution produces:
447
+ # - 3 complete Movies (title, genre, cast, plot)
448
+ # - 3 complete MovieScripts (characters, scenes, pages)
449
+ # - 3 complete MovieCampaigns (taglines, posters)
450
+ # = 9 complex artifacts, 100+ fields, full validation, ONE LLM call!
451
+ ```
452
+
453
+ **📖 [Full Fan-Out Guide →](https://whiteducksoftware.github.io/flock/guides/fan-out/)**
454
+
455
+ ### 🔒 Zero-Trust Visibility Controls
456
+
457
+ **Built-in security (not bolt-on):**
458
+
459
+ ```python
460
+ # Multi-tenancy (SaaS isolation)
461
+ agent.publishes(CustomerData, visibility=TenantVisibility(tenant_id="customer_123"))
462
+
463
+ # Explicit allowlist (HIPAA compliance)
464
+ agent.publishes(MedicalRecord, visibility=PrivateVisibility(agents={"physician", "nurse"}))
465
+
466
+ # Role-based access control
467
+ agent.identity(AgentIdentity(name="analyst", labels={"clearance:secret"}))
468
+ agent.publishes(IntelReport, visibility=LabelledVisibility(required_labels={"clearance:secret"}))
469
+
470
+ # Time-delayed release
471
+ artifact.visibility = AfterVisibility(ttl=timedelta(hours=24), then=PublicVisibility())
472
+ ```
473
+
474
+ **Architecturally impossible to bypass:** Every context provider inherits from `BaseContextProvider`, which enforces visibility filtering automatically. You literally cannot create a provider that forgets to check permissions.
475
+
476
+ ### Context Providers (Smart Filtering)
477
+
478
+ **Control what agents see:**
479
+
480
+ ```python
481
+ from flock.context_provider import FilteredContextProvider, PasswordRedactorProvider
482
+
483
+ # Global filtering - all agents see only urgent items
484
+ flock = Flock(
485
+ "openai/gpt-4.1",
486
+ context_provider=FilteredContextProvider(FilterConfig(tags={"urgent"}))
487
+ )
488
+
489
+ # Per-agent overrides
490
+ error_agent.context_provider = FilteredContextProvider(FilterConfig(tags={"ERROR"}))
491
+
492
+ # Production-ready password filtering
493
+ flock = Flock(
494
+ "openai/gpt-4.1",
495
+ context_provider=PasswordRedactorProvider() # Auto-redacts secrets!
496
+ )
497
+ ```
498
+
499
+ **Built-in providers (all visibility-filtered):**
500
+ - `DefaultContextProvider` - Full blackboard access
501
+ - `CorrelatedContextProvider` - Workflow isolation
502
+ - `RecentContextProvider` - Token cost control
503
+ - `TimeWindowContextProvider` - Time-based filtering
504
+ - `SemanticContextProvider` - Similarity-based retrieval (New!)
505
+ - `EmptyContextProvider` - Stateless agents
506
+ - `FilteredContextProvider` - Custom filtering
507
+
508
+ **Semantic Context Provider:**
509
+ ```python
510
+ from flock.semantic import SemanticContextProvider
511
+
512
+ # Find similar historical incidents
513
+ provider = SemanticContextProvider(
514
+ query_text="database connection timeout",
515
+ threshold=0.4,
516
+ limit=5,
517
+ artifact_type=Incident,
518
+ where=lambda a: a.payload["resolved"] is True
519
+ )
520
+ similar = await provider.get_context(store)
521
+ ```
522
+
523
+ **📖 [Context Providers Guide →](https://whiteducksoftware.github.io/flock/guides/context-providers/)**
524
+
525
+ ### Persistent Blackboard
526
+
527
+ **Production durability with SQLite:**
528
+
529
+ ```python
530
+ from flock.store import SQLiteBlackboardStore
531
+
532
+ store = SQLiteBlackboardStore(".flock/blackboard.db")
533
+ await store.ensure_schema()
534
+ flock = Flock("openai/gpt-4.1", store=store)
535
+ ```
536
+
537
+ **What you get:**
538
+ - Long-lived artifacts with full history
539
+ - Historical APIs with pagination
540
+ - Dashboard integration with retention windows
541
+ - CLI tools for maintenance and retention policies
542
+
543
+ ### Parallel Execution Control
544
+
545
+ **Batch-then-execute pattern:**
546
+
547
+ ```python
548
+ # ✅ EFFICIENT: Batch publish, then run in parallel
549
+ for review in customer_reviews:
550
+ await flock.publish(review) # Just scheduling work
551
+
552
+ await flock.run_until_idle() # All sentiment_analyzer agents run concurrently!
553
+
554
+ # Get all results
555
+ analyses = await flock.store.get_by_type(SentimentAnalysis)
556
+ # 100 analyses in ~1x single review time!
557
+ ```
558
+
559
+ ### Agent & Orchestrator Components
560
+
561
+ **Composable lifecycle hooks:**
562
+
563
+ ```python
564
+ from flock.components import AgentComponent
565
+
566
+ class LoggingComponent(AgentComponent):
567
+ async def on_pre_evaluate(self, agent, ctx, inputs):
568
+ logger.info(f"Agent {agent.name} evaluating: {inputs}")
569
+ return inputs
570
+
571
+ async def on_post_evaluate(self, agent, ctx, inputs, result):
572
+ logger.info(f"Agent {agent.name} produced: {result}")
573
+ return result
574
+
575
+ analyzer.with_utilities(LoggingComponent())
576
+ ```
577
+
578
+ **Built-in components:** Rate limiting, caching, metrics, budget tracking, circuit breakers, deduplication
579
+
580
+ **📖 [Agent Components Guide →](https://whiteducksoftware.github.io/flock/guides/components/)**
581
+
582
+ ### Production Safety
583
+
584
+ **Built-in safeguards:**
585
+
586
+ ```python
587
+ # Circuit breakers (auto-added)
588
+ flock = Flock("openai/gpt-4.1") # CircuitBreakerComponent(max_iterations=1000)
589
+
590
+ # Feedback loop protection
591
+ critic.prevent_self_trigger(True) # Won't trigger itself infinitely
592
+
593
+ # Best-of-N execution
594
+ agent.best_of(5, score=lambda result: result.metrics["confidence"])
595
+ ```
596
+
597
+ ---
598
+
599
+ ## Production Observability
600
+
601
+ ### Real-Time Dashboard
602
+
603
+ **Start with one line:**
604
+
605
+ ```python
606
+ await flock.serve(dashboard=True)
607
+ ```
608
+
609
+ <p align="center">
610
+ <img alt="Agent View" src="docs/assets/images/flock_ui_agent_view.png" width="1000">
611
+ <i>Agent View: Real-time communication patterns</i>
612
+ </p>
613
+
614
+ **Features:**
615
+ - **Dual Modes:** Agent view & Blackboard view
616
+ - **Real-Time Updates:** WebSocket streaming with live activation
617
+ - **Interactive Graph:** Drag, zoom, pan, 5 auto-layout algorithms
618
+ - **Advanced Filtering:** Correlation ID tracking, time ranges, autocomplete
619
+ - **Control Panel:** Publish artifacts, invoke agents from UI
620
+ - **Keyboard Shortcuts:** WCAG 2.1 AA compliant
621
+
622
+ <p align="center">
623
+ <img alt="Blackboard View" src="docs/assets/images/flock_ui_blackboard_view.png" width="1000">
624
+ <i>Blackboard View: Data lineage and transformations</i>
625
+ </p>
626
+
627
+ ### Production-Grade Trace Viewer
628
+
629
+ **Jaeger-style tracing with 7 modes:**
630
+
631
+ <p align="center">
632
+ <img alt="Trace Viewer" src="docs/assets/images/trace_1.png" width="1000">
633
+ <i>Timeline view with span hierarchies</i>
634
+ </p>
635
+
636
+ **7 Trace Modes:**
637
+ 1. **Timeline** - Waterfall visualization
638
+ 2. **Statistics** - Sortable duration/error tracking
639
+ 3. **RED Metrics** - Rate, Errors, Duration monitoring
640
+ 4. **Dependencies** - Service communication analysis
641
+ 5. **DuckDB SQL** - Interactive query editor with CSV export
642
+ 6. **Configuration** - Real-time filtering
643
+ 7. **Guide** - Built-in documentation
644
+
645
+ <p align="center">
646
+ <img alt="Dependencies" src="docs/assets/images/trace_2.png" width="1000">
647
+ <i>Dependency analysis</i>
648
+ </p>
649
+
650
+ ### OpenTelemetry + DuckDB Tracing
651
+
652
+ **One environment variable enables tracing:**
653
+
654
+ ```bash
655
+ export FLOCK_AUTO_TRACE=true
656
+ export FLOCK_TRACE_FILE=true
657
+
658
+ python your_app.py
659
+ # Traces stored in .flock/traces.duckdb
660
+ ```
661
+
662
+ **AI-queryable debugging:**
663
+
664
+ ```python
665
+ import duckdb
666
+ conn = duckdb.connect('.flock/traces.duckdb', read_only=True)
667
+
668
+ # Find bottlenecks
669
+ slow_ops = conn.execute("""
670
+ SELECT name, AVG(duration_ms) as avg_ms, COUNT(*) as count
671
+ FROM spans
672
+ WHERE duration_ms > 1000
673
+ GROUP BY name
674
+ ORDER BY avg_ms DESC
675
+ """).fetchall()
676
+
677
+ # Find errors with full context
678
+ errors = conn.execute("""
679
+ SELECT name, status_description,
680
+ json_extract(attributes, '$.input') as input,
681
+ json_extract(attributes, '$.output') as output
682
+ FROM spans
683
+ WHERE status_code = 'ERROR'
684
+ """).fetchall()
685
+ ```
686
+
687
+ **Real debugging:**
688
+ ```
689
+ You: "My pizza agent is slow"
690
+ AI: [queries DuckDB]
691
+ "DSPyEngine.evaluate takes 23s on average.
692
+ Input size: 50KB of conversation history.
693
+ Recommendation: Limit context to last 5 messages."
694
+ ```
695
+
696
+ <p align="center">
697
+ <img alt="DuckDB Query" src="docs/assets/images/trace_3.png" width="1000">
698
+ <i>DuckDB SQL query interface</i>
699
+ </p>
700
+
701
+ ### REST API
702
+
703
+ **Production-ready HTTP endpoints:**
704
+
705
+ ```python
706
+ await flock.serve(dashboard=True) # API + Dashboard on port 8344
707
+ # API docs: http://localhost:8344/docs
708
+ ```
709
+
710
+ **Key endpoints:**
711
+ - `POST /api/v1/artifacts` - Publish to blackboard
712
+ - `GET /api/v1/artifacts` - Query with filtering/pagination
713
+ - `POST /api/v1/agents/{name}/run` - Direct agent invocation
714
+ - `GET /api/v1/correlations/{id}/status` - Workflow tracking
715
+ - `GET /health` and `GET /metrics` - Monitoring
716
+
717
+ **Features:**
718
+ - ✅ OpenAPI 3.0 documentation at `/docs`
719
+ - ✅ Pydantic validation
720
+ - ✅ Correlation tracking
721
+ - ✅ Consumption metadata
722
+ - ✅ Prometheus-compatible metrics
723
+
724
+ ---
725
+
726
+ ## Framework Comparison
727
+
728
+ | Dimension | Graph-Based | Chat-Based | Flock (Blackboard) |
729
+ |-----------|------------|------------|-------------------|
730
+ | **Pattern** | Directed graph | Round-robin chat | Blackboard subscriptions |
731
+ | **Coordination** | Manual edges | Message passing | Type subscriptions |
732
+ | **Parallelism** | Manual split/join | Sequential | Automatic |
733
+ | **Type Safety** | Varies | Text messages | Pydantic + validation |
734
+ | **Coupling** | Tight | Medium | Loose |
735
+ | **Adding Agents** | Rewrite graph | Update flow | Just subscribe |
736
+ | **Testing** | Full graph | Full group | Individual isolation |
737
+ | **Security** | DIY | DIY | Built-in (5 types) |
738
+ | **Scalability** | O(n²) | Limited | O(n) |
739
+
740
+ ### When Flock Wins
741
+
742
+ **✅ Use Flock when you need:**
743
+ - Parallel agent execution (automatic)
744
+ - Type-safe outputs (Pydantic validation)
745
+ - Minimal prompt engineering (schemas define behavior)
746
+ - Dynamic agent addition (no rewiring)
747
+ - Testing in isolation (unit test individual agents)
748
+ - Built-in security (HIPAA, SOC2, multi-tenancy)
749
+ - 10+ agents (linear complexity)
750
+ - Semantic routing (meaning-based matching)
751
+
752
+ ### When Alternatives Win
753
+
754
+ **⚠️ Consider graph-based frameworks:**
755
+ - Extensive ecosystem integration needed
756
+ - Workflow is inherently sequential
757
+ - Battle-tested maturity required
758
+ - Team has existing expertise
759
+
760
+ **⚠️ Consider chat-based frameworks:**
761
+ - Conversation-based development preferred
762
+ - Turn-taking dialogue use case
763
+ - Specific ecosystem features needed
764
+
765
+ ### Honest Trade-offs
766
+
767
+ **You trade:**
768
+ - Ecosystem maturity (smaller community)
769
+ - Extensive documentation (catching up)
770
+ - Battle-tested age (newer architecture)
771
+
772
+ **You gain:**
773
+ - Better scalability (O(n) vs O(n²))
774
+ - Type safety (validation vs hope)
775
+ - Cleaner architecture (loose coupling)
776
+ - Production safety (built-in circuit breakers)
777
+ - Security model (5 visibility types)
778
+ - Semantic intelligence (meaning-based routing)
779
+
780
+ **Different frameworks for different priorities. Choose based on what matters to your team.**
781
+
782
+ ---
783
+
784
+ ## Production Readiness
785
+
786
+ ### What Works Today (v0.5.0)
787
+
788
+ **✅ Production-ready core:**
789
+ - 1300+ tests with >75% coverage (>90% on critical paths)
790
+ - Blackboard orchestrator with typed artifacts
791
+ - Parallel + sequential execution (automatic)
792
+ - Zero-trust security (5 visibility types)
793
+ - Semantic subscriptions with local embeddings
794
+ - Circuit breakers and feedback prevention
795
+ - OpenTelemetry + DuckDB tracing
796
+ - Real-time dashboard with 7-mode trace viewer
797
+ - MCP integration (Model Context Protocol)
798
+ - Best-of-N, batching, joins, fan-out
799
+ - Type-safe retrieval API
800
+ - SQLite persistent store
801
+
802
+ **⚠️ What's missing for large-scale:**
803
+ - Advanced retry logic (basic only)
804
+ - Event replay (no Kafka yet)
805
+ - Kubernetes-native deployment (no Helm)
806
+ - OAuth/RBAC (dashboard has no auth)
807
+
808
+ All missing features planned for v1.0 (Q4 2025)
809
+
810
+ ### Recommended Use Cases Today
811
+
812
+ **✅ Good fit right now:**
813
+ - Startups/MVPs (fast iteration, type safety)
814
+ - Internal tools (in-memory acceptable)
815
+ - Research/prototyping (clean architecture)
816
+ - Medium-scale systems (10-50 agents, 1000s of artifacts)
817
+
818
+ **⚠️ Wait for 1.0 if you need:**
819
+ - Enterprise persistence (multi-region, HA)
820
+ - Compliance auditing (immutable logs)
821
+ - Multi-tenancy SaaS (OAuth/SSO)
822
+ - Mission-critical 99.99% uptime
823
+
824
+ **Flock 0.5.0 is production-ready for the right use cases. Know your requirements.**
825
+
826
+ ---
827
+
828
+ ## Getting Started
829
+
830
+ ```bash
831
+ # Install
832
+ pip install flock-core
833
+
834
+ # With semantic features
835
+ pip install flock-core[semantic]
836
+
837
+ # Set API key
838
+ export OPENAI_API_KEY="sk-..."
839
+
840
+ # Try examples
841
+ git clone https://github.com/whiteducksoftware/flock-flow.git
842
+ cd flock-flow
843
+
844
+ # CLI examples
845
+ uv run python examples/01-cli/01_declarative_pizza.py
846
+
847
+ # Dashboard examples
848
+ uv run python examples/02-dashboard/01_declarative_pizza.py
849
+
850
+ # Semantic routing
851
+ uv run python examples/08-semantic/01_intelligent_ticket_routing.py
852
+ ```
853
+
854
+ **Learn by doing:**
855
+ - 📚 [Examples README](examples/README.md) - Complete learning path
856
+ - 🖥️ [CLI Examples](examples/01-cli/) - Console output (01-12)
857
+ - 📊 [Dashboard Examples](examples/02-dashboard/) - Interactive visualization (01-12)
858
+ - 🧠 [Semantic Examples](examples/08-semantic/) - Meaning-based routing
859
+ - 📖 [Documentation](https://whiteducksoftware.github.io/flock) - Full docs
860
+
861
+ ---
862
+
863
+ ## Production Use Cases
864
+
865
+ ### Financial Services: Multi-Signal Trading
866
+
867
+ **Challenge:** Analyze signals in parallel, correlate within time windows, maintain audit trails.
868
+
869
+ ```python
870
+ # Parallel signal analyzers
871
+ volatility = flock.agent("volatility").consumes(MarketData).publishes(VolatilityAlert)
872
+ sentiment = flock.agent("sentiment").consumes(NewsArticle).publishes(SentimentAlert)
873
+
874
+ # Trade execution waits for CORRELATED signals
875
+ trader = flock.agent("trader").consumes(
876
+ VolatilityAlert, SentimentAlert,
877
+ join=JoinSpec(within=timedelta(minutes=5))
878
+ ).publishes(TradeOrder)
879
+ ```
880
+
881
+ ### Healthcare: HIPAA-Compliant Diagnostics
882
+
883
+ **Challenge:** Multi-modal fusion with access controls, audit trails, zero-trust.
884
+
885
+ ```python
886
+ # Privacy controls built-in
887
+ radiology.publishes(XRayAnalysis, visibility=PrivateVisibility(agents={"diagnostician"}))
888
+ lab.publishes(LabResults, visibility=TenantVisibility(tenant_id="patient_123"))
889
+
890
+ # Diagnostician waits for BOTH with role-based access
891
+ diagnostician = flock.agent("diagnostician").consumes(XRayAnalysis, LabResults).publishes(Diagnosis)
892
+ ```
893
+
894
+ ### E-Commerce: Intelligent Support Routing
895
+
896
+ **Challenge:** Route support tickets to specialized teams based on meaning.
897
+
898
+ ```python
899
+ # Semantic routing (NO keyword matching!)
900
+ security_team.consumes(Ticket, semantic_match="security vulnerability exploit")
901
+ billing_team.consumes(Ticket, semantic_match="payment charge refund billing")
902
+ tech_support.consumes(Ticket, semantic_match="technical issue error bug")
903
+
904
+ # "SQL injection" → Security (no "security" keyword needed!)
905
+ # "charged twice" → Billing (semantic match!)
906
+ # "app crashes" → Tech Support (semantic understanding!)
907
+ ```
908
+
909
+ **📖 [Full Use Cases →](USECASES.md)**
910
+
911
+ ---
912
+
913
+ ## Contributing
914
+
915
+ We're building Flock in the open. See **[Contributing Guide](https://whiteducksoftware.github.io/flock/about/contributing/)**.
916
+
917
+ **Before contributing:**
918
+ - [Architecture Overview](docs/architecture.md) - Codebase organization
919
+ - [Error Handling](docs/patterns/error_handling.md) - Required patterns
920
+ - [Async Patterns](docs/patterns/async_patterns.md) - Standards
921
+
922
+ **Quality standards:**
923
+ - All tests must pass
924
+ - Coverage requirements met
925
+ - Code formatted with Ruff
926
+
927
+ ---
928
+
929
+ ## Roadmap to 1.0
930
+
931
+ **Target: Q4 2025**
932
+
933
+ See [ROADMAP.md](ROADMAP.md) for detailed status and tracking.
934
+
935
+ **Key initiatives:**
936
+ - **Reliability:** Advanced retry, error recovery, distributed tracing
937
+ - **Persistence:** Multi-region stores, event replay, Kafka integration
938
+ - **Security:** OAuth/RBAC, audit logging, compliance tooling
939
+ - **Operations:** Kubernetes deployment, Helm charts, monitoring
940
+ - **Quality:** Performance benchmarks, stress testing, migration tools
941
+
942
+ ---
943
+
944
+ ## The Bottom Line
945
+
946
+ **Flock makes different architectural choices:**
947
+
948
+ **Instead of:**
949
+ - ❌ Prompt engineering → ✅ Declarative type contracts
950
+ - ❌ Workflow graphs → ✅ Blackboard subscriptions
951
+ - ❌ Keyword matching → ✅ Semantic intelligence
952
+ - ❌ Manual parallelization → ✅ Automatic concurrent execution
953
+ - ❌ Bolt-on security → ✅ Zero-trust visibility controls
954
+ - ❌ Hope-based debugging → ✅ AI-queryable distributed traces
955
+
956
+ **These are architectural decisions with real tradeoffs.**
957
+
958
+ **Different frameworks for different priorities. Choose based on what matters to your team.**
959
+
960
+ ---
961
+
962
+ <div align="center">
963
+
964
+ **Built with ❤️ by white duck GmbH**
965
+
966
+ **"Declarative contracts eliminate prompt hell. Blackboard architecture eliminates graph spaghetti. Semantic intelligence eliminates keyword brittleness. Proven patterns applied to modern LLMs."**
967
+
968
+ [⭐ Star on GitHub](https://github.com/whiteducksoftware/flock-flow) | [📖 Documentation](https://whiteducksoftware.github.io/flock) | [🚀 Try Examples](examples/) | [💼 Enterprise Support](mailto:support@whiteduck.de)
969
+
970
+ </div>
971
+
972
+ ---
973
+
974
+ **Last Updated:** October 19, 2025
975
+ **Version:** Flock 0.5.0 (Blackboard Edition)
976
+ **Status:** Production-Ready Core, Enterprise Features Roadmapped