agentgit 0.1.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.
- agentgit-0.1.0/LICENSE +21 -0
- agentgit-0.1.0/PKG-INFO +309 -0
- agentgit-0.1.0/README.md +280 -0
- agentgit-0.1.0/agentgit/__init__.py +50 -0
- agentgit-0.1.0/agentgit/cli.py +317 -0
- agentgit-0.1.0/agentgit/decorators.py +204 -0
- agentgit-0.1.0/agentgit/engine.py +853 -0
- agentgit-0.1.0/agentgit/serializers.py +147 -0
- agentgit-0.1.0/agentgit/storage.py +327 -0
- agentgit-0.1.0/agentgit/strategies.py +242 -0
- agentgit-0.1.0/agentgit.egg-info/PKG-INFO +309 -0
- agentgit-0.1.0/agentgit.egg-info/SOURCES.txt +16 -0
- agentgit-0.1.0/agentgit.egg-info/dependency_links.txt +1 -0
- agentgit-0.1.0/agentgit.egg-info/entry_points.txt +2 -0
- agentgit-0.1.0/agentgit.egg-info/requires.txt +4 -0
- agentgit-0.1.0/agentgit.egg-info/top_level.txt +1 -0
- agentgit-0.1.0/pyproject.toml +52 -0
- agentgit-0.1.0/setup.cfg +4 -0
agentgit-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 AgentGit Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
agentgit-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentgit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Git for AI Thoughts β Checkpointing & Recovery Protocol for AI Agents
|
|
5
|
+
Author: AgentGit Contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/agentgit/agentgit
|
|
8
|
+
Project-URL: Documentation, https://agentgit.readthedocs.io
|
|
9
|
+
Project-URL: Repository, https://github.com/agentgit/agentgit
|
|
10
|
+
Project-URL: Issues, https://github.com/agentgit/agentgit/issues
|
|
11
|
+
Keywords: ai,agents,checkpointing,recovery,state-management,llm,reasoning,rollback,branching
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# π§ AgentGit β Git for AI Thoughts
|
|
31
|
+
|
|
32
|
+
**An open-source Checkpointing & Recovery Protocol for AI Agents**
|
|
33
|
+
|
|
34
|
+
> Save, branch, rollback, and recover an agent's "state of mind" at every reasoning step. If the model hits a bug or a timeout, it rolls back to the last logical state and tries a different path β without starting over.
|
|
35
|
+
|
|
36
|
+
[](https://www.python.org/downloads/)
|
|
37
|
+
[](LICENSE)
|
|
38
|
+
[]()
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## The Problem
|
|
43
|
+
|
|
44
|
+
AI agents are **fragile**. When a multi-step reasoning chain fails at step 7, most frameworks throw everything away and start from scratch. That's like closing your entire Word document because you made a typo on page 3.
|
|
45
|
+
|
|
46
|
+
## The Solution
|
|
47
|
+
|
|
48
|
+
AgentGit gives your agent a **version-controlled brain**:
|
|
49
|
+
|
|
50
|
+
| Git Concept | AgentGit Equivalent | What It Means |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| `git commit` | `agent.checkpoint()` | Save the agent's current "thought" |
|
|
53
|
+
| `git reset` | `agent.rollback()` | Undo bad reasoning, go back to a good state |
|
|
54
|
+
| `git branch` | `agent.branch()` | Explore alternative solutions in parallel |
|
|
55
|
+
| `git merge` | `agent.merge()` | Combine the best ideas from different paths |
|
|
56
|
+
| `git log` | `agent.history()` | View the full reasoning timeline |
|
|
57
|
+
| `git diff` | `agent.diff()` | See what changed between two thought-states |
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Quick Start
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install agentgit
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from agentgit import AgentGit
|
|
69
|
+
|
|
70
|
+
# Initialize β like 'git init' for your agent's brain
|
|
71
|
+
agent = AgentGit("my-research-agent")
|
|
72
|
+
|
|
73
|
+
# Step 1: Save the agent's initial understanding
|
|
74
|
+
agent.checkpoint(
|
|
75
|
+
state={"task": "Find best restaurants in NYC", "status": "parsing"},
|
|
76
|
+
metadata={"confidence": 0.9},
|
|
77
|
+
description="Parsed user request",
|
|
78
|
+
logic_step="parse_input"
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
# Step 2: Agent does some work...
|
|
82
|
+
agent.checkpoint(
|
|
83
|
+
state={"task": "Find best restaurants in NYC", "results": ["Le Bernardin", "Eleven Madison Park"]},
|
|
84
|
+
metadata={"confidence": 0.85},
|
|
85
|
+
description="Found top restaurants",
|
|
86
|
+
logic_step="search_restaurants"
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# Step 3: Oh no, the API timed out on the next step!
|
|
90
|
+
# No problem β just roll back.
|
|
91
|
+
agent.rollback() # Goes back to "Found top restaurants"
|
|
92
|
+
|
|
93
|
+
# Or try a completely different approach
|
|
94
|
+
agent.branch("alternative-search")
|
|
95
|
+
agent.checkpoint(
|
|
96
|
+
state={"task": "Find best restaurants in NYC", "approach": "Use cached reviews"},
|
|
97
|
+
logic_step="cached_search"
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Core Features
|
|
104
|
+
|
|
105
|
+
### 1. Checkpointing β Save Points for the Brain
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
cp = agent.checkpoint(
|
|
109
|
+
state={"reasoning": "The user wants X because of Y..."},
|
|
110
|
+
metadata={"confidence": 0.87, "tokens_used": 150},
|
|
111
|
+
description="Identified user intent",
|
|
112
|
+
logic_step="intent_classification"
|
|
113
|
+
)
|
|
114
|
+
# Every checkpoint gets a unique ID and content hash
|
|
115
|
+
print(f"Saved: {cp.id} (hash: {cp.hash})")
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 2. Rollback β Ctrl+Z for Thinking
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
# Go back one step
|
|
122
|
+
agent.rollback()
|
|
123
|
+
|
|
124
|
+
# Go back 3 steps
|
|
125
|
+
agent.rollback(steps=3)
|
|
126
|
+
|
|
127
|
+
# Jump to a specific checkpoint
|
|
128
|
+
agent.rollback(to_checkpoint_id="abc123")
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 3. Branching β Explore Multiple Approaches
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
# Main path: conservative approach
|
|
135
|
+
agent.checkpoint(state={"approach": "step-by-step"})
|
|
136
|
+
|
|
137
|
+
# Branch off to try something creative
|
|
138
|
+
agent.branch("creative")
|
|
139
|
+
agent.checkpoint(state={"approach": "lateral-thinking"})
|
|
140
|
+
|
|
141
|
+
# Go back to main if creative doesn't work
|
|
142
|
+
agent.switch_branch("main")
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 4. Safe Execution β Automatic Error Recovery
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
def risky_api_call(state):
|
|
149
|
+
# This might fail due to rate limits, timeouts, etc.
|
|
150
|
+
return call_external_api(state["query"])
|
|
151
|
+
|
|
152
|
+
result, checkpoint = agent.safe_execute(
|
|
153
|
+
func=risky_api_call,
|
|
154
|
+
state={"query": "latest news"},
|
|
155
|
+
description="Fetch news articles",
|
|
156
|
+
max_retries=3,
|
|
157
|
+
fallback=use_cached_data # Plan B if all retries fail
|
|
158
|
+
)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### 5. Logic Tree β Full Decision Audit Trail
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
print(agent.visualize_tree())
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Output:
|
|
168
|
+
```
|
|
169
|
+
βββ β
Task received [de3eec5f]
|
|
170
|
+
βββ β
Plan created [3a7996fa]
|
|
171
|
+
βββ β API call failed [372aabc7]
|
|
172
|
+
βββ β
Used cache instead [a4d4e95e]
|
|
173
|
+
βββ β
Retry succeeded [330a3284]
|
|
174
|
+
βββ β
Summary generated [67f8369a]
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### 6. Decorators β Zero-Code-Change Integration
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
from agentgit.decorators import agentgit_step
|
|
181
|
+
|
|
182
|
+
@agentgit_step("analyze_data")
|
|
183
|
+
def analyze(state):
|
|
184
|
+
# Your existing code β unchanged!
|
|
185
|
+
return {"analysis": process(state["data"])}
|
|
186
|
+
|
|
187
|
+
# Automatically checkpointed, with rollback on failure
|
|
188
|
+
result = analyze({"data": raw_data})
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Recovery Strategies
|
|
194
|
+
|
|
195
|
+
| Strategy | When to Use | What It Does |
|
|
196
|
+
|---|---|---|
|
|
197
|
+
| `RetryWithBackoff` | API timeouts, rate limits | Waits longer between each retry |
|
|
198
|
+
| `AlternativePathStrategy` | Logic dead-ends | Switches to a different approach |
|
|
199
|
+
| `DegradeGracefully` | Resource limits | Produces simpler output |
|
|
200
|
+
| `CompositeStrategy` | Complex scenarios | Chains multiple strategies |
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
from agentgit import AgentGit
|
|
204
|
+
from agentgit.strategies import RetryWithBackoff, DegradeGracefully, CompositeStrategy
|
|
205
|
+
|
|
206
|
+
agent = AgentGit(
|
|
207
|
+
"resilient-agent",
|
|
208
|
+
recovery_strategies=[
|
|
209
|
+
CompositeStrategy([
|
|
210
|
+
RetryWithBackoff(base_delay=1.0, max_delay=30.0),
|
|
211
|
+
DegradeGracefully(),
|
|
212
|
+
])
|
|
213
|
+
]
|
|
214
|
+
)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Storage Backends
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
from agentgit.storage import FileSystemStorage, SQLiteStorage
|
|
223
|
+
|
|
224
|
+
# File-based (great for debugging β you can read the JSON files)
|
|
225
|
+
agent = AgentGit("my-agent", storage_backend=FileSystemStorage(".agentgit"))
|
|
226
|
+
|
|
227
|
+
# SQLite (fast queries, good for production)
|
|
228
|
+
agent = AgentGit("my-agent", storage_backend=SQLiteStorage("agent.db"))
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## CLI
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
# Run the interactive demo
|
|
237
|
+
agentgit demo
|
|
238
|
+
|
|
239
|
+
# View checkpoint history
|
|
240
|
+
agentgit log
|
|
241
|
+
|
|
242
|
+
# Visualize the reasoning tree
|
|
243
|
+
agentgit tree
|
|
244
|
+
|
|
245
|
+
# List branches
|
|
246
|
+
agentgit branches
|
|
247
|
+
|
|
248
|
+
# Compare two checkpoints
|
|
249
|
+
agentgit diff abc123 def456
|
|
250
|
+
|
|
251
|
+
# View metrics
|
|
252
|
+
agentgit metrics
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Framework Integration
|
|
258
|
+
|
|
259
|
+
### LangChain
|
|
260
|
+
```python
|
|
261
|
+
from agentgit.decorators import AgentGitMiddleware
|
|
262
|
+
|
|
263
|
+
middleware = AgentGitMiddleware("langchain-agent")
|
|
264
|
+
wrapped_chain = middleware.wrap(my_chain.invoke, "process_query")
|
|
265
|
+
result = wrapped_chain({"input": "Hello"})
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Any Python Agent
|
|
269
|
+
```python
|
|
270
|
+
from agentgit.decorators import checkpoint_context
|
|
271
|
+
|
|
272
|
+
with checkpoint_context(description="Data processing") as ctx:
|
|
273
|
+
result = process_data(data)
|
|
274
|
+
ctx.state = {"result": result}
|
|
275
|
+
# Auto-rolls back on exception
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Architecture
|
|
281
|
+
|
|
282
|
+
```
|
|
283
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
284
|
+
β Your AI Agent β
|
|
285
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
286
|
+
β Decorators & Middleware (agentgit.decorators) β
|
|
287
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
288
|
+
β AgentGit Core Engine (agentgit.engine) β
|
|
289
|
+
β βββββββββββ ββββββββββ ββββββββββ ββββββββββββ β
|
|
290
|
+
β βCheckpointβ β Branch β βRollbackβ βLogic Treeβ β
|
|
291
|
+
β βββββββββββ ββββββββββ ββββββββββ ββββββββββββ β
|
|
292
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
293
|
+
β Recovery Strategies (agentgit.strategies) β
|
|
294
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
295
|
+
β Serializers (agentgit.serializers) β
|
|
296
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
297
|
+
β Storage Backends: FileSystem β SQLite β Memory β
|
|
298
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## Contributing
|
|
304
|
+
|
|
305
|
+
Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
306
|
+
|
|
307
|
+
## License
|
|
308
|
+
|
|
309
|
+
MIT License β see [LICENSE](LICENSE) for details.
|
agentgit-0.1.0/README.md
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# π§ AgentGit β Git for AI Thoughts
|
|
2
|
+
|
|
3
|
+
**An open-source Checkpointing & Recovery Protocol for AI Agents**
|
|
4
|
+
|
|
5
|
+
> Save, branch, rollback, and recover an agent's "state of mind" at every reasoning step. If the model hits a bug or a timeout, it rolls back to the last logical state and tries a different path β without starting over.
|
|
6
|
+
|
|
7
|
+
[](https://www.python.org/downloads/)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[]()
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## The Problem
|
|
14
|
+
|
|
15
|
+
AI agents are **fragile**. When a multi-step reasoning chain fails at step 7, most frameworks throw everything away and start from scratch. That's like closing your entire Word document because you made a typo on page 3.
|
|
16
|
+
|
|
17
|
+
## The Solution
|
|
18
|
+
|
|
19
|
+
AgentGit gives your agent a **version-controlled brain**:
|
|
20
|
+
|
|
21
|
+
| Git Concept | AgentGit Equivalent | What It Means |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| `git commit` | `agent.checkpoint()` | Save the agent's current "thought" |
|
|
24
|
+
| `git reset` | `agent.rollback()` | Undo bad reasoning, go back to a good state |
|
|
25
|
+
| `git branch` | `agent.branch()` | Explore alternative solutions in parallel |
|
|
26
|
+
| `git merge` | `agent.merge()` | Combine the best ideas from different paths |
|
|
27
|
+
| `git log` | `agent.history()` | View the full reasoning timeline |
|
|
28
|
+
| `git diff` | `agent.diff()` | See what changed between two thought-states |
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install agentgit
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from agentgit import AgentGit
|
|
40
|
+
|
|
41
|
+
# Initialize β like 'git init' for your agent's brain
|
|
42
|
+
agent = AgentGit("my-research-agent")
|
|
43
|
+
|
|
44
|
+
# Step 1: Save the agent's initial understanding
|
|
45
|
+
agent.checkpoint(
|
|
46
|
+
state={"task": "Find best restaurants in NYC", "status": "parsing"},
|
|
47
|
+
metadata={"confidence": 0.9},
|
|
48
|
+
description="Parsed user request",
|
|
49
|
+
logic_step="parse_input"
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# Step 2: Agent does some work...
|
|
53
|
+
agent.checkpoint(
|
|
54
|
+
state={"task": "Find best restaurants in NYC", "results": ["Le Bernardin", "Eleven Madison Park"]},
|
|
55
|
+
metadata={"confidence": 0.85},
|
|
56
|
+
description="Found top restaurants",
|
|
57
|
+
logic_step="search_restaurants"
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# Step 3: Oh no, the API timed out on the next step!
|
|
61
|
+
# No problem β just roll back.
|
|
62
|
+
agent.rollback() # Goes back to "Found top restaurants"
|
|
63
|
+
|
|
64
|
+
# Or try a completely different approach
|
|
65
|
+
agent.branch("alternative-search")
|
|
66
|
+
agent.checkpoint(
|
|
67
|
+
state={"task": "Find best restaurants in NYC", "approach": "Use cached reviews"},
|
|
68
|
+
logic_step="cached_search"
|
|
69
|
+
)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Core Features
|
|
75
|
+
|
|
76
|
+
### 1. Checkpointing β Save Points for the Brain
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
cp = agent.checkpoint(
|
|
80
|
+
state={"reasoning": "The user wants X because of Y..."},
|
|
81
|
+
metadata={"confidence": 0.87, "tokens_used": 150},
|
|
82
|
+
description="Identified user intent",
|
|
83
|
+
logic_step="intent_classification"
|
|
84
|
+
)
|
|
85
|
+
# Every checkpoint gets a unique ID and content hash
|
|
86
|
+
print(f"Saved: {cp.id} (hash: {cp.hash})")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 2. Rollback β Ctrl+Z for Thinking
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
# Go back one step
|
|
93
|
+
agent.rollback()
|
|
94
|
+
|
|
95
|
+
# Go back 3 steps
|
|
96
|
+
agent.rollback(steps=3)
|
|
97
|
+
|
|
98
|
+
# Jump to a specific checkpoint
|
|
99
|
+
agent.rollback(to_checkpoint_id="abc123")
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 3. Branching β Explore Multiple Approaches
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
# Main path: conservative approach
|
|
106
|
+
agent.checkpoint(state={"approach": "step-by-step"})
|
|
107
|
+
|
|
108
|
+
# Branch off to try something creative
|
|
109
|
+
agent.branch("creative")
|
|
110
|
+
agent.checkpoint(state={"approach": "lateral-thinking"})
|
|
111
|
+
|
|
112
|
+
# Go back to main if creative doesn't work
|
|
113
|
+
agent.switch_branch("main")
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 4. Safe Execution β Automatic Error Recovery
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
def risky_api_call(state):
|
|
120
|
+
# This might fail due to rate limits, timeouts, etc.
|
|
121
|
+
return call_external_api(state["query"])
|
|
122
|
+
|
|
123
|
+
result, checkpoint = agent.safe_execute(
|
|
124
|
+
func=risky_api_call,
|
|
125
|
+
state={"query": "latest news"},
|
|
126
|
+
description="Fetch news articles",
|
|
127
|
+
max_retries=3,
|
|
128
|
+
fallback=use_cached_data # Plan B if all retries fail
|
|
129
|
+
)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 5. Logic Tree β Full Decision Audit Trail
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
print(agent.visualize_tree())
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Output:
|
|
139
|
+
```
|
|
140
|
+
βββ β
Task received [de3eec5f]
|
|
141
|
+
βββ β
Plan created [3a7996fa]
|
|
142
|
+
βββ β API call failed [372aabc7]
|
|
143
|
+
βββ β
Used cache instead [a4d4e95e]
|
|
144
|
+
βββ β
Retry succeeded [330a3284]
|
|
145
|
+
βββ β
Summary generated [67f8369a]
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 6. Decorators β Zero-Code-Change Integration
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from agentgit.decorators import agentgit_step
|
|
152
|
+
|
|
153
|
+
@agentgit_step("analyze_data")
|
|
154
|
+
def analyze(state):
|
|
155
|
+
# Your existing code β unchanged!
|
|
156
|
+
return {"analysis": process(state["data"])}
|
|
157
|
+
|
|
158
|
+
# Automatically checkpointed, with rollback on failure
|
|
159
|
+
result = analyze({"data": raw_data})
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Recovery Strategies
|
|
165
|
+
|
|
166
|
+
| Strategy | When to Use | What It Does |
|
|
167
|
+
|---|---|---|
|
|
168
|
+
| `RetryWithBackoff` | API timeouts, rate limits | Waits longer between each retry |
|
|
169
|
+
| `AlternativePathStrategy` | Logic dead-ends | Switches to a different approach |
|
|
170
|
+
| `DegradeGracefully` | Resource limits | Produces simpler output |
|
|
171
|
+
| `CompositeStrategy` | Complex scenarios | Chains multiple strategies |
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
from agentgit import AgentGit
|
|
175
|
+
from agentgit.strategies import RetryWithBackoff, DegradeGracefully, CompositeStrategy
|
|
176
|
+
|
|
177
|
+
agent = AgentGit(
|
|
178
|
+
"resilient-agent",
|
|
179
|
+
recovery_strategies=[
|
|
180
|
+
CompositeStrategy([
|
|
181
|
+
RetryWithBackoff(base_delay=1.0, max_delay=30.0),
|
|
182
|
+
DegradeGracefully(),
|
|
183
|
+
])
|
|
184
|
+
]
|
|
185
|
+
)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Storage Backends
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
from agentgit.storage import FileSystemStorage, SQLiteStorage
|
|
194
|
+
|
|
195
|
+
# File-based (great for debugging β you can read the JSON files)
|
|
196
|
+
agent = AgentGit("my-agent", storage_backend=FileSystemStorage(".agentgit"))
|
|
197
|
+
|
|
198
|
+
# SQLite (fast queries, good for production)
|
|
199
|
+
agent = AgentGit("my-agent", storage_backend=SQLiteStorage("agent.db"))
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## CLI
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
# Run the interactive demo
|
|
208
|
+
agentgit demo
|
|
209
|
+
|
|
210
|
+
# View checkpoint history
|
|
211
|
+
agentgit log
|
|
212
|
+
|
|
213
|
+
# Visualize the reasoning tree
|
|
214
|
+
agentgit tree
|
|
215
|
+
|
|
216
|
+
# List branches
|
|
217
|
+
agentgit branches
|
|
218
|
+
|
|
219
|
+
# Compare two checkpoints
|
|
220
|
+
agentgit diff abc123 def456
|
|
221
|
+
|
|
222
|
+
# View metrics
|
|
223
|
+
agentgit metrics
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Framework Integration
|
|
229
|
+
|
|
230
|
+
### LangChain
|
|
231
|
+
```python
|
|
232
|
+
from agentgit.decorators import AgentGitMiddleware
|
|
233
|
+
|
|
234
|
+
middleware = AgentGitMiddleware("langchain-agent")
|
|
235
|
+
wrapped_chain = middleware.wrap(my_chain.invoke, "process_query")
|
|
236
|
+
result = wrapped_chain({"input": "Hello"})
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Any Python Agent
|
|
240
|
+
```python
|
|
241
|
+
from agentgit.decorators import checkpoint_context
|
|
242
|
+
|
|
243
|
+
with checkpoint_context(description="Data processing") as ctx:
|
|
244
|
+
result = process_data(data)
|
|
245
|
+
ctx.state = {"result": result}
|
|
246
|
+
# Auto-rolls back on exception
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## Architecture
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
255
|
+
β Your AI Agent β
|
|
256
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
257
|
+
β Decorators & Middleware (agentgit.decorators) β
|
|
258
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
259
|
+
β AgentGit Core Engine (agentgit.engine) β
|
|
260
|
+
β βββββββββββ ββββββββββ ββββββββββ ββββββββββββ β
|
|
261
|
+
β βCheckpointβ β Branch β βRollbackβ βLogic Treeβ β
|
|
262
|
+
β βββββββββββ ββββββββββ ββββββββββ ββββββββββββ β
|
|
263
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
264
|
+
β Recovery Strategies (agentgit.strategies) β
|
|
265
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
266
|
+
β Serializers (agentgit.serializers) β
|
|
267
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
268
|
+
β Storage Backends: FileSystem β SQLite β Memory β
|
|
269
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## Contributing
|
|
275
|
+
|
|
276
|
+
Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
277
|
+
|
|
278
|
+
## License
|
|
279
|
+
|
|
280
|
+
MIT License β see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AgentGit β Git for AI Thoughts
|
|
3
|
+
================================
|
|
4
|
+
An open-source Checkpointing & Recovery Protocol for AI Agents.
|
|
5
|
+
|
|
6
|
+
Save, branch, rollback, and recover agent "state of mind" at every reasoning step.
|
|
7
|
+
Think of it as version control for AI cognition.
|
|
8
|
+
|
|
9
|
+
Quick Start:
|
|
10
|
+
from agentgit import AgentGit
|
|
11
|
+
|
|
12
|
+
agent = AgentGit("my-agent")
|
|
13
|
+
|
|
14
|
+
agent.checkpoint(
|
|
15
|
+
state={"reasoning": "Analyzing user query..."},
|
|
16
|
+
metadata={"step": "initial_analysis"}
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
# If something goes wrong, rollback:
|
|
20
|
+
agent.rollback()
|
|
21
|
+
|
|
22
|
+
# Or branch to explore alternative reasoning:
|
|
23
|
+
agent.branch("alternative-approach")
|
|
24
|
+
|
|
25
|
+
License: MIT
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
__version__ = "0.1.0"
|
|
29
|
+
__author__ = "AgentGit Contributors"
|
|
30
|
+
|
|
31
|
+
from .engine import AgentGit, Checkpoint, Branch, LogicTree
|
|
32
|
+
from .strategies import RecoveryStrategy, RetryWithBackoff, AlternativePathStrategy
|
|
33
|
+
from .serializers import StateSerializer, JSONSerializer, PickleSerializer
|
|
34
|
+
from .storage import StorageBackend, FileSystemStorage, SQLiteStorage
|
|
35
|
+
|
|
36
|
+
__all__ = [
|
|
37
|
+
"AgentGit",
|
|
38
|
+
"Checkpoint",
|
|
39
|
+
"Branch",
|
|
40
|
+
"LogicTree",
|
|
41
|
+
"RecoveryStrategy",
|
|
42
|
+
"RetryWithBackoff",
|
|
43
|
+
"AlternativePathStrategy",
|
|
44
|
+
"StateSerializer",
|
|
45
|
+
"JSONSerializer",
|
|
46
|
+
"PickleSerializer",
|
|
47
|
+
"StorageBackend",
|
|
48
|
+
"FileSystemStorage",
|
|
49
|
+
"SQLiteStorage",
|
|
50
|
+
]
|