Commit a1fa913
authored
feat(go): add ContentCaptureMode for SDK-level content stripping (#21)
Callers now have a way to prevent text from leaving the process via the
export pipeline or OTel attributes. `MetadataOnly` mode strips all text
content at the SDK level while preserving message structure, tool names,
usage, and timing.
The existing `IncludeContent` bool on `ToolExecutionStart` only
controlled span attributes for individual tools. `ContentCapture`
supersedes it with a mode that applies to the entire generation and
propagates to child tool executions via context. `IncludeContent`
continues to work for backward compatibility under the default
`NoToolContent` mode.
### Modes
| Mode | Generations | Tool spans |
|------|------------|------------|
| `Full` | All content exported | Arguments and results in span
attributes |
| `NoToolContent` (SDK default, same as before this PR) | All content
exported | Excluded |
| `MetadataOnly` | Structure preserved, text stripped | Arguments and
results excluded |
### Example
```go
// Client-level default
client := sigil.NewClient(sigil.Config{
ContentCapture: sigil.ContentCaptureModeMetadataOnly,
})
// Per-generation override
ctx, rec := client.StartGeneration(ctx, sigil.GenerationStart{
ContentCapture: sigil.ContentCaptureModeFull,
})
// Tool executions inherit from parent generation
_, toolRec := client.StartToolExecution(ctx, sigil.ToolExecutionStart{
ToolName: "search",
})
```
---
### Dynamic resolution via ContentCaptureResolver
A callback on `sigil.Config` that resolves the capture mode
per-recording at runtime. Useful for feature flags, per-tenant policies,
or context-dependent decisions.
```go
client := sigil.NewClient(sigil.Config{
ContentCaptureResolver: func(ctx context.Context, metadata map[string]any) sigil.ContentCaptureMode {
if shouldStripContent(ctx, metadata) {
return sigil.ContentCaptureModeMetadataOnly
}
return sigil.ContentCaptureModeDefault // fall through to Config.ContentCapture
},
})
```
Resolution precedence (highest -> lowest):
1. Per-recording `ContentCapture` field (on `GenerationStart` /
`ToolExecutionStart`)
2. `ContentCaptureResolver` return value
3. `Config.ContentCapture` (client default, resolves to `NoToolContent`
when unset to preserve old behaviour)
Panics in the resolver are recovered and treated as `MetadataOnly`.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes what generation payloads and tool span attributes can contain
(including new MetadataOnly stripping), which can affect downstream
ingestion/observability and validation behavior. Defaults aim to
preserve prior behavior, but misconfiguration could unintentionally drop
content or export more than intended.
>
> **Overview**
> Introduces `ContentCaptureMode` with client defaults
(`Config.ContentCapture`), per-generation
(`GenerationStart.ContentCapture`) and per-tool
(`ToolExecutionStart.ContentCapture`) overrides, plus a
`Config.ContentCaptureResolver` callback (panic-safe, fail-closed) to
resolve capture policy per request.
>
> When `MetadataOnly` is effective, generations are stamped with
`sigil.sdk.content_capture_mode` and have prompts/messages/tool
I/O/artifacts stripped before enqueue/export, while preserving structure
and operational fields; tool executions also inherit the parent
generation’s mode via context and only include arguments/results in span
attributes when allowed (keeping `IncludeContent` as deprecated
backward-compat opt-in under the default behavior).
>
> Extends validation to accept stripped text/thinking parts, updates
rating submission to drop `Comment` under `MetadataOnly`, and
adds/updates docs, examples, and tests to cover mode resolution,
inheritance, and stripping behavior.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
ed684ca. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent a6d244e commit a1fa913
File tree
13 files changed
+1074
-68
lines changed- go/sigil
- sigiltest
13 files changed
+1074
-68
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
29 | 47 | | |
30 | 48 | | |
31 | 49 | | |
| |||
226 | 244 | | |
227 | 245 | | |
228 | 246 | | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
234 | 253 | | |
235 | 254 | | |
236 | 255 | | |
| |||
455 | 474 | | |
456 | 475 | | |
457 | 476 | | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
458 | 483 | | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
464 | 490 | | |
465 | 491 | | |
466 | 492 | | |
| |||
575 | 601 | | |
576 | 602 | | |
577 | 603 | | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
578 | 610 | | |
579 | 611 | | |
580 | 612 | | |
581 | 613 | | |
582 | 614 | | |
583 | 615 | | |
584 | | - | |
| 616 | + | |
585 | 617 | | |
586 | 618 | | |
587 | 619 | | |
| |||
661 | 693 | | |
662 | 694 | | |
663 | 695 | | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
664 | 701 | | |
665 | 702 | | |
666 | 703 | | |
667 | 704 | | |
668 | 705 | | |
669 | 706 | | |
670 | 707 | | |
671 | | - | |
| 708 | + | |
672 | 709 | | |
673 | 710 | | |
674 | 711 | | |
| |||
1078 | 1115 | | |
1079 | 1116 | | |
1080 | 1117 | | |
1081 | | - | |
1082 | | - | |
| 1118 | + | |
| 1119 | + | |
1083 | 1120 | | |
1084 | 1121 | | |
1085 | | - | |
1086 | 1122 | | |
1087 | 1123 | | |
1088 | 1124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1086 | 1086 | | |
1087 | 1087 | | |
1088 | 1088 | | |
| 1089 | + | |
1089 | 1090 | | |
1090 | 1091 | | |
1091 | | - | |
1092 | | - | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
1097 | | - | |
1098 | | - | |
1099 | | - | |
1100 | | - | |
1101 | | - | |
1102 | | - | |
1103 | | - | |
1104 | | - | |
1105 | | - | |
1106 | | - | |
1107 | | - | |
1108 | | - | |
1109 | | - | |
1110 | | - | |
1111 | | - | |
1112 | | - | |
1113 | | - | |
1114 | | - | |
1115 | | - | |
1116 | | - | |
1117 | | - | |
1118 | | - | |
1119 | | - | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
1120 | 1103 | | |
1121 | | - | |
1122 | | - | |
1123 | | - | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
1124 | 1112 | | |
1125 | 1113 | | |
1126 | | - | |
1127 | | - | |
| 1114 | + | |
1128 | 1115 | | |
1129 | 1116 | | |
1130 | | - | |
1131 | | - | |
1132 | | - | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
1133 | 1124 | | |
1134 | | - | |
1135 | | - | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
1136 | 1131 | | |
1137 | | - | |
| 1132 | + | |
1138 | 1133 | | |
1139 | | - | |
1140 | | - | |
1141 | | - | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
1142 | 1140 | | |
1143 | 1141 | | |
1144 | 1142 | | |
| |||
0 commit comments