Skip to content

Python: feat(autogenstudio): add SensitiveDataRedactor to sanitize credentials from Agent Responses (#3255) - #8357

Open
SparkyPunk (sparkysolutions10-pixel) wants to merge 1 commit into
microsoft:mainfrom
sparkysolutions10-pixel:fix/autogen-studio-pii-redaction-3255
Open

SparkyPunk (sparkysolutions10-pixel) wants to merge 1 commit into
microsoft:mainfrom
sparkysolutions10-pixel:fix/autogen-studio-pii-redaction-3255

Conversation

@sparkysolutions10-pixel

Copy link
Copy Markdown

Summary

This PR addresses issue #3255 by introducing a modular, dynamic, and generic credential & sensitive data redaction architecture (SensitiveDataRedactor) for AutoGen Studio.

Motivation & Problem Statement

In AutoGen Studio, agents execute tools and skills that interact with the local environment. When agents call tools, process environment variables (such as OpenAI/Anthropic/Azure/AWS keys), or generate reasoning outputs, there is a risk of inadvertently emitting raw credentials or secrets into streaming websocket events, SQLite database records, and the Studio UI.

Key Changes

  1. SensitiveDataRedactor Engine (�utogenstudio.utils.redactor):

    • Sanitizes high-entropy credential patterns (OpenAI sk-..., Anthropic sk-ant-..., GitHub PATs ghp_..., AWS Access Keys AKIA..., Bearer tokens, Azure Account Keys, Private Key blocks).
    • Dynamically redacts environment variable secrets (�ar.type == 'secret' or sensitive keywords like KEY, SECRET, PASSWORD, TOKEN).
    • Supports user-defined custom regex patterns and customizable replacement masks (default: [REDACTED]).
    • Recursively sanitizes nested dictionaries, lists, and message types (TextMessage, MultiModalMessage, StopMessage, HandoffMessage, ToolCallExecutionEvent, TaskResult, TeamResult).
  2. Studio Settings & Data Models (datamodel/types.py & datamodel.ts):

    • Added RedactionConfig with fields enabled,
      edact_env_vars,
      edact_api_keys, custom_patterns, and
      eplacement.
    • Integrated
      edaction into SettingsConfig with safe default factory (100% backward compatible with existing configurations).
  3. WebSocket & Persistence Layer (web/managers/connection.py):

    • Streamed messages are sanitized before WebSocket dispatch (_send_message).
    • Persisted database messages (Message) and run outcomes ( eam_result, error_message) are sanitized before being saved to SQLite.
  4. TeamManager Execution ( eammanager/teammanager.py):

    • Added optional
      edaction_config parameter to
      un_stream() and
      un() for automatic response sanitation.
  5. Test Coverage ( ests/test_redactor.py):

    • Added 7 comprehensive unit tests covering API key sanitization, environment secrets, custom regex patterns, message types, tool execution results, and nested structures. All tests passing green.

Fixes #3255

Signed-off-by: sparkysolutions10-pixelmy sparkysolutions10@gmail.com

…edentials from Agent Responses (microsoft#3255)

Add SensitiveDataRedactor utility and integration into AutoGen Studio to prevent leakage of sensitive credentials, API keys, and environment variable secrets in agent responses and streaming logs.

- Introduce SensitiveDataRedactor in autogenstudio.utils.redactor
- Add RedactionConfig to SettingsConfig in datamodel/types.py and datamodel.ts
- Integrate redactor in WebSocketManager (streaming, DB persistence, run updates)
- Integrate redactor in TeamManager run and run_stream flows
- Add comprehensive test coverage in tests/test_redactor.py

Fixes microsoft#3255

Signed-off-by: sparkysolutions10-pixelmy <sparkysolutions10@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Need a new feature to redact sensitive information from Agent Response in Autogenstudio

1 participant