behive 0.2.2__tar.gz → 0.3.2__tar.gz

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 (61) hide show
  1. {behive-0.2.2/src/behive.egg-info → behive-0.3.2}/PKG-INFO +46 -17
  2. {behive-0.2.2 → behive-0.3.2}/README.md +42 -13
  3. {behive-0.2.2 → behive-0.3.2}/pyproject.toml +22 -4
  4. {behive-0.2.2 → behive-0.3.2}/src/behive/__init__.py +1 -1
  5. {behive-0.2.2 → behive-0.3.2}/src/behive/cli.py +154 -1
  6. {behive-0.2.2 → behive-0.3.2}/src/behive/config.py +27 -13
  7. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/__init__.py +2 -0
  8. behive-0.3.2/src/behive/engine/__main__.py +61 -0
  9. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/api_scout.py +5 -1
  10. behive-0.3.2/src/behive/engine/bedrock_compat.py +152 -0
  11. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/bionic_quorum.py +3 -12
  12. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/db.py +27 -6
  13. behive-0.3.2/src/behive/engine/db_helpers.py +127 -0
  14. behive-0.3.2/src/behive/engine/hive_api_sources.json +1192 -0
  15. behive-0.3.2/src/behive/engine/llm.py +410 -0
  16. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/orchestrator.py +194 -172
  17. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/preprocessor.py +2 -16
  18. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/process.py +75 -37
  19. behive-0.3.2/src/behive/engine/queen.py +839 -0
  20. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/queen_fact_mem.py +38 -16
  21. behive-0.3.2/src/behive/engine/queen_planner_extracted.py +838 -0
  22. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/queen_primer.py +1 -1
  23. behive-0.3.2/src/behive/engine/runner.py +147 -0
  24. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/scout.py +15 -23
  25. behive-0.3.2/src/behive/engine/search_backends.py +615 -0
  26. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/synth.py +17 -107
  27. behive-0.3.2/src/behive/init-db.sql +331 -0
  28. behive-0.3.2/src/behive/knowledge_graph.py +354 -0
  29. {behive-0.2.2 → behive-0.3.2}/src/behive/mcp_server.py +55 -2
  30. behive-0.3.2/src/behive/server.py +870 -0
  31. {behive-0.2.2 → behive-0.3.2/src/behive.egg-info}/PKG-INFO +46 -17
  32. {behive-0.2.2 → behive-0.3.2}/src/behive.egg-info/SOURCES.txt +16 -0
  33. {behive-0.2.2 → behive-0.3.2}/src/behive.egg-info/requires.txt +3 -3
  34. behive-0.3.2/tests/test_db_integration.py +166 -0
  35. behive-0.3.2/tests/test_e2e_pipeline.py +180 -0
  36. behive-0.3.2/tests/test_llm.py +179 -0
  37. behive-0.3.2/tests/test_regression.py +236 -0
  38. behive-0.3.2/tests/test_search_backends.py +98 -0
  39. behive-0.3.2/tests/test_server_integration.py +157 -0
  40. {behive-0.2.2 → behive-0.3.2}/tests/test_smoke.py +4 -3
  41. behive-0.2.2/src/behive/engine/__main__.py +0 -29
  42. behive-0.2.2/src/behive/server.py +0 -390
  43. {behive-0.2.2 → behive-0.3.2}/LICENSE +0 -0
  44. {behive-0.2.2 → behive-0.3.2}/setup.cfg +0 -0
  45. {behive-0.2.2 → behive-0.3.2}/src/behive/client.py +0 -0
  46. {behive-0.2.2 → behive-0.3.2}/src/behive/compat/__init__.py +0 -0
  47. {behive-0.2.2 → behive-0.3.2}/src/behive/compat/shims.py +0 -0
  48. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/constants.py +0 -0
  49. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/domain_reputation.py +0 -0
  50. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/drones.py +0 -0
  51. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/events.py +0 -0
  52. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/guardrail.py +0 -0
  53. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/harvest.py +0 -0
  54. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/prescout.py +0 -0
  55. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/quality.py +0 -0
  56. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/queen_calibrator.py +0 -0
  57. {behive-0.2.2 → behive-0.3.2}/src/behive/engine/queen_memory.py +0 -0
  58. {behive-0.2.2 → behive-0.3.2}/src/behive/models.py +0 -0
  59. {behive-0.2.2 → behive-0.3.2}/src/behive.egg-info/dependency_links.txt +0 -0
  60. {behive-0.2.2 → behive-0.3.2}/src/behive.egg-info/entry_points.txt +0 -0
  61. {behive-0.2.2 → behive-0.3.2}/src/behive.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: behive
3
- Version: 0.2.2
3
+ Version: 0.3.2
4
4
  Summary: Research engine that builds structured knowledge graphs from any topic
5
5
  Author-email: QA10 <hello@qa10.io>
6
6
  License-Expression: MIT
@@ -19,10 +19,10 @@ Requires-Python: >=3.10
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
21
  Requires-Dist: aiohttp>=3.9
22
- Requires-Dist: boto3>=1.28
22
+ Requires-Dist: httpx>=0.25
23
23
  Requires-Dist: psycopg2-binary>=2.9
