loopgain 0.1.0__tar.gz → 0.1.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.
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: loopgain
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Barkhausen stability monitor for AI agent loops. Real-time loop-gain (Aβ) monitoring with five named threshold bands, best-so-far rollback, and ETA prediction.
5
5
  Author-email: Dave Fitzsimmons <dave_fitz@icloud.com>
6
6
  License: Apache-2.0
7
7
  Project-URL: Homepage, https://loopgain.ai
8
8
  Project-URL: Repository, https://github.com/loopgain-ai/loopgain
9
9
  Project-URL: Issues, https://github.com/loopgain-ai/loopgain/issues
10
- Keywords: ai,agent,barkhausen,loop-stability,control-theory,feedback-loop,llm,agentic,verify-revise,convergence
10
+ Keywords: ai,agent,ai-agent,ai-agents,agentic,agentic-ai,llm,llm-agent,llm-orchestration,agent-orchestration,agent-loop,verify-revise,verify-revise-loop,gvr,generator-verifier-reviser,convergence,divergence-detection,infinite-loop,infinite-loop-detection,loop-detection,loop-stability,stability-monitor,early-stopping,max-iterations,barkhausen,barkhausen-criterion,control-theory,feedback-loop,feedback-loop-stability,loop-gain,rollback,best-so-far,langgraph,crewai,autogen,claude,anthropic,openai
11
11
  Classifier: Development Status :: 3 - Alpha
12
12
  Classifier: Intended Audience :: Developers
13
13
  Classifier: License :: OSI Approved :: Apache Software License
@@ -28,13 +28,18 @@ Dynamic: license-file
28
28
 
29
29
  # LoopGain
30
30
 
31
- **Barkhausen stability monitor for AI agent verify-revise loops.**
31
+ **Barkhausen stability monitor for AI agent loops.**
32
32
 
33
33
  Replace `max_iterations=5` with a real-time loop-gain (`Aβ`) monitor that knows whether your agent loop is converging, stalling, oscillating, or diverging — and what to do in each case.
34
34
 
