| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | // DeliveryExecutionScope is host-owned state for a multi-turn task. It never |
| 9 | // enters the provider request; it only controls delivery evidence lifetime and |
| 10 | // trusted task classification across synthetic continuation turns. |
| 11 | type DeliveryExecutionScope struct { |
| 12 | ID string |
| 13 | TaskText string |
| 14 | } |
| 15 | |
| 16 | type deliveryExecutionScopeKey struct{} |
| 17 | |
| 18 | func WithDeliveryExecutionScope(ctx context.Context, scope DeliveryExecutionScope) context.Context { |
| 19 | scope.ID = strings.TrimSpace(scope.ID) |
| 20 | scope.TaskText = strings.TrimSpace(scope.TaskText) |
| 21 | if scope.ID == "" { |
| 22 | return ctx |
| 23 | } |
| 24 | return context.WithValue(ctx, deliveryExecutionScopeKey{}, scope) |
| 25 | } |
| 26 | |
| 27 | func DeliveryExecutionScopeFromContext(ctx context.Context) (DeliveryExecutionScope, bool) { |
| 28 | if ctx == nil { |
| 29 | return DeliveryExecutionScope{}, false |
| 30 | } |
| 31 | scope, ok := ctx.Value(deliveryExecutionScopeKey{}).(DeliveryExecutionScope) |
| 32 | if !ok || strings.TrimSpace(scope.ID) == "" { |
| 33 | return DeliveryExecutionScope{}, false |
| 34 | } |
| 35 | return scope, true |
| 36 | } |
| 37 |