24
24
  Requires-Dist: pydantic>=2.0
25
- Requires-Dist: httpx>=0.25
25
+ Requires-Dist: litellm>=1.40
26
26
  Requires-Dist: feedparser>=6.0
27
27
  Provides-Extra: stealth
28
28
  Requires-Dist: curl-cffi>=0.7; extra == "stealth"
@@ -54,7 +54,7 @@ Provides-Extra: qdrant
54
54
  Requires-Dist: qdrant-client>=1.7; extra == "qdrant"
55
55
  Requires-Dist: sentence-transformers>=2.2; extra == "qdrant"
56
56
  Provides-Extra: all
57
- Requires-Dist: behive[api,harvest,mcp,process,qdrant,science,stealth]; extra == "all"
57
+ Requires-Dist: behive[api,harvest,mcp,process,science,stealth]; extra == "all"
58
58
  Provides-Extra: dev
59
59
  Requires-Dist: pytest>=7.0; extra == "dev"
60
60
  Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
@@ -104,7 +104,7 @@ You ask Perplexity. Better — it cites sources. But the output is still unstruc
104
104
 
105
105
  ```
106
106
  Your AI assistant → BeHive → Verified, structured, scored knowledge
107
- ├── 363 claims (avg quality 0.824)
107
+ ├── 363 claims (avg quality 0.77)
108
108
  ├── 42 entities with relationships
109
109
  └── Synthesized report with citations
110
110
  ```
@@ -117,17 +117,32 @@ Your AI assistant → BeHive → Verified, structured, scored knowledge
117
117
  pip install behive
118
118
 
119
119
  # Set your LLM API key (you use YOUR OWN subscription — BeHive costs nothing)
120
- export ANTHROPIC_API_KEY=*** # or OPENAI_API_KEY
120
+ export ANTHROPIC_API_KEY=your-key # or OPENAI_API_KEY, or AWS creds for Bedrock
121
+
122
+ # PostgreSQL required for storage (or use Docker below)
123
+ export BEHIVE_DB_URL=postgresql://user:***@localhost:5432/behive
121
124
 
122
125
  # Start the server
123
126
  behive serve
124
127
  ```
125
128
 
129
+ **Fastest path — Docker Compose (PostgreSQL included):**
130
+ ```bash
131
+ git clone https://github.com/qa10devteam/behive && cd behive
132
+ echo "ANTHROPIC_API_KEY=your-key" > .env
133
+ docker compose up -d
134
+ # API at http://localhost:8091
135
+ ```
136
+
126
137
  **Full install** (stealth drones, content extraction, NLP processing):
127
138
  ```bash
128
139
  pip install "behive[all]"
129
140
  ```
130
141
 
142
+ > **⚠️ GPU/CUDA note:** `behive[all]` does NOT include GPU dependencies. If you need vector embeddings (Qdrant), install separately:
143
+ > `pip install "behive[qdrant]"` — this pulls PyTorch + sentence-transformers (~4GB with CUDA).
144
+ > For CPU-only machines, install torch CPU-only first: `pip install torch --index-url https://download.pytorch.org/whl/cpu`
145
+
131
146
  Or pick what you need:
132
147
  ```bash
133
148
  pip install "behive[stealth]" # curl_cffi, primp, nodriver, patchright
@@ -196,7 +211,7 @@ Priority: `BEHIVE_MODEL_{STAGE}` > `BEHIVE_MODEL` > config.yaml > defaults
196
211
 
197
212
  | Preset | Model String |
198
213
  |--------|-------------|
199
- | `claude-haiku` | anthropic/claude-3-5-haiku-20241022 |
214
+ | `claude-haiku` | anthropic/claude-haiku-4-5-20251001 |
200
215
  | `claude-sonnet` | anthropic/claude-sonnet-4-20250514 |
201
216
  | `claude-opus` | anthropic/claude-opus-4-20250514 |
202
217
  | `gpt-4o-mini` | openai/gpt-4o-mini |
@@ -290,7 +305,7 @@ Or manually add this schema:
290
305
  openapi: 3.1.0
291
306
  info:
292
307
  title: BeHive Research API
293
- version: 0.2.0
308
+ version: 0.3.0
294
309
  servers:
295
310
  - url: https://*** paths:
296
311
  /research:
@@ -491,7 +506,7 @@ Real results. No cherry-picking. Scale 30 (standard depth).
491
506
 
492
507
  **Quality score meaning:**
493
508
  - `0.90+` — Exceptional: specific numbers, dates, sources, fully verifiable
494
- - `0.82+` — Excellent: multi-dimensional, publication-ready
509
+ - `0.82+` — Excellent: multi-source corroboration, publication-ready (top 25% of missions)
495
510
  - `0.75+` — Good: useful intelligence with some specifics
496
511
  - `0.65+` — Acceptable: general facts, entered into DB
497
512
  - `<0.55` — Rejected: too vague, not stored
@@ -575,10 +590,10 @@ event: phase
575
590
  data: {"phase": "process", "event": "started"}
576
591
 
577
592
  event: claims
578
- data: {"count": 142, "avg_quality": 0.791, "above_082": 23, "new_since_last": 18}
593
+ data: {"count": 142, "avg_quality": 0.77, "above_082": 23, "new_since_last": 18}
579
594
 
580
595
  event: done
581
- data: {"total_claims": 363, "avg_quality": 0.824, "sources": 64}
596
+ data: {"total_claims": 363, "avg_quality": 0.77, "sources": 64}
582
597
  ```
