thoughtflow 0.0.1__py3-none-any.whl → 0.0.3__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.
@@ -0,0 +1,141 @@
1
+ """
2
+ Session object for ThoughtFlow.
3
+
4
+ A Session captures the complete state of an agent run, enabling
5
+ debugging, evaluation, reproducibility, and replay.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import uuid
12
+ from dataclasses import dataclass, field
13
+ from datetime import datetime
14
+ from pathlib import Path
15
+ from typing import TYPE_CHECKING, Any
16
+
17
+ if TYPE_CHECKING:
18
+ from thoughtflow.trace.events import Event
19
+
20
+
21
+ @dataclass
22
+ class Session:
23
+ """A session capturing the complete trace of an agent run.
24
+
25
+ Sessions are the foundation for:
26
+ - Debugging: See exactly what happened
27
+ - Evaluation: Measure quality and performance
28
+ - Reproducibility: Replay runs with same inputs
29
+ - Regression testing: Diff across versions/models
30
+
31
+ Attributes:
32
+ session_id: Unique identifier for this session.
33
+ created_at: When the session was created.
34
+ events: List of events that occurred during the run.
35
+ metadata: Additional session metadata.
36
+
37
+ Example:
38
+ >>> session = Session()
39
+ >>> session.add_event(Event(type="call_start", data={...}))
40
+ >>> session.add_event(Event(type="call_end", data={...}))
41
+ >>>
42
+ >>> # Get summary
43
+ >>> print(session.summary())
44
+ >>>
45
+ >>> # Save for later
46
+ >>> session.save("trace.json")
47
+ >>>
48
+ >>> # Load and replay
49
+ >>> loaded = Session.load("trace.json")
50
+ """
51
+
52
+ session_id: str = field(default_factory=lambda: str(uuid.uuid4()))
53
+ created_at: datetime = field(default_factory=datetime.now)
54
+ events: list[Event] = field(default_factory=list)
55
+ metadata: dict[str, Any] = field(default_factory=dict)
56
+
57
+ # Aggregated metrics (updated as events are added)
58
+ _total_tokens: int = field(default=0, repr=False)
59
+ _total_cost: float = field(default=0.0, repr=False)
60
+ _total_duration_ms: int = field(default=0, repr=False)
61
+
62
+ def add_event(self, event: Event) -> None:
63
+ """Add an event to the session.
64
+
65
+ Args:
66
+ event: The event to add.
67
+ """
68
+ self.events.append(event)
69
+ # TODO: Update aggregated metrics based on event type
70
+
71
+ @property
72
+ def total_tokens(self) -> int:
73
+ """Total tokens used across all model calls."""
74
+ return self._total_tokens
75
+
76
+ @property
77
+ def total_cost(self) -> float:
78
+ """Total cost in USD across all model calls."""
79
+ return self._total_cost
80
+
81
+ @property
82
+ def duration_ms(self) -> int:
83
+ """Total duration in milliseconds."""
84
+ return self._total_duration_ms
85
+
86
+ def summary(self) -> dict[str, Any]:
87
+ """Get a summary of the session.
88
+
89
+ Returns:
90
+ Dict with key metrics and counts.
91
+ """
92
+ return {
93
+ "session_id": self.session_id,
94
+ "created_at": self.created_at.isoformat(),
95
+ "event_count": len(self.events),
96
+ "total_tokens": self.total_tokens,
97
+ "total_cost": self.total_cost,
98
+ "duration_ms": self.duration_ms,
99
+ }
100
+
101
+ def to_dict(self) -> dict[str, Any]:
102
+ """Convert to a serializable dict.
103
+
104
+ Returns:
105
+ Complete session data as a dict.
106
+ """
107
+ return {
108
+ "session_id": self.session_id,
109
+ "created_at": self.created_at.isoformat(),
110
+ "events": [e.to_dict() for e in self.events],
111
+ "metadata": self.metadata,
112
+ "summary": self.summary(),
113
+ }
114
+
115
+ def save(self, path: str | Path) -> None:
116
+ """Save the session to a JSON file.
117
+
118
+ Args:
119
+ path: Path to save to.
120
+ """
121
+ path = Path(path)
122
+ path.write_text(json.dumps(self.to_dict(), indent=2))
123
+
124
+ @classmethod
125
+ def load(cls, path: str | Path) -> Session:
126
+ """Load a session from a JSON file.
127
+
128
+ Args:
129
+ path: Path to load from.
130
+
131
+ Returns:
132
+ Loaded Session instance.
133
+
134
+ Raises:
135
+ NotImplementedError: This is a placeholder implementation.
136
+ """
137
+ # TODO: Implement session loading with event deserialization
138
+ raise NotImplementedError(
139
+ "Session.load() is not yet implemented. "
140
+ "This is a placeholder for the ThoughtFlow alpha release."
141
+ )
@@ -0,0 +1,215 @@
1
+ Metadata-Version: 2.4
2
+ Name: thoughtflow
3
+ Version: 0.0.3
4
+ Summary: A minimal, explicit, Pythonic substrate for building reproducible, portable, testable LLM and agent systems.
5
+ Project-URL: Homepage, https://github.com/jrolf/thoughtflow
6
+ Project-URL: Documentation, https://thoughtflow.dev
7
+ Project-URL: Repository, https://github.com/jrolf/thoughtflow
8
+ Project-URL: Issues, https://github.com/jrolf/thoughtflow/issues
9
+ Project-URL: Changelog, https://github.com/jrolf/thoughtflow/blob/main/CHANGELOG.md
10
+ Author-email: "James A. Rolfsen" <james@think.dev>
11
+ Maintainer-email: "James A. Rolfsen" <james@think.dev>
12
+ License: MIT License
13
+
14
+ Copyright (c) 2025 James A. Rolfsen
15
+
16
+ Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ of this software and associated documentation files (the "Software"), to deal
18
+ in the Software without restriction, including without limitation the rights
19
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ copies of the Software, and to permit persons to whom the Software is
21
+ furnished to do so, subject to the following conditions:
22
+
23
+ The above copyright notice and this permission notice shall be included in all
24
+ copies or substantial portions of the Software.
25
+
26
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ SOFTWARE.
33
+ License-File: LICENSE
34
+ Keywords: agents,ai,anthropic,langchain-alternative,llm,machine-learning,openai,orchestration
35
+ Classifier: Development Status :: 3 - Alpha
36
+ Classifier: Intended Audience :: Developers
37
+ Classifier: License :: OSI Approved :: MIT License
38
+ Classifier: Operating System :: OS Independent
39
+ Classifier: Programming Language :: Python :: 3
40
+ Classifier: Programming Language :: Python :: 3.9
41
+ Classifier: Programming Language :: Python :: 3.10
42
+ Classifier: Programming Language :: Python :: 3.11
43
+ Classifier: Programming Language :: Python :: 3.12
44
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
45
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
46
+ Classifier: Typing :: Typed
47
+ Requires-Python: >=3.9
48
+ Provides-Extra: all
49
+ Requires-Dist: anthropic>=0.18; extra == 'all'
50
+ Requires-Dist: mkdocs-material>=9.0; extra == 'all'
51
+ Requires-Dist: mkdocs>=1.5; extra == 'all'
52
+ Requires-Dist: mkdocstrings[python]>=0.24; extra == 'all'
53
+ Requires-Dist: mypy>=1.0; extra == 'all'
54
+ Requires-Dist: ollama>=0.1; extra == 'all'
55
+ Requires-Dist: openai>=1.0; extra == 'all'
56
+ Requires-Dist: pre-commit>=3.0; extra == 'all'
57
+ Requires-Dist: pytest-asyncio>=0.21; extra == 'all'
58
+ Requires-Dist: pytest-cov>=4.0; extra == 'all'
59
+ Requires-Dist: pytest>=7.0; extra == 'all'
60
+ Requires-Dist: ruff>=0.1; extra == 'all'
61
+ Provides-Extra: all-providers
62
+ Requires-Dist: anthropic>=0.18; extra == 'all-providers'
63
+ Requires-Dist: ollama>=0.1; extra == 'all-providers'
64
+ Requires-Dist: openai>=1.0; extra == 'all-providers'
65
+ Provides-Extra: anthropic
66
+ Requires-Dist: anthropic>=0.18; extra == 'anthropic'
67
+ Provides-Extra: dev
68
+ Requires-Dist: mypy>=1.0; extra == 'dev'
69
+ Requires-Dist: pre-commit>=3.0; extra == 'dev'
70
+ Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
71
+ Requires-Dist: pytest-cov>=4.0; extra == 'dev'
72
+ Requires-Dist: pytest>=7.0; extra == 'dev'
73
+ Requires-Dist: ruff>=0.1; extra == 'dev'
74
+ Provides-Extra: docs
75
+ Requires-Dist: mkdocs-material>=9.0; extra == 'docs'
76
+ Requires-Dist: mkdocs>=1.5; extra == 'docs'
77
+ Requires-Dist: mkdocstrings[python]>=0.24; extra == 'docs'
78
+ Provides-Extra: local
79
+ Requires-Dist: ollama>=0.1; extra == 'local'
80
+ Provides-Extra: openai
81
+ Requires-Dist: openai>=1.0; extra == 'openai'
82
+ Description-Content-Type: text/markdown
83
+
84
+ # ThoughtFlow
85
+
86
+ [![PyPI version](https://badge.fury.io/py/thoughtflow.svg)](https://badge.fury.io/py/thoughtflow)
87
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
88
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
89
+ [![CI](https://github.com/jrolf/thoughtflow/actions/workflows/ci.yml/badge.svg)](https://github.com/jrolf/thoughtflow/actions/workflows/ci.yml)
90
+
91
+ **A minimal, explicit, Pythonic substrate for building reproducible, portable, testable LLM and agent systems.**
92
+
93
+ > *Tiny surface area. Explicit state. Portable execution. Deterministic testing.*
94
+
95
+ ---
96
+
97
+ ## Why ThoughtFlow?
98
+
99
+ The modern LLM/agent ecosystem often evolves into abstraction swamps—hidden state, magical callbacks, and frameworks that are hard to understand, test, and deploy.
100
+
101
+ **ThoughtFlow takes a different path:**
102
+
103
+ - ✅ **No hidden agent runtime** you can't reason about
104
+ - ✅ **No graph DSL** you must adopt to do anything serious
105
+ - ✅ **No implicit global memory** or callback chains
106
+ - ✅ **No abstraction layers** whose main job is wrapping other abstractions
107
+
108
+ Instead, ThoughtFlow makes orchestration logic **plain Python**: explicit inputs, explicit outputs, explicit state transitions, replayable sessions, deterministic evaluation paths.
109
+
110
+ ---
111
+
112
+ ## Installation
113
+
114
+ ```bash
115
+ # Core library (zero dependencies)
116
+ pip install thoughtflow
117
+
118
+ # With OpenAI support
119
+ pip install thoughtflow[openai]
120
+
121
+ # With Anthropic support
122
+ pip install thoughtflow[anthropic]
123
+
124
+ # With all providers
125
+ pip install thoughtflow[all-providers]
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Quick Start
131
+
132
+ ```python
133
+ from thoughtflow import Agent
134
+ from thoughtflow.adapters import OpenAIAdapter
135
+
136
+ # Create an adapter for your provider
137
+ adapter = OpenAIAdapter(api_key="your-api-key")
138
+
139
+ # Create an agent
140
+ agent = Agent(adapter)
141
+
142
+ # Call with a message list (the universal currency)
143
+ response = agent.call([
144
+ {"role": "system", "content": "You are a helpful assistant."},
145
+ {"role": "user", "content": "What is ThoughtFlow?"}
146
+ ])
147
+
148
+ print(response)
149
+ ```
150
+
151
+ ---
152
+
153
+ ## Core Concepts
154
+
155
+ ### The Agent Contract
156
+
157
+ An Agent is something that can be called with messages and parameters:
158
+
159
+ ```python
160
+ class Agent:
161
+ def call(self, msg_list, params=None):
162
+ raise NotImplementedError
163
+ ```
164
+
165
+ That's it. Everything else is composition.
166
+
167
+ ### Messages: Stable Schema, Minimal Assumptions
168
+
169
+ ```python
170
+ msg_list = [
171
+ {"role": "system", "content": "You are a helpful assistant."},
172
+ {"role": "user", "content": "Draft 3 names for a company."},
173
+ ]
174
+ ```
175
+
176
+ ### Explicit Tracing
177
+
178
+ ```python
179
+ from thoughtflow.trace import Session
180
+
181
+ session = Session()
182
+ response = agent.call(msg_list, session=session)
183
+
184
+ # Session captures everything: inputs, outputs, timing, tokens, costs
185
+ print(session.to_dict())
186
+ ```
187
+
188
+ ---
189
+
190
+ ## Design Principles
191
+
192
+ 1. **Tiny Surface Area**: Few powerful primitives over many specialized classes
193
+ 2. **Explicit State**: All state is visible, serializable, and replayable
194
+ 3. **Portability**: Works across OpenAI, Anthropic, local models, serverless
195
+ 4. **Deterministic Testing**: Record/replay workflows, stable sessions, predictable behavior
196
+
197
+ ---
198
+
199
+ ## Project Status
200
+
201
+ 🚧 **Alpha** - ThoughtFlow is under active development. The API may change.
202
+
203
+ See the [CHANGELOG](CHANGELOG.md) for version history.
204
+
205
+ ---
206
+
207
+ ## Contributing
208
+
209
+ We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
210
+
211
+ ---
212
+
213
+ ## License
214
+
215
+ [MIT](LICENSE) © James A. Rolfsen
@@ -0,0 +1,25 @@
1
+ thoughtflow/__init__.py,sha256=oeMPn51oJCvIB1m4hOj7yemq_2Ng9sTAlQ3zb0nNXnU,2541
2
+ thoughtflow/_util.py,sha256=c0pMAdFXCGUFf9yhK3xwnqAD3SrlijD0eJVh0EekjMA,25260
3
+ thoughtflow/action.py,sha256=ZCKC95luZwZPEUkHIf8V0ZYxRXZ_msFLtb85Zs_cETg,14246
4
+ thoughtflow/agent.py,sha256=nSwUwUjjkcE2_dF81waSqRFmQ8xW3nQgwzX1VlEOJMo,1977
5
+ thoughtflow/llm.py,sha256=_aZiTHzlavabeKNgdYd-uM45_R10JvvgEgSavNx_k0M,10528
6
+ thoughtflow/message.py,sha256=5hR2Zs3tDRYLtYuuArqmJ4CgBDTUhjHj_RQhCN7tRrg,3800
7
+ thoughtflow/py.typed,sha256=Y3QpSe9qtWcL1vKplcWdRY0cn5071TLJQWBO0QbxTm8,84
8
+ thoughtflow/thought.py,sha256=i5Ca0IxaVGE688AhCpYFlk2vnJzotWZTX2IsW3cuLLU,43229
9
+ thoughtflow/thoughtflow6.py,sha256=GMKlqxFyNvvMD7yIU7NEYAtuDZplapeFeK1pGf20u5o,162824
10
+ thoughtflow/eval/__init__.py,sha256=WiXk5IarMdgQV-mCpWVq_ZwCq6iC6pAKwl9wbZsmmNA,866
11
+ thoughtflow/eval/harness.py,sha256=DH8EGajfxIGsb9HLk7g-hnQM0t1C90VAk7bOPLK9OBQ,5505
12
+ thoughtflow/eval/replay.py,sha256=-osU4BbjVdThLeM1bygCss7sqqHHvg9I43XEvVZkNd8,4011
13
+ thoughtflow/memory/__init__.py,sha256=3DAxZ4NlvJbvyP-8p86WlwoU1BUF24V97a4Z0c0ZC0w,859
14
+ thoughtflow/memory/base.py,sha256=TQn0JJd_t_k4FW73MWEbYNudwe0GEaaDqRyZIe9irvo,64870
15
+ thoughtflow/tools/__init__.py,sha256=1bDivRtNS2rGDForiLMOGKjStBeZAWFH8wylAN3Ihjk,648
16
+ thoughtflow/tools/base.py,sha256=VYRFDhzG912HFUR6W82kykm_FU-r4xg4aEzHBDN_b8M,4069
17
+ thoughtflow/tools/registry.py,sha256=ERKStxvh_UkfLg7GebVFaifSuudFYAfYXbnxr7lC5o0,3335
18
+ thoughtflow/trace/__init__.py,sha256=fQSpJJyYdtaI_L_QAD4NqvYA6yXS5xCJXxS5-rVUpoM,891
19
+ thoughtflow/trace/events.py,sha256=jJtVzs2xSLb43CAW6_CqgBVGgM0gBJ1x-_xmQjwUGkw,4647
20
+ thoughtflow/trace/schema.py,sha256=teyUJ3gV80ZgsU8oCYJmku_f-SDULKtvqqLjvp1eQ_E,3180
21
+ thoughtflow/trace/session.py,sha256=ZYKMGe3t98A7LujG-nSuRQo83BvzqhZGKFXHZZU0amw,4225
22
+ thoughtflow-0.0.3.dist-info/METADATA,sha256=4QewTCLBg1f8bGIsJiqUf6HPrZCMlk27t80eLiFGmkc,7548
23
+ thoughtflow-0.0.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
24
+ thoughtflow-0.0.3.dist-info/licenses/LICENSE,sha256=Z__Z0xyty_n2lxI7UNvfqkgemXIP0_UliF5sZN8GsPw,1073
25
+ thoughtflow-0.0.3.dist-info/RECORD,,
@@ -1,5 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.2)
2
+ Generator: hatchling 1.28.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
-
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 James A. Rolfsen
3
+ Copyright (c) 2025 James A. Rolfsen
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
thoughtflow/jtools1.py DELETED
@@ -1,25 +0,0 @@
1
-
2
- import numpy as np
3
-
4
- class Sorter:
5
- def __init__(self):
6
- self.x = np.array([])
7
- def sort_things(self,things):
8
- idx = np.argsort(things)
9
- return np.array(things)[idx]
10
-
11
-
12
- Notes = '''
13
-
14
- S = Sorter()
15
- things1 = [5,1,4,2,3]
16
- things2 = S.sort_things(things1)
17
-
18
-
19
- '''
20
-
21
-
22
-
23
-
24
-
25
-
thoughtflow/jtools2.py DELETED
@@ -1,27 +0,0 @@
1
-
2
- import numpy as np
3
-
4
- class Adder:
5
- def __init__(self):
6
- self.x = np.array([])
7
- def add_things(self,things1,things2):
8
- a = np.array(things1)
9
- b = np.array(things2)
10
- return a+b
11
-
12
-
13
- Notes = '''
14
-
15
- things1 = [5,1,4,2,3]
16
- things2 = [1,2,3,4,5]
17
-
18
- A = Adder()
19
- things3 = A.add_things(things1)
20
-
21
- '''
22
-
23
-
24
-
25
-
26
-
27
-
@@ -1,17 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: thoughtflow
3
- Version: 0.0.1
4
- Summary: Short Description
5
- Home-page: https://github.com/jrolf/rolfdog
6
- Author: James A. Rolfsen
7
- Author-email: james@think.dev
8
- Classifier: Programming Language :: Python :: 3.12
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: OS Independent
11
- Classifier: Natural Language :: English
12
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
- License-File: LICENSE
14
- Requires-Dist: numpy >=1.1.1
15
- Requires-Dist: pandas >=0.1.1
16
-
17
- Long Description
@@ -1,8 +0,0 @@
1
- thoughtflow/__init__.py,sha256=1k9Fv27FmuVKKsy5O4mwLU9VCcSuRprW_P50yCN0qYg,223
2
- thoughtflow/jtools1.py,sha256=blvqa6ipN4aprYVfsw2sPoyJqJswk1Riw74PC_t_Yzk,269
3
- thoughtflow/jtools2.py,sha256=vqxDivVtzhwDz_-qwg5c8RsNZurEbK9r1WaFLSDiQNk,298
4
- thoughtflow-0.0.1.dist-info/LICENSE,sha256=a5AbP99aMpQEW-PKXUuR7qNHxvXnSC-R3M02LBusp6g,1073
5
- thoughtflow-0.0.1.dist-info/METADATA,sha256=d-pYfPPzWbyvqY4AQHkv_AJOwoxFZYadKlsZAim5g8U,542
6
- thoughtflow-0.0.1.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
7
- thoughtflow-0.0.1.dist-info/top_level.txt,sha256=vuLVkcDNHCDfhFcrdwBW62c9gOII2XuyWax3-cWVHCE,12
8
- thoughtflow-0.0.1.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- thoughtflow