35
35
  [![PyPI](https://img.shields.io/pypi/v/loopgain.svg)](https://pypi.org/project/loopgain/)
36
36
  [![Python](https://img.shields.io/pypi/pyversions/loopgain.svg)](https://pypi.org/project/loopgain/)
37
37
  [![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](LICENSE)
38
+ [![Tests](https://img.shields.io/badge/tests-73_passing-brightgreen.svg)](tests/)
39
+
40
+ Works for **any iterative AI workflow with a measurable error signal** — verify-revise loops, refinement passes, tool-use retry chains, RAG with self-correction, code-gen with linter feedback, multi-step reasoning loops. Integrates with **LangGraph**, **CrewAI**, **AutoGen**, **Claude Agent SDK**, and custom stacks. Pure Python, no runtime dependencies.
41
+
42
+ **Keywords:** AI agent loops · agentic AI · infinite loop detection · divergence detection · early stopping · convergence · agent orchestration · LLM stability · generator-verifier-reviser · feedback-loop control.
38
43
 
39
44
  ---
40
45
 
@@ -42,8 +47,6 @@ Replace `max_iterations=5` with a real-time loop-gain (`Aβ`) monitor that knows
42
47
 
43
48
  Production agent loops universally use `max_iterations=N` as their termination policy. It's the embarrassing default of agentic AI: you either waste compute (loop stops too late) or ship bad output (loop stops too early). LoopGain replaces it with a control-theoretic stability monitor based on the **Barkhausen criterion** — a foundational result from electrical-engineering feedback-oscillator analysis (1921).
44
49
 
45
- The math is foundational. The product is the threshold bands, the best-so-far buffer, the ETA prediction, and the clean Python API.
46
-
47
50
  ---
48
51
 
49
52
  ## Install
@@ -58,7 +61,7 @@ Pure Python, no dependencies, supports Python 3.10+.
58
61
 
59
62
  ## Usage
60
63
 
61
- Three lines of code wrap any verify-revise loop:
64
+ Three lines of code wrap any iterative loop with a measurable error signal:
62
65
 
63
66
  ```python
64
67
  from loopgain import LoopGain
@@ -169,24 +172,42 @@ Terminal result with `outcome`, `iterations_used`, `best_index`, `best_output`,
169
172
  **Opt-in.** Send a single anonymized telemetry POST after the loop terminates. Best-effort — never raises, returns `True` on 2xx, `False` otherwise.
170
173
 
171
174
  ```python
175
+ import os
176
+ from loopgain import LoopGain
177
+
178
+ lg = LoopGain(target_error=0.1)
179
+ # ... run the loop ...
172
180
  lg.send_telemetry(
173
- endpoint="https://telemetry.loopgain.ai/v1/aggregate", # or self-hosted
174
- token="your-token", # bearer auth
175
- workload_id="my-rag-pipeline", # opaque label
181
+ endpoint=os.environ["LOOPGAIN_TELEMETRY_ENDPOINT"], # or hardcode
182
+ token=os.environ["LOOPGAIN_TELEMETRY_TOKEN"], # never hardcode
183
+ workload_id="my-rag-pipeline", # opaque label
176
184
  )
177
185
  ```
178
186
 
187
+ Recommended setup: store the token outside source. Two clean options:
188
+
189
+ ```bash
190
+ # Option A: environment variable (simplest)
191
+ export LOOPGAIN_TELEMETRY_ENDPOINT="https://telemetry.loopgain.ai/v1/aggregate"
192
+ export LOOPGAIN_TELEMETRY_TOKEN="lgk_..." # add to ~/.zshrc or ~/.bashrc
193
+
194
+ # Option B: macOS Keychain (more secure)
195
+ pip install keyring
196
+ python3 -c "import keyring; keyring.set_password('loopgain', 'telemetry', input('Token: '))"
197
+ # Then in code: keyring.get_password('loopgain', 'telemetry')
198
+ ```
199
+
179
200
  What is sent: state transitions, Aβ summary (min/max/median), gain margin, rollback flag, iterations used, savings, library version, optional opaque `workload_id`, threshold config, hour-bucketed timestamp.
180
201
 
181
202
  **What is NEVER sent: prompts, completions, error contents, output buffer, individual Aβ values, or any customer identity beyond the bearer token.** Privacy contract is enforced by the payload-shape unit tests in `tests/test_telemetry.py`.
182
203
 
183
- The Cascade-Systems-hosted endpoint at `telemetry.loopgain.ai` is one acceptable destination; the receiver code is open-source so customers can self-host to keep telemetry fully under their control.
204
+ The hosted endpoint at `telemetry.loopgain.ai` is one acceptable destination. The [receiver](https://github.com/loopgain-ai/telemetry-receiver) and [dashboard](https://github.com/loopgain-ai/dashboard) are both open-source self-host to keep telemetry fully under your control.
184
205
 
185
206
  ---
186
207
 
187
208
  ## Status
188
209
 
189
- **v0.1.0 — initial public release.** Core library shipped. Framework adapters (LangGraph, CrewAI, AutoGen, Vesper) and the cloud-aggregator dashboard come in v0.2+. The math and the API surface are stable.
210
+ **Initial public release.** Core library shipped (current version: see the PyPI badge at the top). Framework adapters (LangGraph, CrewAI, AutoGen) and the cloud-aggregator dashboard come in v0.2+. The math and the API surface are stable.
190
211
 
191
212
  This is alpha software. The API may break before 1.0 if production usage surfaces design issues; pin the version.
192
213
 
@@ -202,6 +223,16 @@ This is alpha software. The API may break before 1.0 if production usage surface
202
223
 
203
224
  LoopGain applies the **Barkhausen stability criterion** (Heinrich Barkhausen, 1921 — the foundational result on when feedback amplifiers oscillate) to AI agent feedback loops. The criterion was originally a way to predict whether an electronic oscillator would sustain oscillation; it turns out to map cleanly onto any feedback loop you can attach an error signal to.
204
225
 
205
- The cleanest summary: a verify-revise loop is a feedback system with measurable error magnitude. The ratio `E(n) / E(n-1)` is its empirical loop gain. The Barkhausen result tells you that loop gain less than 1 converges, equal to 1 oscillates, greater than 1 diverges. LoopGain operationalizes this: classifies the loop's current band, decides what to do, and tells you when you'll converge.
226
+ The cleanest summary: an iterative AI loop with a measurable error signal is a feedback system. The ratio `E(n) / E(n-1)` is its empirical loop gain. The Barkhausen result tells you that loop gain less than 1 converges, equal to 1 oscillates, greater than 1 diverges. LoopGain operationalizes this: classifies the loop's current band, decides what to do, and tells you when you'll converge.
227
+
228
+ Loop types this applies to in practice:
229
+
230
+ - **Verify-revise loops** (GVR pattern) — generator produces, verifier finds issues, reviser fixes. Error = issue count or severity-weighted score.
231
+ - **Refinement loops** — initial output, iterate to improve. Error = distance from target spec / rubric score.
232
+ - **Tool-use retry chains** — agent calls tool, gets back error/success, retries. Error = consecutive failure count or aggregate score.
233
+ - **RAG with self-correction** — retrieve, generate, critique, re-retrieve. Error = critique severity or hallucination score.
234
+ - **Code generation with linter/test feedback** — generate, run tests/linter, fix, repeat. Error = failing test count or linter violation count.
235
+ - **Multi-step reasoning loops** — ReAct-style think/act/observe iterations. Error = whatever the agent's quality assessor returns.
236
+ - **Custom feedback loops** — anything where you can produce a number that should drop toward zero as the loop succeeds.
206
237
 
207
238
  See [loopgain.ai](https://loopgain.ai) for the longer write-up.
@@ -1,12 +1,17 @@
1
1
  # LoopGain
2
2
 
3
- **Barkhausen stability monitor for AI agent verify-revise loops.**
3
+ **Barkhausen stability monitor for AI agent loops.**
4
4
 
5
5
  Replace `max_iterations=5` with a real-time loop-gain (`Aβ`) monitor that knows whether your agent loop is converging, stalling, oscillating, or diverging — and what to do in each case.
6
6
 
7
7
  [![PyPI](https://img.shields.io/pypi/v/loopgain.svg)](https://pypi.org/project/loopgain/)
8
8
  [![Python](https://img.shields.io/pypi/pyversions/loopgain.svg)](https://pypi.org/project/loopgain/)
9
9
  [![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](LICENSE)
10
+ [![Tests](https://img.shields.io/badge/tests-73_passing-brightgreen.svg)](tests/)
11
+
12
+ Works for **any iterative AI workflow with a measurable error signal** — verify-revise loops, refinement passes, tool-use retry chains, RAG with self-correction, code-gen with linter feedback, multi-step reasoning loops. Integrates with **LangGraph**, **CrewAI**, **AutoGen**, **Claude Agent SDK**, and custom stacks. Pure Python, no runtime dependencies.
13
+
14
+ **Keywords:** AI agent loops · agentic AI · infinite loop detection · divergence detection · early stopping · convergence · agent orchestration · LLM stability · generator-verifier-reviser · feedback-loop control.
10
15
 
11
16
  ---
12
17
 
@@ -14,8 +19,6 @@ Replace `max_iterations=5` with a real-time loop-gain (`Aβ`) monitor that knows
14
19
 
15
20
  Production agent loops universally use `max_iterations=N` as their termination policy. It's the embarrassing default of agentic AI: you either waste compute (loop stops too late) or ship bad output (loop stops too early). LoopGain replaces it with a control-theoretic stability monitor based on the **Barkhausen criterion** — a foundational result from electrical-engineering feedback-oscillator analysis (1921).
16
21
 
17
- The math is foundational. The product is the threshold bands, the best-so-far buffer, the ETA prediction, and the clean Python API.
18
-
19
22
  ---
20
23
 
21
24
  ## Install
@@ -30,7 +33,7 @@ Pure Python, no dependencies, supports Python 3.10+.
30
33
 
31
34
  ## Usage
32
35
 
33
- Three lines of code wrap any verify-revise loop:
36
+ Three lines of code wrap any iterative loop with a measurable error signal:
34
37
 
35
38
  ```python
36
39
  from loopgain import LoopGain
@@ -141,24 +144,42 @@ Terminal result with `outcome`, `iterations_used`, `best_index`, `best_output`,
141
144
  **Opt-in.** Send a single anonymized telemetry POST after the loop terminates. Best-effort — never raises, returns `True` on 2xx, `False` otherwise.
142
145
 
143
146
  ```python
147
+ import os
148
+ from loopgain import LoopGain
149
+
150
+ lg = LoopGain(target_error=0.1)
151
+ # ... run the loop ...
144
152
  lg.send_telemetry(
145
- endpoint="https://telemetry.loopgain.ai/v1/aggregate", # or self-hosted
146
- token="your-token", # bearer auth
147
- workload_id="my-rag-pipeline", # opaque label
153
+ endpoint=os.environ["LOOPGAIN_TELEMETRY_ENDPOINT"], # or hardcode
154
+ token=os.environ["LOOPGAIN_TELEMETRY_TOKEN"], # never hardcode
155
+ workload_id="my-rag-pipeline", # opaque label
148
156
  )
149
157
  ```
150
158
 
159
+ Recommended setup: store the token outside source. Two clean options:
160
+
161
+ ```bash
162
+ # Option A: environment variable (simplest)
163
+ export LOOPGAIN_TELEMETRY_ENDPOINT="https://telemetry.loopgain.ai/v1/aggregate"
164
+ export LOOPGAIN_TELEMETRY_TOKEN="lgk_..." # add to ~/.zshrc or ~/.bashrc
165
+
166
+ # Option B: macOS Keychain (more secure)
167
+ pip install keyring
168
+ python3 -c "import keyring; keyring.set_password('loopgain', 'telemetry', input('Token: '))"
169
+ # Then in code: keyring.get_password('loopgain', 'telemetry')
170
+ ```
171
+
151
172
  What is sent: state transitions, Aβ summary (min/max/median), gain margin, rollback flag, iterations used, savings, library version, optional opaque `workload_id`, threshold config, hour-bucketed timestamp.
152
173
 
153
174
  **What is NEVER sent: prompts, completions, error contents, output buffer, individual Aβ values, or any customer identity beyond the bearer token.** Privacy contract is enforced by the payload-shape unit tests in `tests/test_telemetry.py`.
154
175
 
155
- The Cascade-Systems-hosted endpoint at `telemetry.loopgain.ai` is one acceptable destination; the receiver code is open-source so customers can self-host to keep telemetry fully under their control.
176
+ The hosted endpoint at `telemetry.loopgain.ai` is one acceptable destination. The [receiver](https://github.com/loopgain-ai/telemetry-receiver) and [dashboard](https://github.com/loopgain-ai/dashboard) are both open-source self-host to keep telemetry fully under your control.
156
177
 
157
178
  ---
158
179
 
159
180
  ## Status
160
181
 
161
- **v0.1.0 — initial public release.** Core library shipped. Framework adapters (LangGraph, CrewAI, AutoGen, Vesper) and the cloud-aggregator dashboard come in v0.2+. The math and the API surface are stable.
182
+ **Initial public release.** Core library shipped (current version: see the PyPI badge at the top). Framework adapters (LangGraph, CrewAI, AutoGen) and the cloud-aggregator dashboard come in v0.2+. The math and the API surface are stable.
162
183
 
163
184
  This is alpha software. The API may break before 1.0 if production usage surfaces design issues; pin the version.
164
185
 
@@ -174,6 +195,16 @@ This is alpha software. The API may break before 1.0 if production usage surface
174
195
 
175
196
  LoopGain applies the **Barkhausen stability criterion** (Heinrich Barkhausen, 1921 — the foundational result on when feedback amplifiers oscillate) to AI agent feedback loops. The criterion was originally a way to predict whether an electronic oscillator would sustain oscillation; it turns out to map cleanly onto any feedback loop you can attach an error signal to.
176
197
 
177
- The cleanest summary: a verify-revise loop is a feedback system with measurable error magnitude. The ratio `E(n) / E(n-1)` is its empirical loop gain. The Barkhausen result tells you that loop gain less than 1 converges, equal to 1 oscillates, greater than 1 diverges. LoopGain operationalizes this: classifies the loop's current band, decides what to do, and tells you when you'll converge.
198
+ The cleanest summary: an iterative AI loop with a measurable error signal is a feedback system. The ratio `E(n) / E(n-1)` is its empirical loop gain. The Barkhausen result tells you that loop gain less than 1 converges, equal to 1 oscillates, greater than 1 diverges. LoopGain operationalizes this: classifies the loop's current band, decides what to do, and tells you when you'll converge.
199
+
200
+ Loop types this applies to in practice:
201
+
202
+ - **Verify-revise loops** (GVR pattern) — generator produces, verifier finds issues, reviser fixes. Error = issue count or severity-weighted score.
203
+ - **Refinement loops** — initial output, iterate to improve. Error = distance from target spec / rubric score.
204
+ - **Tool-use retry chains** — agent calls tool, gets back error/success, retries. Error = consecutive failure count or aggregate score.
205
+ - **RAG with self-correction** — retrieve, generate, critique, re-retrieve. Error = critique severity or hallucination score.
206
+ - **Code generation with linter/test feedback** — generate, run tests/linter, fix, repeat. Error = failing test count or linter violation count.
207
+ - **Multi-step reasoning loops** — ReAct-style think/act/observe iterations. Error = whatever the agent's quality assessor returns.
208
+ - **Custom feedback loops** — anything where you can produce a number that should drop toward zero as the loop succeeds.
178
209
 
179
210
  See [loopgain.ai](https://loopgain.ai) for the longer write-up.
@@ -24,7 +24,7 @@ from loopgain.core import (
24
24
  )
25
25
  from loopgain.telemetry import build_payload as build_telemetry_payload
26
26
 
27
- __version__ = "0.1.0"
27
+ __version__ = "0.1.2"
28
28
 
29
29
  __all__ = [
30
30
  "LoopGain",
@@ -1,9 +1,12 @@
1
1
  """LoopGain — Barkhausen stability monitor for AI agent loops.
2
2
 
3
3
  The product layer of the Barkhausen stability criterion (1921) applied to
4
- agent verify-revise feedback loops. Replaces the universal max_iterations
5
- hack with a real-time loop-gain monitor that classifies the loop into one
6
- of five named states and decides whether to continue, stop, or roll back.
4
+ any iterative AI loop with a measurable error signal: verify-revise (GVR)
5
+ patterns, refinement passes, tool-use retry chains, RAG with self-correction,
6
+ code-gen with linter feedback, multi-step reasoning loops, and custom
7
+ feedback systems. Replaces the universal max_iterations hack with a
8
+ real-time loop-gain monitor that classifies the loop into one of five
9
+ named states and decides whether to continue, stop, or roll back.
7
10
 
8
11
  The math is foundational EE control theory. The product layer is the
9
12
  threshold bands, the best-so-far buffer, the ETA prediction, and the
@@ -108,12 +111,16 @@ class LoopGainResult:
108
111
 
109
112
 
110
113
  class LoopGain:
111
- """Barkhausen stability monitor for AI agent verify-revise loops.
112
-
113
- Wraps any iterative loop and decides in real time whether to continue,
114
- stop, or roll back. Replaces the universal ``max_iterations=N`` hack
115
- with a control-theoretic stability monitor based on the Barkhausen
116
- criterion.
114
+ """Barkhausen stability monitor for AI agent loops.
115
+
116
+ Wraps any iterative loop with a measurable error signal and decides in
117
+ real time whether to continue, stop, or roll back. Works for
118
+ verify-revise (GVR) loops, refinement passes, tool-use retry chains,
119
+ RAG with self-correction, code-gen with linter feedback, multi-step
120
+ reasoning loops, and any custom iterative process where you can
121
+ produce a number that should drop toward zero. Replaces the universal
122
+ ``max_iterations=N`` hack with a control-theoretic stability monitor
123
+ based on the Barkhausen criterion.
117
124
 
118
125
  Example:
119
126
 
@@ -6,9 +6,9 @@ rollback flag, library version, optional opaque workload label) are sent.
6
6
  Never sends prompts, completions, error contents, or customer identity beyond
7
7
  the bearer token.
8
8
 
9
- The Cascade-Systems-hosted endpoint at ``telemetry.loopgain.ai`` is one
10
- acceptable destination; customers can also self-host the receiver to keep
11
- the data fully under their control.
9
+ The hosted endpoint at ``telemetry.loopgain.ai`` is one acceptable
10
+ destination; the receiver code is open-source so users can also self-host
11
+ to keep the data fully under their control.
12
12
  """
13
13
 
14
14
  from __future__ import annotations
@@ -28,7 +28,7 @@ if TYPE_CHECKING:
28
28
  SCHEMA_VERSION = 1
29
29
 
30
30
  # Library version (kept in sync with __init__.py).
31
- LIBRARY_VERSION = "0.1.0"
31
+ LIBRARY_VERSION = "0.1.2"
32
32
 
33
33
 
34
34
  def build_payload(
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: loopgain
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Barkhausen stability monitor for AI agent loops. Real-time loop-gain (Aβ) monitoring with five named threshold bands, best-so-far rollback, and ETA prediction.
5
5
  Author-email: Dave Fitzsimmons <dave_fitz@icloud.com>
6
6
  License: Apache-2.0
7
7
  Project-URL: Homepage, https://loopgain.ai
8
8
  Project-URL: Repository, https://github.com/loopgain-ai/loopgain
9
9
  Project-URL: Issues, https://github.com/loopgain-ai/loopgain/issues
10
- Keywords: ai,agent,barkhausen,loop-stability,control-theory,feedback-loop,llm,agentic,verify-revise,convergence
10
+ Keywords: ai,agent,ai-agent,ai-agents,agentic,agentic-ai,llm,llm-agent,llm-orchestration,agent-orchestration,agent-loop,verify-revise,verify-revise-loop,gvr,generator-verifier-reviser,convergence,divergence-detection,infinite-loop,infinite-loop-detection,loop-detection,loop-stability,stability-monitor,early-stopping,max-iterations,barkhausen,barkhausen-criterion,control-theory,feedback-loop,feedback-loop-stability,loop-gain,rollback,best-so-far,langgraph,crewai,autogen,claude,anthropic,openai
11
11
  Classifier: Development Status :: 3 - Alpha
12
12
  Classifier: Intended Audience :: Developers
13
13
  Classifier: License :: OSI Approved :: Apache Software License
@@ -28,13 +28,18 @@ Dynamic: license-file
28
28
 
29
29
  # LoopGain
30
30
 
31
- **Barkhausen stability monitor for AI agent verify-revise loops.**
31
+ **Barkhausen stability monitor for AI agent loops.**
32
32
 
33
33
  Replace `max_iterations=5` with a real-time loop-gain (`Aβ`) monitor that knows whether your agent loop is converging, stalling, oscillating, or diverging — and what to do in each case.
34
34
 
35
35
  [![PyPI](https://img.shields.io/pypi/v/loopgain.svg)](https://pypi.org/project/loopgain/)
36
36
  [![Python](https://img.shields.io/pypi/pyversions/loopgain.svg)](https://pypi.org/project/loopgain/)
37
37
  [![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](LICENSE)
38
+ [![Tests](https://img.shields.io/badge/tests-73_passing-brightgreen.svg)](tests/)
39
+
40
+ Works for **any iterative AI workflow with a measurable error signal** — verify-revise loops, refinement passes, tool-use retry chains, RAG with self-correction, code-gen with linter feedback, multi-step reasoning loops. Integrates with **LangGraph**, **CrewAI**, **AutoGen**, **Claude Agent SDK**, and custom stacks. Pure Python, no runtime dependencies.
41
+
42
+ **Keywords:** AI agent loops · agentic AI · infinite loop detection · divergence detection · early stopping · convergence · agent orchestration · LLM stability · generator-verifier-reviser · feedback-loop control.
38
43
 
39
44
  ---
40
45
 
@@ -42,8 +47,6 @@ Replace `max_iterations=5` with a real-time loop-gain (`Aβ`) monitor that knows
42
47
 
43
48
  Production agent loops universally use `max_iterations=N` as their termination policy. It's the embarrassing default of agentic AI: you either waste compute (loop stops too late) or ship bad output (loop stops too early). LoopGain replaces it with a control-theoretic stability monitor based on the **Barkhausen criterion** — a foundational result from electrical-engineering feedback-oscillator analysis (1921).
44
49
 
45
- The math is foundational. The product is the threshold bands, the best-so-far buffer, the ETA prediction, and the clean Python API.
46
-
47
50
  ---
48
51
 
49
52
  ## Install
@@ -58,7 +61,7 @@ Pure Python, no dependencies, supports Python 3.10+.
58
61
 
59
62
  ## Usage
60
63
 
61
- Three lines of code wrap any verify-revise loop:
64
+ Three lines of code wrap any iterative loop with a measurable error signal:
62
65
 
63
66
  ```python
64
67
  from loopgain import LoopGain
@@ -169,24 +172,42 @@ Terminal result with `outcome`, `iterations_used`, `best_index`, `best_output`,
169
172
  **Opt-in.** Send a single anonymized telemetry POST after the loop terminates. Best-effort — never raises, returns `True` on 2xx, `False` otherwise.
170
173
 
171
174
  ```python
175
+ import os
176
+ from loopgain import LoopGain
177
+
178
+ lg = LoopGain(target_error=0.1)
179
+ # ... run the loop ...
172
180
  lg.send_telemetry(
173
- endpoint="https://telemetry.loopgain.ai/v1/aggregate", # or self-hosted
174
- token="your-token", # bearer auth
175
- workload_id="my-rag-pipeline", # opaque label
181
+ endpoint=os.environ["LOOPGAIN_TELEMETRY_ENDPOINT"], # or hardcode
182
+ token=os.environ["LOOPGAIN_TELEMETRY_TOKEN"], # never hardcode
183
+ workload_id="my-rag-pipeline", # opaque label
176
184
  )
177
185
  ```
178
186
 
187
+ Recommended setup: store the token outside source. Two clean options:
188
+
189
+ ```bash
190
+ # Option A: environment variable (simplest)
191
+ export LOOPGAIN_TELEMETRY_ENDPOINT="https://telemetry.loopgain.ai/v1/aggregate"
192
+ export LOOPGAIN_TELEMETRY_TOKEN="lgk_..." # add to ~/.zshrc or ~/.bashrc
193
+
194
+ # Option B: macOS Keychain (more secure)
195
+ pip install keyring
196
+ python3 -c "import keyring; keyring.set_password('loopgain', 'telemetry', input('Token: '))"
197
+ # Then in code: keyring.get_password('loopgain', 'telemetry')
198
+ ```
199
+
179
200
  What is sent: state transitions, Aβ summary (min/max/median), gain margin, rollback flag, iterations used, savings, library version, optional opaque `workload_id`, threshold config, hour-bucketed timestamp.
180
201
 
181
202
  **What is NEVER sent: prompts, completions, error contents, output buffer, individual Aβ values, or any customer identity beyond the bearer token.** Privacy contract is enforced by the payload-shape unit tests in `tests/test_telemetry.py`.
182
203
 
183
- The Cascade-Systems-hosted endpoint at `telemetry.loopgain.ai` is one acceptable destination; the receiver code is open-source so customers can self-host to keep telemetry fully under their control.
204
+ The hosted endpoint at `telemetry.loopgain.ai` is one acceptable destination. The [receiver](https://github.com/loopgain-ai/telemetry-receiver) and [dashboard](https://github.com/loopgain-ai/dashboard) are both open-source self-host to keep telemetry fully under your control.
184
205
 
185
206
  ---
186
207
 
187
208
  ## Status
188
209
 
189
- **v0.1.0 — initial public release.** Core library shipped. Framework adapters (LangGraph, CrewAI, AutoGen, Vesper) and the cloud-aggregator dashboard come in v0.2+. The math and the API surface are stable.
210
+ **Initial public release.** Core library shipped (current version: see the PyPI badge at the top). Framework adapters (LangGraph, CrewAI, AutoGen) and the cloud-aggregator dashboard come in v0.2+. The math and the API surface are stable.
190
211
 
191
212
  This is alpha software. The API may break before 1.0 if production usage surfaces design issues; pin the version.
192
213
 
@@ -202,6 +223,16 @@ This is alpha software. The API may break before 1.0 if production usage surface
202
223
 
203
224
  LoopGain applies the **Barkhausen stability criterion** (Heinrich Barkhausen, 1921 — the foundational result on when feedback amplifiers oscillate) to AI agent feedback loops. The criterion was originally a way to predict whether an electronic oscillator would sustain oscillation; it turns out to map cleanly onto any feedback loop you can attach an error signal to.
204
225
 
205
- The cleanest summary: a verify-revise loop is a feedback system with measurable error magnitude. The ratio `E(n) / E(n-1)` is its empirical loop gain. The Barkhausen result tells you that loop gain less than 1 converges, equal to 1 oscillates, greater than 1 diverges. LoopGain operationalizes this: classifies the loop's current band, decides what to do, and tells you when you'll converge.
226
+ The cleanest summary: an iterative AI loop with a measurable error signal is a feedback system. The ratio `E(n) / E(n-1)` is its empirical loop gain. The Barkhausen result tells you that loop gain less than 1 converges, equal to 1 oscillates, greater than 1 diverges. LoopGain operationalizes this: classifies the loop's current band, decides what to do, and tells you when you'll converge.
227
+
228
+ Loop types this applies to in practice:
229
+
230
+ - **Verify-revise loops** (GVR pattern) — generator produces, verifier finds issues, reviser fixes. Error = issue count or severity-weighted score.
231
+ - **Refinement loops** — initial output, iterate to improve. Error = distance from target spec / rubric score.
232
+ - **Tool-use retry chains** — agent calls tool, gets back error/success, retries. Error = consecutive failure count or aggregate score.
233
+ - **RAG with self-correction** — retrieve, generate, critique, re-retrieve. Error = critique severity or hallucination score.
234
+ - **Code generation with linter/test feedback** — generate, run tests/linter, fix, repeat. Error = failing test count or linter violation count.
235
+ - **Multi-step reasoning loops** — ReAct-style think/act/observe iterations. Error = whatever the agent's quality assessor returns.
236
+ - **Custom feedback loops** — anything where you can produce a number that should drop toward zero as the loop succeeds.
206
237
 
207
238
  See [loopgain.ai](https://loopgain.ai) for the longer write-up.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "loopgain"
7
- version = "0.1.0"
7
+ version = "0.1.2"
8
8
  description = "Barkhausen stability monitor for AI agent loops. Real-time loop-gain (Aβ) monitoring with five named threshold bands, best-so-far rollback, and ETA prediction."
9
9
  authors = [{name = "Dave Fitzsimmons", email = "dave_fitz@icloud.com"}]
10
10
  readme = "README.md"
@@ -13,14 +13,42 @@ requires-python = ">=3.10"
13
13
  keywords = [
14
14
  "ai",
15
15
  "agent",
16
- "barkhausen",
17
- "loop-stability",
18
- "control-theory",
19
- "feedback-loop",
20
- "llm",
16
+ "ai-agent",
17
+ "ai-agents",
21
18
  "agentic",
19
+ "agentic-ai",
20
+ "llm",
21
+ "llm-agent",
22
+ "llm-orchestration",
23
+ "agent-orchestration",
24
+ "agent-loop",
22
25
  "verify-revise",
26
+ "verify-revise-loop",
27
+ "gvr",
28
+ "generator-verifier-reviser",
23
29
  "convergence",
30
+ "divergence-detection",
31
+ "infinite-loop",
32
+ "infinite-loop-detection",
33
+ "loop-detection",
34
+ "loop-stability",
35
+ "stability-monitor",
36
+ "early-stopping",
37
+ "max-iterations",
38
+ "barkhausen",
39
+ "barkhausen-criterion",
40
+ "control-theory",
41
+ "feedback-loop",
42
+ "feedback-loop-stability",
43
+ "loop-gain",
44
+ "rollback",
45
+ "best-so-far",
46
+ "langgraph",
47
+ "crewai",
48
+ "autogen",
49
+ "claude",
50
+ "anthropic",
51
+ "openai",
24
52
  ]
25
53
  classifiers = [
26
54
  "Development Status :: 3 - Alpha",
File without changes
File without changes
File without changes
File without changes