Workspace¶
deep_db_agents.workspace ¶
Materialization of large results to file, outside the agent's context.
The pattern: datasets too large to "read" are saved to file (Parquet or CSV) in a workspace area; only metadata, a preview, and a few statistics are returned to the agent. This decouples data volume from context volume.
MaterializedResult
dataclass
¶
MaterializedResult(path: str, fmt: str, row_count: int, columns: list[str], preview: list[dict[str, Any]], stats: dict[str, dict[str, float]])
Metadata about a result saved to file (never the full rows).
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
Path of the file the result was written to. |
fmt |
str
|
Format the result was written in ( |
row_count |
int
|
Total number of rows written. |
columns |
list[str]
|
Ordered list of column names. |
preview |
list[dict[str, Any]]
|
The first few rows, as a list of |
stats |
dict[str, dict[str, float]]
|
Per-column numeric statistics ( |
to_summary ¶
to_summary() -> str
Build a compact textual summary to return to the agent.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A multi-line summary describing where the result was saved, its |
str
|
columns, numeric statistics (if any), and a preview of the first rows. |
Source code in src/deep_db_agents/workspace.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
materialize_result ¶
materialize_result(columns: Sequence[str], rows: Sequence[Sequence[Any]], backend: BackendProtocol, *, fmt: str = 'csv', filename: str | None = None, preview_rows: int = 5) -> MaterializedResult
Save rows to file and return only the metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
Sequence[str]
|
Ordered column names. |
required |
rows
|
Sequence[Sequence[Any]]
|
Row data, each row aligned with |
required |
backend
|
BackendProtocol
|
The deepagents backend used to write the file (workspace filesystem). |
required |
fmt
|
str
|
Output format, either |
'csv'
|
filename
|
str | None
|
Name of the file to write; if |
None
|
preview_rows
|
int
|
Number of rows to include in the returned preview. |
5
|
Returns:
| Name | Type | Description |
|---|---|---|
MaterializedResult |
MaterializedResult
|
Metadata about the saved file, including path, row count, |
MaterializedResult
|
columns, a preview, and numeric statistics. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If |
OSError
|
If writing the file via |
ValueError
|
If |
Source code in src/deep_db_agents/workspace.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |