trading_agent.memory.checkpoints
¶
Snapshots of a desk's own files, so any change the desk makes can be undone.
Each desk gets its own git repository in workspace/.checkpoints/<desk>.git, kept apart from the project's git. Its working tree is the desk folder, but only Memory.md, memory/, notes/ and skills/agent/ are tracked; everything else in the folder is ignored. A snapshot is taken before every write the desk makes, so each checkpoint is the state just before one change.
Typical usage example:
checkpoints = Checkpoints(Path('workspace/.checkpoints/main.git'), Path('workspace/desks/main')) checkpoints.snapshot('before write_file Memory.md') checkpoints.restore('3f2a9c1')
CheckpointError
¶
Bases: RuntimeError
git could not take, list or restore a checkpoint.
Checkpoint
dataclass
¶
One snapshot.
Attributes:
| Name | Type | Description |
|---|---|---|
checkpoint_id |
str
|
The snapshot's short git commit id. |
created_at |
str
|
When it was taken, as an ISO 8601 string. |
reason |
str
|
What was about to happen, such as "before write_file Memory.md". |
Checkpoints
¶
The checkpoint repository of one desk.
Attributes:
| Name | Type | Description |
|---|---|---|
repository_directory |
The git directory that holds the snapshots. |
|
desk_directory |
The desk folder whose files are snapshotted. |
Describes the repository without touching the disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repository_directory
|
Path
|
The git directory, such as workspace/.checkpoints/main.git. |
required |
desk_directory
|
Path
|
The desk folder. |
required |
Source code in src/trading_agent/memory/checkpoints.py
snapshot
¶
Records the desk's files as they are now, if they changed since the last snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason
|
str
|
What is about to happen, kept as the snapshot's message. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The new checkpoint's id, or None when nothing had changed. |
Raises:
| Type | Description |
|---|---|
CheckpointError
|
git failed. |
Source code in src/trading_agent/memory/checkpoints.py
list
¶
Lists the most recent checkpoints, newest first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
The most checkpoints to list. |
20
|
Returns:
| Type | Description |
|---|---|
list[Checkpoint]
|
The checkpoints, or an empty list when none has been taken. |
Raises:
| Type | Description |
|---|---|
CheckpointError
|
git failed. |
Source code in src/trading_agent/memory/checkpoints.py
restore
¶
Puts the desk's files back as they were at a checkpoint.
The current files are snapshotted first, so a restore can itself be undone. Files created after the checkpoint are removed; files outside Memory.md, memory/, notes/ and skills/agent/ are never touched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_id
|
str
|
The checkpoint to return to. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The id of the snapshot taken just before restoring, or of the current state when nothing had changed. |
Raises:
| Type | Description |
|---|---|
CheckpointError
|
The checkpoint does not exist, or git failed. |