thought-fork 0.6.0__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.
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Ameen Saeed
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,213 @@
1
+ Metadata-Version: 2.4
2
+ Name: thought-fork
3
+ Version: 0.6.0
4
+ Summary: Branch AI reasoning into parallel thought paths
5
+ Author: Ameen Saeed
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/A-radman9/Thought-Fork
8
+ Project-URL: Documentation, https://github.com/A-radman9/Thought-Fork#readme
9
+ Project-URL: Repository, https://github.com/A-radman9/Thought-Fork
10
+ Project-URL: Issues, https://github.com/A-radman9/Thought-Fork/issues
11
+ Keywords: ai,reasoning,parallel,fork,synthesis,llm,thought-fork
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: openai>=1.86.0
23
+ Requires-Dist: python-dotenv>=1.1.0
24
+ Provides-Extra: api
25
+ Requires-Dist: fastapi>=0.115.0; extra == "api"
26
+ Requires-Dist: uvicorn[standard]>=0.34.0; extra == "api"
27
+ Requires-Dist: sse-starlette>=2.3.0; extra == "api"
28
+ Requires-Dist: aiosqlite>=0.21.0; extra == "api"
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
31
+ Requires-Dist: pytest-asyncio>=0.25.0; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ # 🔀 Thought Fork
35
+
36
+ **Branch your AI's reasoning like Git branches.**
37
+
38
+ Thought Fork is a Python framework that introduces **Attributed Convergence** to AI reasoning. Instead of asking a single AI model to give you one generic answer, Thought Fork dynamically invents $N$ distinct reasoning perspectives (stances) tailored to your specific prompt, branches the AI into parallel reasoning streams, and then merges them back together into a single, synthesized, highly-structured answer.
39
+
40
+ The result? The AI explicitly credits *which* perspective contributed *what* insight, providing unprecedented transparency and depth.
41
+
42
+ *Created by **Ameen Saeed** (Copyright © 2026).*
43
+
44
+ ---
45
+
46
+ ## 🚀 Why Thought Fork?
47
+
48
+ Standard LLM queries suffer from "averaging"—they give you the safest, most generic middle-ground answer.
49
+ Thought Fork solves this by forcing the model to argue with itself from distinct angles before concluding.
50
+
51
+ **Features:**
52
+ - 🧠 **Dynamic Stance Selection:** The engine analyzes your prompt and automatically invents the perfect reasoning personas (e.g., *a pragmatic-startup-builder*, *a long-term-code-quality-advocate*, and *a performance-focused-engineer*).
53
+ - ⚡ **Parallel Execution:** Forks are resolved concurrently using `asyncio`.
54
+ - 🧬 **Attributed Convergence (Synthesis):** The final output weaves the parallel thoughts together, explicitly crediting the source of each idea and resolving contradictions.
55
+ - 📡 **Server-Sent Events (SSE) Streaming:** Fully built-in SSE support for real-time frontend streaming of parallel forks.
56
+
57
+ ---
58
+
59
+ ## 📦 Installation
60
+
61
+ ```bash
62
+ pip install thought-fork
63
+ ```
64
+
65
+ ### Requirements
66
+ - Python 3.10+
67
+ - `openai` (used as the universal async client)
68
+ - `pydantic`
69
+
70
+ ---
71
+
72
+ ## 🔑 Configuration (Bring Your Own API)
73
+
74
+ Thought Fork is provider-agnostic. Because it relies on the universal `AsyncOpenAI` client, you can use **OpenAI**, **Anthropic** (via OpenRouter), **Gemini**, or **Local Models** (like Ollama).
75
+
76
+ By default, the library expects your API key in the environment variables:
77
+ ```bash
78
+ export OPENROUTER_API_KEY="your-key-here"
79
+ # or
80
+ export OPENAI_API_KEY="your-key-here"
81
+ ```
82
+
83
+ You can also pass the configuration explicitly in code using `ForkConfig`:
84
+
85
+ ```python
86
+ from thought_fork import ForkConfig
87
+ from openai import AsyncOpenAI
88
+
89
+ # 1. OpenAI Directly
90
+ config = ForkConfig(
91
+ api_key="sk-proj-...",
92
+ api_base_url="https://api.openai.com/v1",
93
+ fork_model="gpt-4o-mini",
94
+ synthesis_model="gpt-4o",
95
+ stance_selector_model="gpt-4o-mini"
96
+ )
97
+
98
+ # 2. Google Gemini (via OpenAI compatibility)
99
+ config = ForkConfig(
100
+ api_key="your-google-api-key",
101
+ api_base_url="https://generativelanguage.googleapis.com/v1beta/openai",
102
+ fork_model="gemini-2.0-flash",
103
+ synthesis_model="gemini-2.0-pro-exp",
104
+ stance_selector_model="gemini-2.0-flash"
105
+ )
106
+
107
+ # 3. Local Models (Ollama / vLLM)
108
+ # API key is automatically bypassed for localhost URLs
109
+ config = ForkConfig(
110
+ api_base_url="http://localhost:11434/v1",
111
+ fork_model="llama3",
112
+ synthesis_model="llama3",
113
+ stance_selector_model="llama3"
114
+ )
115
+
116
+ # 4. Anthropic / Any Provider via OpenRouter (Default)
117
+ config = ForkConfig(
118
+ api_key="sk-or-v1-...",
119
+ api_base_url="https://openrouter.ai/api/v1",
120
+ fork_model="anthropic/claude-haiku-4.5",
121
+ synthesis_model="anthropic/claude-sonnet-4-6",
122
+ stance_selector_model="anthropic/claude-haiku-4.5"
123
+ )
124
+
125
+ # 5. Enterprise BYOC (Bring Your Own Client)
126
+ # If you have custom proxies, headers, or httpx settings:
127
+ my_client = AsyncOpenAI(api_key="...", default_headers={"X-Custom": "123"})
128
+ config = ForkConfig(client=my_client)
129
+ ```
130
+
131
+ ### Production Resilience
132
+ Thought Fork v0.6+ is designed for production reliability:
133
+ - **Concurrency Limiting:** `max_concurrent_forks=5` protects against 429 rate limits.
134
+ - **Automatic Retries:** `max_retries=2` silently handles 502 Bad Gateway errors with exponential backoff.
135
+ - **Graceful Degradation:** If a fork completely fails, synthesis continues with the remaining successful forks.
136
+
137
+ ---
138
+
139
+ ## 💻 Quickstart (Python SDK)
140
+
141
+ The easiest way to use Thought Fork is via the `synthesize()` helper function.
142
+
143
+ ```python
144
+ import asyncio
145
+ from thought_fork import synthesize, ForkConfig
146
+
147
+ async def main():
148
+ config = ForkConfig(api_key="your-api-key")
149
+ prompt = "Should I build a monolith or microservices for my new startup?"
150
+
151
+ # This automatically invents 3 custom stances, runs them in parallel,
152
+ # and synthesizes the final answer.
153
+ result = await synthesize(prompt, fork_count=3, config=config)
154
+
155
+ print("--- Synthesis ---")
156
+ print(result.synthesis)
157
+
158
+ print("\n--- Individual Forks ---")
159
+ for detail in result.fork_details:
160
+ print(f"Fork {detail['id']} ({detail['stance']}): {detail['token_count']} tokens")
161
+
162
+ print(f"\nTotal tokens: {result.token_usage['total']}")
163
+
164
+ if __name__ == "__main__":
165
+ asyncio.run(main())
166
+ ```
167
+
168
+ ### Advanced Usage (Manual Forks)
169
+
170
+ If you want to manually specify the stances instead of letting the AI invent them dynamically:
171
+
172
+ ```python
173
+ from thought_fork import synthesize
174
+
175
+ stances = ["cautious", "creative", "pragmatic"]
176
+ result = await synthesize(prompt, stances=stances)
177
+ ```
178
+
179
+ Or you can use the `ForkManager` directly to build your own custom pipeline (see the `examples/` directory in the repository).
180
+
181
+ ---
182
+
183
+ ## 🌐 The API Engine (FastAPI + SSE)
184
+
185
+ Thought Fork isn't just a Python library; it ships with a production-ready **FastAPI streaming engine**.
186
+
187
+ To start the API server locally:
188
+ ```bash
189
+ uvicorn api.main:app --port 8000
190
+ ```
191
+
192
+ The server exposes a POST `/fork` endpoint that streams Server-Sent Events (SSE).
193
+
194
+ **Event Flow:**
195
+ 1. `stances_selected` — Emitted first with the AI's chosen personas for the prompt.
196
+ 2. `fork_start` — Emitted when a specific reasoning path begins.
197
+ 3. `fork_chunk` — Real-time tokens streamed from parallel forks (interleaved).
198
+ 4. `fork_done` — Emitted when a fork finishes.
199
+ 5. `synthesis_chunk` — Real-time tokens for the final convergence.
200
+ 6. `synthesis_done` — Final event with token usage, timing metrics, and a `session_id`.
201
+
202
+ *(See `api/streaming.py` for the full implementation.)*
203
+
204
+ ---
205
+
206
+ ## 📜 License & Copyright
207
+
208
+ Thought Fork is open-source software licensed under the **Apache License 2.0**.
209
+
210
+ **Copyright © 2026 Ameen Saeed.**
211
+ If you use, modify, or distribute this framework, you must include the original copyright notice.
212
+
213
+ > "A tool is only as good as the perspectives it considers."
@@ -0,0 +1,180 @@
1
+ # 🔀 Thought Fork
2
+
3
+ **Branch your AI's reasoning like Git branches.**
4
+
5
+ Thought Fork is a Python framework that introduces **Attributed Convergence** to AI reasoning. Instead of asking a single AI model to give you one generic answer, Thought Fork dynamically invents $N$ distinct reasoning perspectives (stances) tailored to your specific prompt, branches the AI into parallel reasoning streams, and then merges them back together into a single, synthesized, highly-structured answer.
6
+
7
+ The result? The AI explicitly credits *which* perspective contributed *what* insight, providing unprecedented transparency and depth.
8
+
9
+ *Created by **Ameen Saeed** (Copyright © 2026).*
10
+
11
+ ---
12
+
13
+ ## 🚀 Why Thought Fork?
14
+
15
+ Standard LLM queries suffer from "averaging"—they give you the safest, most generic middle-ground answer.
16
+ Thought Fork solves this by forcing the model to argue with itself from distinct angles before concluding.
17
+
18
+ **Features:**
19
+ - 🧠 **Dynamic Stance Selection:** The engine analyzes your prompt and automatically invents the perfect reasoning personas (e.g., *a pragmatic-startup-builder*, *a long-term-code-quality-advocate*, and *a performance-focused-engineer*).
20
+ - ⚡ **Parallel Execution:** Forks are resolved concurrently using `asyncio`.
21
+ - 🧬 **Attributed Convergence (Synthesis):** The final output weaves the parallel thoughts together, explicitly crediting the source of each idea and resolving contradictions.
22
+ - 📡 **Server-Sent Events (SSE) Streaming:** Fully built-in SSE support for real-time frontend streaming of parallel forks.
23
+
24
+ ---
25
+
26
+ ## 📦 Installation
27
+
28
+ ```bash
29
+ pip install thought-fork
30
+ ```
31
+
32
+ ### Requirements
33
+ - Python 3.10+
34
+ - `openai` (used as the universal async client)
35
+ - `pydantic`
36
+
37
+ ---
38
+
39
+ ## 🔑 Configuration (Bring Your Own API)
40
+
41
+ Thought Fork is provider-agnostic. Because it relies on the universal `AsyncOpenAI` client, you can use **OpenAI**, **Anthropic** (via OpenRouter), **Gemini**, or **Local Models** (like Ollama).
42
+
43
+ By default, the library expects your API key in the environment variables:
44
+ ```bash
45
+ export OPENROUTER_API_KEY="your-key-here"
46
+ # or
47
+ export OPENAI_API_KEY="your-key-here"
48
+ ```
49
+
50
+ You can also pass the configuration explicitly in code using `ForkConfig`:
51
+
52
+ ```python
53
+ from thought_fork import ForkConfig
54
+ from openai import AsyncOpenAI
55
+
56
+ # 1. OpenAI Directly
57
+ config = ForkConfig(
58
+ api_key="sk-proj-...",
59
+ api_base_url="https://api.openai.com/v1",
60
+ fork_model="gpt-4o-mini",
61
+ synthesis_model="gpt-4o",
62
+ stance_selector_model="gpt-4o-mini"
63
+ )
64
+
65
+ # 2. Google Gemini (via OpenAI compatibility)
66
+ config = ForkConfig(
67
+ api_key="your-google-api-key",
68
+ api_base_url="https://generativelanguage.googleapis.com/v1beta/openai",
69
+ fork_model="gemini-2.0-flash",
70
+ synthesis_model="gemini-2.0-pro-exp",
71
+ stance_selector_model="gemini-2.0-flash"
72
+ )
73
+
74
+ # 3. Local Models (Ollama / vLLM)
75
+ # API key is automatically bypassed for localhost URLs
76
+ config = ForkConfig(
77
+ api_base_url="http://localhost:11434/v1",
78
+ fork_model="llama3",
79
+ synthesis_model="llama3",
80
+ stance_selector_model="llama3"
81
+ )
82
+
83
+ # 4. Anthropic / Any Provider via OpenRouter (Default)
84
+ config = ForkConfig(
85
+ api_key="sk-or-v1-...",
86
+ api_base_url="https://openrouter.ai/api/v1",
87
+ fork_model="anthropic/claude-haiku-4.5",
88
+ synthesis_model="anthropic/claude-sonnet-4-6",
89
+ stance_selector_model="anthropic/claude-haiku-4.5"
90
+ )
91
+
92
+ # 5. Enterprise BYOC (Bring Your Own Client)
93
+ # If you have custom proxies, headers, or httpx settings:
94
+ my_client = AsyncOpenAI(api_key="...", default_headers={"X-Custom": "123"})
95
+ config = ForkConfig(client=my_client)
96
+ ```
97
+
98
+ ### Production Resilience
99
+ Thought Fork v0.6+ is designed for production reliability:
100
+ - **Concurrency Limiting:** `max_concurrent_forks=5` protects against 429 rate limits.
101
+ - **Automatic Retries:** `max_retries=2` silently handles 502 Bad Gateway errors with exponential backoff.
102
+ - **Graceful Degradation:** If a fork completely fails, synthesis continues with the remaining successful forks.
103
+
104
+ ---
105
+
106
+ ## 💻 Quickstart (Python SDK)
107
+
108
+ The easiest way to use Thought Fork is via the `synthesize()` helper function.
109
+
110
+ ```python
111
+ import asyncio
112
+ from thought_fork import synthesize, ForkConfig
113
+
114
+ async def main():
115
+ config = ForkConfig(api_key="your-api-key")
116
+ prompt = "Should I build a monolith or microservices for my new startup?"
117
+
118
+ # This automatically invents 3 custom stances, runs them in parallel,
119
+ # and synthesizes the final answer.
120
+ result = await synthesize(prompt, fork_count=3, config=config)
121
+
122
+ print("--- Synthesis ---")
123
+ print(result.synthesis)
124
+
125
+ print("\n--- Individual Forks ---")
126
+ for detail in result.fork_details:
127
+ print(f"Fork {detail['id']} ({detail['stance']}): {detail['token_count']} tokens")
128
+
129
+ print(f"\nTotal tokens: {result.token_usage['total']}")
130
+
131
+ if __name__ == "__main__":
132
+ asyncio.run(main())
133
+ ```
134
+
135
+ ### Advanced Usage (Manual Forks)
136
+
137
+ If you want to manually specify the stances instead of letting the AI invent them dynamically:
138
+
139
+ ```python
140
+ from thought_fork import synthesize
141
+
142
+ stances = ["cautious", "creative", "pragmatic"]
143
+ result = await synthesize(prompt, stances=stances)
144
+ ```
145
+
146
+ Or you can use the `ForkManager` directly to build your own custom pipeline (see the `examples/` directory in the repository).
147
+
148
+ ---
149
+
150
+ ## 🌐 The API Engine (FastAPI + SSE)
151
+
152
+ Thought Fork isn't just a Python library; it ships with a production-ready **FastAPI streaming engine**.
153
+
154
+ To start the API server locally:
155
+ ```bash
156
+ uvicorn api.main:app --port 8000
157
+ ```
158
+
159
+ The server exposes a POST `/fork` endpoint that streams Server-Sent Events (SSE).
160
+
161
+ **Event Flow:**
162
+ 1. `stances_selected` — Emitted first with the AI's chosen personas for the prompt.
163
+ 2. `fork_start` — Emitted when a specific reasoning path begins.
164
+ 3. `fork_chunk` — Real-time tokens streamed from parallel forks (interleaved).
165
+ 4. `fork_done` — Emitted when a fork finishes.
166
+ 5. `synthesis_chunk` — Real-time tokens for the final convergence.
167
+ 6. `synthesis_done` — Final event with token usage, timing metrics, and a `session_id`.
168
+
169
+ *(See `api/streaming.py` for the full implementation.)*
170
+
171
+ ---
172
+
173
+ ## 📜 License & Copyright
174
+
175
+ Thought Fork is open-source software licensed under the **Apache License 2.0**.
176
+
177
+ **Copyright © 2026 Ameen Saeed.**
178
+ If you use, modify, or distribute this framework, you must include the original copyright notice.
179
+
180
+ > "A tool is only as good as the perspectives it considers."
@@ -0,0 +1,56 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "thought-fork"
7
+ version = "0.6.0"
8
+ description = "Branch AI reasoning into parallel thought paths"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ requires-python = ">=3.11"
12
+ authors = [
13
+ { name = "Ameen Saeed" },
14
+ ]
15
+ keywords = ["ai", "reasoning", "parallel", "fork", "synthesis", "llm", "thought-fork"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Developers",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
24
+ ]
25
+ dependencies = [
26
+ "openai>=1.86.0",
27
+ "python-dotenv>=1.1.0",
28
+ ]
29
+
30
+ [project.optional-dependencies]
31
+ api = [
32
+ "fastapi>=0.115.0",
33
+ "uvicorn[standard]>=0.34.0",
34
+ "sse-starlette>=2.3.0",
35
+ "aiosqlite>=0.21.0",
36
+ ]
37
+ dev = [
38
+ "pytest>=8.0.0",
39
+ "pytest-asyncio>=0.25.0",
40
+ ]
41
+
42
+ [project.scripts]
43
+ thought-fork = "thought_fork.cli:main"
44
+
45
+ [project.urls]
46
+ Homepage = "https://github.com/A-radman9/Thought-Fork"
47
+ Documentation = "https://github.com/A-radman9/Thought-Fork#readme"
48
+ Repository = "https://github.com/A-radman9/Thought-Fork"
49
+ Issues = "https://github.com/A-radman9/Thought-Fork/issues"
50
+
51
+ [tool.setuptools.packages.find]
52
+ include = ["thought_fork*"]
53
+
54
+ [tool.pytest.ini_options]
55
+ asyncio_mode = "auto"
56
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+