583
598
 
584
599
  ### Get Report
@@ -682,8 +697,7 @@ export BEHIVE_DB_URL="postgresql://user:pass@localhost:5432/hive"
682
697
  export BEHIVE_LLM=bedrock # or openai, local
683
698
 
684
699
  # Start services
685
- behive api start # REST API on :8091
686
- behive mcp start # MCP server on :8090
700
+ behive serve # Starts both REST API (:8091) + MCP (:8090)
687
701
  ```
688
702
 
689
703
  ### Minimum Requirements
@@ -734,6 +748,20 @@ behive mcp start # MCP server on :8090
734
748
  | `AWS_PROFILE` | `default` | For Bedrock authentication |
735
749
  | `OPENAI_API_KEY` | — | For OpenAI mode |
736
750
 
751
+ ### Search Backends (priority order)
752
+
753
+ BeHive tries search backends in priority order and falls through on failure:
754
+
755
+ | Priority | Backend | Env Variable | Free Tier |
756
+ |:---:|---------|-------------|-----------|
757
+ | 1 | SearXNG (self-hosted) | `SEARXNG_URL=http://localhost:8080` | Unlimited |
758
+ | 2 | Brave Search | `BRAVE_SEARCH_API_KEY=***` | 2,000 req/month |
759
+ | 3 | Serper.dev (Google) | `SERPER_API_KEY=***` | 2,500 credits |
760
+ | 4 | Tavily | `TAVILY_API_KEY=***` | 1,000 req/month |
761
+ | 5 | DuckDuckGo | *(always available)* | Unlimited (slow) |
762
+
763
+ No env vars set? DDG is the default. Add any key above to instantly upgrade search quality.
764
+
737
765
  ---
738
766
 
739
767
  ## Comparison
@@ -755,13 +783,14 @@ behive mcp start # MCP server on :8090
755
783
 
756
784
  ## Roadmap
757
785
 
758
- - [x] V4 pipeline (Haiku + Sonnet extraction)
759
- - [x] Quality scoring (avg 0.82+ achieved)
760
- - [x] REST API (27 endpoints)
786
+ - [x] V4 pipeline (BYOK — bring your own LLM key, any provider)
787
+ - [x] Quality scoring (avg 0.77, top missions reach 0.82+)
788
+ - [x] REST API (14 endpoints)
761
789
  - [x] MCP Server (Streamable HTTP)
762
790
  - [x] SSE streaming (real-time progress)
763
791
  - [x] Knowledge graph (Neo4j)
