trading_agent.tools.path_policy
¶
Decides which files a desk's file tools may read and write.
A relative path is taken from the desk's own folder, so "Memory.md" and "notes/today.md" mean the desk's files. Every path is resolved to where it really is before it is checked, so neither "../" nor a link can lead outside the allowed places.
- Reading is allowed anywhere except the hidden secret files and folders that the bash sandbox also hides.
- Writing is allowed only in the desk's memory, notes and scratch folders and its Memory.md. The user's files can only be changed through propose_file_change.
Typical usage example:
policy = PathPolicy(desk_directory, hidden_paths) path = policy.readable('Memory.md')
PathRefusedError
¶
Bases: ValueError
A file tool asked for a path it may not use.
PathPolicy
¶
The read and write rules for one desk's file tools.
Attributes:
| Name | Type | Description |
|---|---|---|
desk_directory |
The desk's own folder, where relative paths start. |
Creates the policy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_directory
|
Path
|
The desk's own folder. |
required |
hidden_paths
|
Sequence[Path]
|
Resolved secret files and folders that may not be read. |
required |
Source code in src/trading_agent/tools/path_policy.py
readable
¶
Resolves a path the desk wants to read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requested
|
str
|
The path as the model wrote it. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The resolved path. |
Raises:
| Type | Description |
|---|---|
PathRefusedError
|
The path is, or is inside, a hidden secret. |
Source code in src/trading_agent/tools/path_policy.py
writable
¶
Resolves a path the desk wants to write.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requested
|
str
|
The path as the model wrote it. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The resolved path. |
Raises:
| Type | Description |
|---|---|
PathRefusedError
|
The path is outside the desk's own writable places. |