entroplain 0.1.1 → 0.2.1

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.
Binary file
Binary file
@@ -1,178 +1,178 @@
1
- # Entroplain Usage Guide for Agents
2
-
3
- ## Quick Setup
4
-
5
- ### For OpenClaw/Claude Code (Proxy Method)
6
-
7
- Run the entropy proxy and point your agent to it:
8
-
9
- ```bash
10
- # Start the proxy (monitors entropy, enables early exit)
11
- python -m entroplain.proxy --port 8765 --log-entropy
12
-
13
- # Set environment to use proxy
14
- export OPENAI_BASE_URL=http://localhost:8765/v1
15
- # or for NVIDIA:
16
- export NVIDIA_BASE_URL=http://localhost:8765/v1
17
- ```
18
-
19
- Now OpenClaw/Claude Code will automatically have entropy monitoring!
20
-
21
- ### How the Proxy Works
22
-
23
- ```
24
- Agent -> Proxy (localhost:8765) -> Real API
25
- |
26
- v
27
- Entropy Monitor
28
- |
29
- v
30
- Early Exit Check
31
- ```
32
-
33
- The proxy:
34
- 1. Intercepts all chat completion requests
35
- 2. Enables logprobs automatically
36
- 3. Calculates entropy for each token
37
- 4. Terminates stream when reasoning converges
38
- 5. Passes everything through unchanged to the agent
39
-
40
- ---
41
-
42
- ## Direct Usage (Python)
43
-
44
- ```python
45
- from entroplain import EntropyMonitor, NVIDIAProvider
46
-
47
- monitor = EntropyMonitor()
48
- provider = NVIDIAProvider()
49
-
50
- for token in provider.stream_with_entropy(
51
- model="meta/llama-3.1-70b-instruct",
52
- messages=[{"role": "user", "content": "Solve: x^2 = 16"}]
53
- ):
54
- monitor.track(token.token, token.entropy)
55
- print(token.token, end="")
56
-
57
- if monitor.should_exit():
58
- print("\n[Early exit - reasoning converged]")
59
- break
60
-
61
- print(f"\nStats: {monitor.get_stats()}")
62
- ```
63
-
64
- ---
65
-
66
- ## Supported Providers
67
-
68
- | Provider | Works? | How |
69
- |----------|--------|-----|
70
- | OpenAI | YES | `logprobs: true` |
71
- | NVIDIA NIM | YES | OpenAI-compatible |
72
- | Anthropic Claude 4 | YES | `logprobs: True` |
73
- | Google Gemini | YES | `response_logprobs=True` |
74
- | Ollama (local) | YES | Built-in logit access |
75
- | llama.cpp | YES | Built-in logit access |
76
-
77
- ---
78
-
79
- ## Configuration
80
-
81
- ### Exit Conditions
82
-
83
- ```python
84
- monitor = EntropyMonitor(
85
- entropy_threshold=0.15, # Exit when entropy drops below this
86
- min_valleys=2, # Require N reasoning milestones
87
- min_tokens=50, # Don't exit before this many tokens
88
- velocity_threshold=0.05, # Exit when change rate stabilizes
89
- exit_condition="combined" # or: "valleys_plateau", "entropy_drop", "velocity_zero"
90
- )
91
- ```
92
-
93
- ### Environment Variables
94
-
95
- ```bash
96
- # API keys (used by providers)
97
- export OPENAI_API_KEY=sk-...
98
- export ANTHROPIC_API_KEY=sk-ant-...
99
- export NVIDIA_API_KEY=nvapi-...
100
- export GOOGLE_API_KEY=...
101
-
102
- # For proxy
103
- export ENTROPPLAIN_PORT=8765
104
- export ENTROPPLAIN_LOG_ENTROPY=true
105
- ```
106
-
107
- ---
108
-
109
- ## CLI
110
-
111
- ```bash
112
- # Analyze a prompt
113
- entroplain analyze "What is 2+2?" --model gpt-4o
114
-
115
- # Stream with early exit
116
- entroplain stream "Explain quantum computing" --exit-on-converge
117
-
118
- # Run proxy
119
- entroplain proxy --port 8765 --log-entropy
120
- ```
121
-
122
- ---
123
-
124
- ## Agent Integration Examples
125
-
126
- ### OpenClaw with Proxy
127
-
128
- ```yaml
129
- # In config.yaml
130
- llm:
131
- provider: openai-compatible
132
- base_url: http://localhost:8765/v1 # Point to proxy
133
- primary_model: meta/llama-3.1-70b-instruct
134
- ```
135
-
136
- ### Claude Code with Proxy
137
-
138
- Set environment before running:
139
- ```bash
140
- export ANTHROPIC_BASE_URL=http://localhost:8765/v1
141
- claude
142
- ```
143
-
144
- ### Custom Agent
145
-
146
- ```python
147
- from entroplain.hooks import EntropyHook
148
-
149
- hook = EntropyHook(config={"entropy_threshold": 0.15})
150
-
151
- for token in your_agent.generate_stream():
152
- result = hook.on_token(token.text, token.entropy)
153
-
154
- if result["should_exit"]:
155
- print(f"Early exit at token {result['index']}")
156
- break
157
- ```
158
-
159
- ---
160
-
161
- ## Troubleshooting
162
-
163
- ### "No logprobs returned"
164
- Some models don't support logprobs. Try a different model or check provider docs.
165
-
166
- ### "Entropy is always 0"
167
- Make sure `logprobs: true` and `top_logprobs: 5` are set in your API request.
168
-
169
- ### "Proxy won't start"
170
- Install dependencies: `pip install entroplain[all] fastapi uvicorn httpx`
171
-
172
- ---
173
-
174
- ## Learn More
175
-
176
- - GitHub: https://github.com/entroplain/entroplain
177
- - PyPI: https://pypi.org/project/entroplain/
178
- - npm: https://www.npmjs.com/package/entroplain
1
+ # Entroplain Usage Guide for Agents
2
+
3
+ ## Quick Setup
4
+
5
+ ### For OpenClaw/Claude Code (Proxy Method)
6
+
7
+ Run the entropy proxy and point your agent to it:
8
+
9
+ ```bash
10
+ # Start the proxy (monitors entropy, enables early exit)
11
+ python -m entroplain.proxy --port 8765 --log-entropy
12
+
13
+ # Set environment to use proxy
14
+ export OPENAI_BASE_URL=http://localhost:8765/v1
15
+ # or for NVIDIA:
16
+ export NVIDIA_BASE_URL=http://localhost:8765/v1
17
+ ```
18
+
19
+ Now OpenClaw/Claude Code will automatically have entropy monitoring!
20
+
21
+ ### How the Proxy Works
22
+
23
+ ```
24
+ Agent -> Proxy (localhost:8765) -> Real API
25
+ |
26
+ v
27
+ Entropy Monitor
28
+ |
29
+ v
30
+ Early Exit Check
31
+ ```
32
+
33
+ The proxy:
34
+ 1. Intercepts all chat completion requests
35
+ 2. Enables logprobs automatically
36
+ 3. Calculates entropy for each token
37
+ 4. Terminates stream when reasoning converges
38
+ 5. Passes everything through unchanged to the agent
39
+
40
+ ---
41
+
42
+ ## Direct Usage (Python)
43
+
44
+ ```python
45
+ from entroplain import EntropyMonitor, NVIDIAProvider
46
+
47
+ monitor = EntropyMonitor()
48
+ provider = NVIDIAProvider()
49
+
50
+ for token in provider.stream_with_entropy(
51
+ model="meta/llama-3.1-70b-instruct",
52
+ messages=[{"role": "user", "content": "Solve: x^2 = 16"}]
53
+ ):
54
+ monitor.track(token.token, token.entropy)
55
+ print(token.token, end="")
56
+
57
+ if monitor.should_exit():
58
+ print("\n[Early exit - reasoning converged]")
59
+ break
60
+
61
+ print(f"\nStats: {monitor.get_stats()}")
62
+ ```
63
+
64
+ ---
65
+
66
+ ## Supported Providers
67
+
68
+ | Provider | Works? | How |
69
+ |----------|--------|-----|
70
+ | OpenAI | YES | `logprobs: true` |
71
+ | NVIDIA NIM | YES | OpenAI-compatible |
72
+ | Anthropic Claude 4 | YES | `logprobs: True` |
73
+ | Google Gemini | YES | `response_logprobs=True` |
74
+ | Ollama (local) | YES | Built-in logit access |
75
+ | llama.cpp | YES | Built-in logit access |
76
+
77
+ ---
78
+
79
+ ## Configuration
80
+
81
+ ### Exit Conditions
82
+
83
+ ```python
84
+ monitor = EntropyMonitor(
85
+ entropy_threshold=0.15, # Exit when entropy drops below this
86
+ min_valleys=2, # Require N reasoning milestones
87
+ min_tokens=50, # Don't exit before this many tokens
88
+ velocity_threshold=0.05, # Exit when change rate stabilizes
89
+ exit_condition="combined" # or: "valleys_plateau", "entropy_drop", "velocity_zero"
90
+ )
91
+ ```
92
+
93
+ ### Environment Variables
94
+
95
+ ```bash
96
+ # API keys (used by providers)
97
+ export OPENAI_API_KEY=sk-...
98
+ export ANTHROPIC_API_KEY=sk-ant-...
99
+ export NVIDIA_API_KEY=nvapi-...
100
+ export GOOGLE_API_KEY=...
101
+
102
+ # For proxy
103
+ export ENTROPPLAIN_PORT=8765
104
+ export ENTROPPLAIN_LOG_ENTROPY=true
105
+ ```
106
+
107
+ ---
108
+
109
+ ## CLI
110
+
111
+ ```bash
112
+ # Analyze a prompt
113
+ entroplain analyze "What is 2+2?" --model gpt-4o
114
+
115
+ # Stream with early exit
116
+ entroplain stream "Explain quantum computing" --exit-on-converge
117
+
118
+ # Run proxy
119
+ entroplain proxy --port 8765 --log-entropy
120
+ ```
121
+
122
+ ---
123
+
124
+ ## Agent Integration Examples
125
+
126
+ ### OpenClaw with Proxy
127
+
128
+ ```yaml
129
+ # In config.yaml
130
+ llm:
131
+ provider: openai-compatible
132
+ base_url: http://localhost:8765/v1 # Point to proxy
133
+ primary_model: meta/llama-3.1-70b-instruct
134
+ ```
135
+
136
+ ### Claude Code with Proxy
137
+
138
+ Set environment before running:
139
+ ```bash
140
+ export ANTHROPIC_BASE_URL=http://localhost:8765/v1
141
+ claude
142
+ ```
143
+
144
+ ### Custom Agent
145
+
146
+ ```python
147
+ from entroplain.hooks import EntropyHook
148
+
149
+ hook = EntropyHook(config={"entropy_threshold": 0.15})
150
+
151
+ for token in your_agent.generate_stream():
152
+ result = hook.on_token(token.text, token.entropy)
153
+
154
+ if result["should_exit"]:
155
+ print(f"Early exit at token {result['index']}")
156
+ break
157
+ ```
158
+
159
+ ---
160
+
161
+ ## Troubleshooting
162
+
163
+ ### "No logprobs returned"
164
+ Some models don't support logprobs. Try a different model or check provider docs.
165
+
166
+ ### "Entropy is always 0"
167
+ Make sure `logprobs: true` and `top_logprobs: 5` are set in your API request.
168
+
169
+ ### "Proxy won't start"
170
+ Install dependencies: `pip install entroplain[all] fastapi uvicorn httpx`
171
+
172
+ ---
173
+
174
+ ## Learn More
175
+
176
+ - GitHub: https://github.com/entroplain/entroplain
177
+ - PyPI: https://pypi.org/project/entroplain/
178
+ - npm: https://www.npmjs.com/package/entroplain