764
- - [x] 70+ API sources
792
+ - [x] 64 API sources (37 free APIs confirmed working, 26 need BYOK keys)
793
+ - [x] Browser search (Chromium/Playwright — scrapes Google/Bing, zero API keys)
765
794
  - [x] `pip install behive` ([PyPI](https://pypi.org/project/behive/))
766
795
  - [x] Docker Compose one-liner
767
796
  - [x] n8n community node ([npm](https://www.npmjs.com/package/n8n-nodes-behive))
@@ -41,7 +41,7 @@ You ask Perplexity. Better — it cites sources. But the output is still unstruc
41
41
 
42
42
  ```
43
43
  Your AI assistant → BeHive → Verified, structured, scored knowledge
44
- ├── 363 claims (avg quality 0.824)
44
+ ├── 363 claims (avg quality 0.77)
45
45
  ├── 42 entities with relationships
46
46
  └── Synthesized report with citations
47
47
  ```
@@ -54,17 +54,32 @@ Your AI assistant → BeHive → Verified, structured, scored knowledge
54
54
  pip install behive
55
55
 
56
56
  # Set your LLM API key (you use YOUR OWN subscription — BeHive costs nothing)
57
- export ANTHROPIC_API_KEY=*** # or OPENAI_API_KEY
57
+ export ANTHROPIC_API_KEY=your-key # or OPENAI_API_KEY, or AWS creds for Bedrock
58
+
59
+ # PostgreSQL required for storage (or use Docker below)
60
+ export BEHIVE_DB_URL=postgresql://user:***@localhost:5432/behive
58
61
 
59
62
  # Start the server
60
63
  behive serve
61
64
  ```
62
65
 
66
+ **Fastest path — Docker Compose (PostgreSQL included):**
67
+ ```bash
68
+ git clone https://github.com/qa10devteam/behive && cd behive
69
+ echo "ANTHROPIC_API_KEY=your-key" > .env
70
+ docker compose up -d
71
+ # API at http://localhost:8091
72
+ ```
73
+
63
74
  **Full install** (stealth drones, content extraction, NLP processing):
64
75
  ```bash
65
76
  pip install "behive[all]"
66
77
  ```
67
78
 
79
+ > **⚠️ GPU/CUDA note:** `behive[all]` does NOT include GPU dependencies. If you need vector embeddings (Qdrant), install separately:
80
+ > `pip install "behive[qdrant]"` — this pulls PyTorch + sentence-transformers (~4GB with CUDA).
81
+ > For CPU-only machines, install torch CPU-only first: `pip install torch --index-url https://download.pytorch.org/whl/cpu`
82
+
68
83
  Or pick what you need:
69
84
  ```bash
70
85
  pip install "behive[stealth]" # curl_cffi, primp, nodriver, patchright
@@ -133,7 +148,7 @@ Priority: `BEHIVE_MODEL_{STAGE}` > `BEHIVE_MODEL` > config.yaml > defaults
133
148
 
134
149
  | Preset | Model String |
135
150
  |--------|-------------|
136
- | `claude-haiku` | anthropic/claude-3-5-haiku-20241022 |
151
+ | `claude-haiku` | anthropic/claude-haiku-4-5-20251001 |
137
152
  | `claude-sonnet` | anthropic/claude-sonnet-4-20250514 |
138
153
  | `claude-opus` | anthropic/claude-opus-4-20250514 |
139
154
  | `gpt-4o-mini` | openai/gpt-4o-mini |
@@ -227,7 +242,7 @@ Or manually add this schema:
227
242
  openapi: 3.1.0
228
243
  info:
229
244
  title: BeHive Research API
230
- version: 0.2.0
245
+ version: 0.3.0
231
246
  servers:
232
247
  - url: https://*** paths:
233
248
  /research:
@@ -428,7 +443,7 @@ Real results. No cherry-picking. Scale 30 (standard depth).
428
443
 
429
444
  **Quality score meaning:**
430
445
  - `0.90+` — Exceptional: specific numbers, dates, sources, fully verifiable
431
- - `0.82+` — Excellent: multi-dimensional, publication-ready
446
+ - `0.82+` — Excellent: multi-source corroboration, publication-ready (top 25% of missions)
432
447
  - `0.75+` — Good: useful intelligence with some specifics
433
448
  - `0.65+` — Acceptable: general facts, entered into DB
434
449
  - `<0.55` — Rejected: too vague, not stored
@@ -512,10 +527,10 @@ event: phase
512
527
  data: {"phase": "process", "event": "started"}
513
528
 
514
529
  event: claims
515
- data: {"count": 142, "avg_quality": 0.791, "above_082": 23, "new_since_last": 18}
530
+ data: {"count": 142, "avg_quality": 0.77, "above_082": 23, "new_since_last": 18}
516
531
 
517
532
  event: done
518
- data: {"total_claims": 363, "avg_quality": 0.824, "sources": 64}
533
+ data: {"total_claims": 363, "avg_quality": 0.77, "sources": 64}
519
534
  ```
520
535
 
521
536
  ### Get Report
@@ -619,8 +634,7 @@ export BEHIVE_DB_URL="postgresql://user:pass@localhost:5432/hive"
619
634
  export BEHIVE_LLM=bedrock # or openai, local
620
635
 
621
636
  # Start services
622
- behive api start # REST API on :8091
623
- behive mcp start # MCP server on :8090
637
+ behive serve # Starts both REST API (:8091) + MCP (:8090)
624
638
  ```
625
639
 
626
640
  ### Minimum Requirements
@@ -671,6 +685,20 @@ behive mcp start # MCP server on :8090
671
685
  | `AWS_PROFILE` | `default` | For Bedrock authentication |
672
686
  | `OPENAI_API_KEY` | — | For OpenAI mode |
673
687
 
688
+ ### Search Backends (priority order)
689
+
690
+ BeHive tries search backends in priority order and falls through on failure:
691
+
692
+ | Priority | Backend | Env Variable | Free Tier |
693
+ |:---:|---------|-------------|-----------|
694
+ | 1 | SearXNG (self-hosted) | `SEARXNG_URL=http://localhost:8080` | Unlimited |
695
+ | 2 | Brave Search | `BRAVE_SEARCH_API_KEY=***` | 2,000 req/month |
696
+ | 3 | Serper.dev (Google) | `SERPER_API_KEY=***` | 2,500 credits |
697
+ | 4 | Tavily | `TAVILY_API_KEY=***` | 1,000 req/month |
698
+ | 5 | DuckDuckGo | *(always available)* | Unlimited (slow) |
699
+
700
+ No env vars set? DDG is the default. Add any key above to instantly upgrade search quality.
701
+
674
702
  ---
675
703
 
676
704
  ## Comparison
@@ -692,13 +720,14 @@ behive mcp start # MCP server on :8090
692
720
 
693
721
  ## Roadmap
694
722
 
695
- - [x] V4 pipeline (Haiku + Sonnet extraction)
696
- - [x] Quality scoring (avg 0.82+ achieved)
697
- - [x] REST API (27 endpoints)
723
+ - [x] V4 pipeline (BYOK — bring your own LLM key, any provider)
724
+ - [x] Quality scoring (avg 0.77, top missions reach 0.82+)
725
+ - [x] REST API (14 endpoints)
698
726
  - [x] MCP Server (Streamable HTTP)
699
727
  - [x] SSE streaming (real-time progress)
700
728
  - [x] Knowledge graph (Neo4j)
701
- - [x] 70+ API sources
729
+ - [x] 64 API sources (37 free APIs confirmed working, 26 need BYOK keys)
730
+ - [x] Browser search (Chromium/Playwright — scrapes Google/Bing, zero API keys)
702
731
  - [x] `pip install behive` ([PyPI](https://pypi.org/project/behive/))
703
732
  - [x] Docker Compose one-liner
704
733
  - [x] n8n community node ([npm](https://www.npmjs.com/package/n8n-nodes-behive))
@@ -5,9 +5,12 @@ build-backend = "setuptools.build_meta"
5
5
  [tool.setuptools.packages.find]
6
6
  where = ["src"]
7
7
 
8
+ [tool.setuptools.package-data]
9
+ behive = ["init-db.sql", "engine/hive_api_sources.json"]
10
+
8
11
  [project]
9
12
  name = "behive"
10
- version = "0.2.2"
13
+ version = "0.3.2"
11
14
  description = "Research engine that builds structured knowledge graphs from any topic"
12
15
  readme = "README.md"
13
16
  license = "MIT"
@@ -28,10 +31,10 @@ classifiers = [
28
31
 
29
32
  dependencies = [
30
33
  "aiohttp>=3.9",
31
- "boto3>=1.28",
34
+ "httpx>=0.25",
32
35
  "psycopg2-binary>=2.9",
33
36
  "pydantic>=2.0",
34
- "httpx>=0.25",
37
+ "litellm>=1.40",
35
38
  "feedparser>=6.0",
36
39
  ]
37
40
 
@@ -64,7 +67,7 @@ science = [
64
67
  mcp = ["fastmcp>=3.0"]
65
68
  api = ["fastapi>=0.100", "uvicorn>=0.20"]
66
69
  qdrant = ["qdrant-client>=1.7", "sentence-transformers>=2.2"]
67
- all = ["behive[stealth,harvest,process,science,mcp,api,qdrant]"]
70
+ all = ["behive[stealth,harvest,process,science,mcp,api]"]
68
71
  dev = ["pytest>=7.0", "pytest-asyncio>=0.21", "ruff>=0.3"]
69
72
 
70
73
  [project.scripts]
@@ -75,4 +78,19 @@ Homepage = "https://github.com/qa10devteam/behive"
75
78
  Documentation = "https://behive.dev"
76
79
  Repository = "https://github.com/qa10devteam/behive"
77
80
 
81
+ [tool.pytest.ini_options]
82
+ testpaths = ["tests"]
83
+ markers = [
84
+ "unit: pure unit tests, no I/O, fast",
85
+ "integration: requires PostgreSQL",
86
+ "e2e: full pipeline end-to-end (slow)",
87
+ "regression: regression tests for past bugs",
88
+ ]
89
+ addopts = "-v --tb=short"
90
+ asyncio_mode = "auto"
91
+
92
+ [tool.ruff]
93
+ line-length = 100
94
+ target-version = "py311"
95
+
78
96
 
@@ -10,7 +10,7 @@ Usage:
10
10
  print(result.report) # Synthesized markdown report
11
11
  """
12
12
 
13
- __version__ = "0.2.2"
13
+ __version__ = "0.3.0"
14
14
 
15
15
  from behive.client import research, BeHiveClient
16
16
  from behive.models import ResearchResult, Claim, Entity
@@ -51,12 +51,22 @@ def main():
51
51
  config_mode.add_argument("--full", action="store_true", help="Full setup: pick model per stage")
52
52
  config_mode.add_argument("--show", action="store_true", help="Show current configuration")
53
53
  config_mode.add_argument("--preset", choices=["budget", "balanced", "quality", "local"], help="Apply a named preset")
54
+ config_mode.add_argument("--list-models", action="store_true", help="Show available model presets")
54
55
  config_p.add_argument("--stage", choices=["scout", "harvest", "process", "synth"], help="Set model for single stage")
55
56
  config_p.add_argument("--model", help="Model name or litellm string (use with --stage)")
56
57
 
57
58
  # ─── version ──────────────────────────────────────────────────────────
58
59
  sub.add_parser("version", help="Show version")
59
60
 
61
+ # ─── db ────────────────────────────────────────────────────────────────
62
+ db_p = sub.add_parser("db", help="Database management")
63
+ db_sub = db_p.add_subparsers(dest="db_action")
64
+ db_sub.add_parser("init", help="Initialize database schema")
65
+
66
+ # ─── missions ──────────────────────────────────────────────────────────
67
+ missions_p = sub.add_parser("missions", help="List recent research missions")
68
+ missions_p.add_argument("--limit", type=int, default=10, help="Number of missions to show")
69
+
60
70
  args = parser.parse_args()
61
71
 
62
72
  if args.command == "serve":
@@ -67,6 +77,10 @@ def main():
67
77
  cmd_status(args)
68
78
  elif args.command == "config":
69
79
  cmd_config(args)
80
+ elif args.command == "db":
81
+ cmd_db(args)
82
+ elif args.command == "missions":
83
+ cmd_missions(args)
70
84
  elif args.command == "version":
71
85
  from behive import __version__
72
86
  print(f"behive {__version__}")
@@ -97,6 +111,18 @@ def cmd_config(args):
97
111
  resolved = MODEL_PRESETS.get(combo[stage], combo[stage])
98
112
  print(f" {stage:10s} → {resolved}")
99
113
  print(f"\n Config: {CONFIG_FILE}\n")
114
+ elif getattr(args, 'list_models', False):
115
+ # Show all available presets
116
+ print("\n🐝 BeHive Model Presets\n")
117
+ print(f" {'Preset':<20} {'Model String'}")
118
+ print(f" {'─'*20} {'─'*50}")
119
+ for name, model in MODEL_PRESETS.items():
120
+ print(f" {name:<20} {model}")
121
+ print(f"\n 💡 You can also use ANY litellm-compatible model string directly:")
122
+ print(f" BEHIVE_MODEL=anthropic/claude-sonnet-5-20260801")
123
+ print(f" BEHIVE_MODEL=openai/gpt-5.6-turbo")
124
+ print(f" BEHIVE_MODEL=ollama/mixtral:8x22b")
125
+ print(f" behive config --stage synth --model deepseek/deepseek-r1\n")
100
126
  elif args.stage and args.model:
101
127
  # Set single stage model
102
128
  cfg = load_config()
@@ -128,7 +154,7 @@ def cmd_serve(args):
128
154
 
129
155
  print(f"""
130
156
  \033[33m ╔══════════════════════════════════════╗
131
- ║ 🐝 BeHive Research Engine v0.2.0 ║
157
+ ║ 🐝 BeHive Research Engine v0.3.2 ║
132
158
  ╚══════════════════════════════════════╝\033[0m
133
159
 
134
160
  API: http://{args.host}:{args.port}
@@ -282,5 +308,132 @@ def cmd_status(args):
282
308
  print(f" Run: behive serve")
283
309
 
284
310
 
311
+ # ═══════════════════════════════════════════════════════════════════════════════
312
+ # DB — database management
313
+ # ═══════════════════════════════════════════════════════════════════════════════
314
+
315
+ def cmd_db(args):
316
+ """Database management commands."""
317
+ if args.db_action == "init":
318
+ _db_init()
319
+ else:
320
+ print("Usage: behive db init")
321
+ print(" Initialize the BeHive database schema.")
322
+
323
+
324
+ def _db_init():
325
+ """Create all tables in PostgreSQL from bundled schema."""
326
+ import importlib.resources
327
+ import psycopg2
328
+
329
+ # Find init-db.sql bundled with the package
330
+ sql_path = None
331
+ try:
332
+ # Python 3.9+
333
+ ref = importlib.resources.files("behive").joinpath("init-db.sql")
334
+ sql_content = ref.read_text(encoding="utf-8")
335
+ except (AttributeError, FileNotFoundError):
336
+ # Fallback: look relative to this file
337
+ this_dir = os.path.dirname(os.path.abspath(__file__))
338
+ candidate = os.path.join(this_dir, "init-db.sql")
339
+ if not os.path.exists(candidate):
340
+ # Try docker/ directory (development)
341
+ candidate = os.path.join(this_dir, "..", "..", "docker", "init-db.sql")
342
+ if os.path.exists(candidate):
343
+ with open(candidate) as f:
344
+ sql_content = f.read()
345
+ else:
346
+ print("\033[31m✗ Cannot find init-db.sql\033[0m")
347
+ print(" Expected at: src/behive/init-db.sql or docker/init-db.sql")
348
+ sys.exit(1)
349
+
350
+ # Connect to database
351
+ db_url = os.environ.get("BEHIVE_DB_URL") or os.environ.get("DATABASE_URL")
352
+ if not db_url:
353
+ user = os.environ.get("HIVE_PG_USER", "behive")
354
+ password = os.environ.get("HIVE_PG_PASSWORD", "behive")
355
+ host = os.environ.get("HIVE_PG_HOST", "localhost")
356
+ port = os.environ.get("HIVE_PG_PORT", "5432")
357
+ db = os.environ.get("HIVE_PG_DATABASE", "behive")
358
+ db_url = f"postgresql://{user}:***@{host}:{port}/{db}"
359
+
360
+ print(f" Connecting to: {db_url.split('@')[-1] if '@' in db_url else db_url}")
361
+
362
+ try:
363
+ conn = psycopg2.connect(db_url)
364
+ conn.autocommit = True
365
+ cur = conn.cursor()
366
+ cur.execute(sql_content)
367
+ # Count tables created
368
+ cur.execute("""
369
+ SELECT COUNT(*) FROM information_schema.tables
370
+ WHERE table_schema = 'public' AND table_type = 'BASE TABLE'
371
+ """)
372
+ table_count = cur.fetchone()[0]
373
+ conn.close()
374
+ print(f"\033[32m✓ Database initialized — {table_count} tables ready\033[0m")
375
+ except psycopg2.OperationalError as e:
376
+ print(f"\033[31m✗ Cannot connect to database\033[0m")
377
+ print(f" {e}")
378
+ print(f"\n Set BEHIVE_DB_URL or HIVE_PG_* environment variables.")
379
+ print(f" Example: export BEHIVE_DB_URL=postgresql://user:***@localhost:5432/behive")
380
+ sys.exit(1)
381
+ except Exception as e:
382
+ print(f"\033[31m✗ Schema error: {e}\033[0m")
383
+ sys.exit(1)
384
+
385
+
386
+ # ═══════════════════════════════════════════════════════════════════════════════
387
+ # MISSIONS — list recent missions
388
+ # ═══════════════════════════════════════════════════════════════════════════════
389
+
390
+ def cmd_missions(args):
391
+ """List recent research missions from the database."""
392
+ import psycopg2
393
+
394
+ db_url = os.environ.get("BEHIVE_DB_URL") or os.environ.get("DATABASE_URL")
395
+ if not db_url:
396
+ user = os.environ.get("HIVE_PG_USER", "behive")
397
+ password = os.environ.get("HIVE_PG_PASSWORD", "behive")
398
+ host = os.environ.get("HIVE_PG_HOST", "localhost")
399
+ port = os.environ.get("HIVE_PG_PORT", "5432")
400
+ db = os.environ.get("HIVE_PG_DATABASE", "behive")
401
+ db_url = f"postgresql://{user}:***@{host}:{port}/{db}"
402
+
403
+ try:
404
+ conn = psycopg2.connect(db_url)
405
+ cur = conn.cursor()
406
+ cur.execute("""
407
+ SELECT m.id, m.topic, m.status, m.phase, m.created_at,
408
+ COALESCE(c.cnt, 0), COALESCE(c.avg_q, 0)
409
+ FROM hive_missions m
410
+ LEFT JOIN (
411
+ SELECT mission_id, COUNT(*) as cnt, AVG(quality_score) as avg_q
412
+ FROM hive_claims WHERE is_garbage = false OR is_garbage IS NULL
413
+ GROUP BY mission_id
414
+ ) c ON c.mission_id = m.id
415
+ ORDER BY m.created_at DESC
416
+ LIMIT %s
417
+ """, (args.limit,))
418
+ rows = cur.fetchall()
419
+ conn.close()
420
+
421
+ if not rows:
422
+ print(" No missions found. Run: behive research \"your topic\"")
423
+ return
424
+
425
+ print(f"\033[33m🐝 Recent Missions ({len(rows)})\033[0m\n")
426
+ print(f" {'ID':<28} {'Status':<8} {'Claims':>6} {'Quality':>8} Topic")
427
+ print(f" {'─'*28} {'─'*8} {'─'*6} {'─'*8} {'─'*30}")
428
+ for row in rows:
429
+ mid, topic, status, phase, created, claims, avg_q = row
430
+ status_icon = {"done": "✓", "running": "⟳", "error": "✗", "queued": "◌"}.get(status, "?")
431
+ topic_short = (topic or "")[:40]
432
+ print(f" {mid:<28} {status_icon} {status:<6} {claims:>6} {avg_q:>7.3f} {topic_short}")
433
+ except Exception as e:
434
+ print(f"\033[31m✗ Cannot connect to database: {e}\033[0m")
435
+ print(f" Set BEHIVE_DB_URL or run: behive db init")
436
+
437
+
285
438
  if __name__ == "__main__":
286
439
  main()
@@ -30,40 +30,51 @@ STAGES = {
30
30
  "scout": {
31
31
  "description": "Source discovery & query generation",
32
32
  "role": "Fast, cheap — generates search queries and scores URL relevance",
33
- "default": "claude-haiku",
33
+ "suggested": "fast model (Haiku, GPT-4o-mini, Llama-3.3-70B, Gemini Flash)",
34
34
  },
35
35
  "harvest": {
36
36
  "description": "Content extraction & relevance filtering",
37
37
  "role": "Fast, cheap — filters irrelevant content, detects language",
38
- "default": "claude-haiku",
38
+ "suggested": "fast model (Haiku, GPT-4o-mini, Llama-3.3-70B, Gemini Flash)",
39
39
  },
40
40
  "process": {
41
41
  "description": "Claim extraction & quality scoring",
42
42
  "role": "Medium — extracts structured claims from text, scores quality",
43
- "default": "claude-haiku",
43
+ "suggested": "balanced model (Haiku, GPT-4o-mini, or Sonnet for quality)",
44
44
  },
45
45
  "synth": {
46
46
  "description": "Report synthesis & cross-referencing",
47
47
  "role": "Smart, thorough — synthesizes final report, deduplicates, verifies",
48
- "default": "claude-sonnet",
48
+ "suggested": "smart model (Sonnet, GPT-4o, Gemini Pro, Opus for max quality)",
49
49
  },
50
50
  }
51
51
 
52
- # Known model presets (user can also pass any litellm-compatible model string)
52
+ # Known model presets (user can also pass any litellm-compatible model string directly)
53
+ # These are convenience aliases — if your model isn't listed, just use the full string:
54
+ # BEHIVE_MODEL=anthropic/claude-sonnet-5-20260801
55
+ # BEHIVE_MODEL=openai/gpt-5.6-turbo
56
+ # Any string litellm recognizes works as-is.
53
57
  MODEL_PRESETS = {
54
- # Anthropic
55
- "claude-haiku": "anthropic/claude-3-5-haiku-20241022",
58
+ # Anthropic (latest as of July 2026)
59
+ "claude-haiku": "anthropic/claude-haiku-4-5-20251001",
56
60
  "claude-sonnet": "anthropic/claude-sonnet-4-20250514",
61
+ "claude-sonnet-5": "anthropic/claude-sonnet-5-20260715",
57
62
  "claude-opus": "anthropic/claude-opus-4-20250514",
63
+ "claude-opus-5": "anthropic/claude-opus-5-20260801",
64
+ "claude-fable": "anthropic/claude-fable-5-20260801",
58
65
  # OpenAI
59
66
  "gpt-4o-mini": "openai/gpt-4o-mini",
60
67
  "gpt-4o": "openai/gpt-4o",
61
68
  "gpt-4.1-mini": "openai/gpt-4.1-mini",
62
69
  "gpt-4.1": "openai/gpt-4.1",
70
+ "gpt-5": "openai/gpt-5",
71
+ "gpt-5-mini": "openai/gpt-5-mini",
63
72
  # AWS Bedrock
64
73
  "bedrock-haiku": "bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
65
74
  "bedrock-sonnet": "bedrock/us.anthropic.claude-sonnet-4-6-v1@us-east-1",
75
+ "bedrock-sonnet-5": "bedrock/us.anthropic.claude-sonnet-5-v1@us-east-1",
66
76
  "bedrock-opus": "bedrock/us.anthropic.claude-opus-4-6-v1@us-east-1",
77
+ "bedrock-opus-5": "bedrock/us.anthropic.claude-opus-5-v1@us-east-1",
67
78
  # Google
68
79
  "gemini-flash": "google/gemini-2.5-flash",
69
80
  "gemini-pro": "google/gemini-2.5-pro",
@@ -72,14 +83,15 @@ MODEL_PRESETS = {
72
83
  "ollama": "ollama/llama3.1",
73
84
  }
74
85
 
75
- # Recommended combos
86
+ # Recommended combos (provider-agnostic names that map via MODEL_PRESETS)
76
87
  RECOMMENDED_COMBOS = {
77
88
  "budget": {
78
- "description": "Cheapest — Haiku/GPT-4o-mini everywhere (~$0.30/mission)",
89
+ "description": "Cheapest — fast model everywhere (~$0.30/mission)",
79
90
  "scout": "claude-haiku",
80
91
  "harvest": "claude-haiku",
81
92
  "process": "claude-haiku",
82
93
  "synth": "claude-haiku",
94
+ "openai_alt": {"scout": "gpt-4o-mini", "harvest": "gpt-4o-mini", "process": "gpt-4o-mini", "synth": "gpt-4o-mini"},
83
95
  },
84
96
  "balanced": {
85
97
  "description": "Best value — cheap collection, smart synthesis (~$1.50/mission)",
@@ -87,13 +99,15 @@ RECOMMENDED_COMBOS = {
87
99
  "harvest": "claude-haiku",
88
100
  "process": "claude-haiku",
89
101
  "synth": "claude-sonnet",
102
+ "openai_alt": {"scout": "gpt-4o-mini", "harvest": "gpt-4o-mini", "process": "gpt-4o-mini", "synth": "gpt-4o"},
90
103
  },
91
104
  "quality": {
92
- "description": "Maximum quality — Sonnet everywhere (~$4.00/mission)",
105
+ "description": "Maximum quality — smart model everywhere (~$4.00/mission)",
93
106
  "scout": "claude-sonnet",
94
107
  "harvest": "claude-haiku",
95
108
  "process": "claude-sonnet",
96
109
  "synth": "claude-sonnet",
110
+ "openai_alt": {"scout": "gpt-4o", "harvest": "gpt-4o-mini", "process": "gpt-4o", "synth": "gpt-4o"},
97
111
  },
98
112
  "local": {
99
113
  "description": "Fully local — requires running LLM server ($0.00/mission)",
@@ -181,9 +195,9 @@ def get_model_for_stage(stage: str) -> str:
181
195
  if model_name:
182
196
  return MODEL_PRESETS.get(model_name, model_name)
183
197
 
184
- # Hardcoded default
185
- model_name = STAGES[stage]["default"]
186
- return MODEL_PRESETS.get(model_name, model_name)
198
+ # Hardcoded default — return empty string to let llm.py auto-detect
199
+ # from available API keys. We don't assume any provider here.
200
+ return ""
187
201
 
188
202
 
189
203
  def get_all_stage_models() -> dict:
@@ -40,6 +40,8 @@ import logging
40
40
  log = logging.getLogger(__name__)
41
41
  __all__ = [
42
42
  "orchestrator",
43
+ "queen",
44
+ "runner",
43
45
  "scout",
44
46
  "harvest",
45
47
  "process",