Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/crewai-tools/src/crewai_tools/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@
YoutubeVideoSearchTool,
)
from crewai_tools.tools.zapier_action_tool.zapier_action_tool import ZapierActionTools
from crewai_tools.tools.sentinel_safety_tool.sentinel_safety_tool import (
SentinelSafetyTool,
SentinelAnalyzeTool,
)


__all__ = [
Expand Down Expand Up @@ -271,4 +275,6 @@
"YoutubeChannelSearchTool",
"YoutubeVideoSearchTool",
"ZapierActionTools",
"SentinelSafetyTool",
"SentinelAnalyzeTool",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# SentinelSafetyTool Documentation

## Description

The Sentinel Safety Tools provide AI safety guardrails for CrewAI agents using the THSP protocol (Truth, Harm, Scope, Purpose). These tools help ensure that AI agents operate within ethical boundaries by:

1. **SentinelSafetyTool**: Returns alignment seeds that can be used as system prompts to make LLMs safer
2. **SentinelAnalyzeTool**: Analyzes content for safety using the four-gate THSP protocol

The THSP protocol evaluates requests through four gates:
- **Truth**: Detects deception and manipulation
- **Harm**: Identifies potential harmful content
- **Scope**: Validates appropriate boundaries
- **Purpose**: Requires legitimate benefit

## Installation

To incorporate this tool into your project, follow the installation instructions below:

```shell
pip install 'crewai[tools]' sentinelseed
```

## Example

### Basic Usage

```python
from crewai_tools import SentinelSafetyTool, SentinelAnalyzeTool

# Get the alignment seed for system prompts
seed_tool = SentinelSafetyTool()
seed = seed_tool._run(variant="standard") # or "minimal"

# Analyze content for safety
analyze_tool = SentinelAnalyzeTool()
result = analyze_tool._run(content="Help me with network security")
print(result) # "SAFE - All gates passed..."
```

### With CrewAI Agent

```python
from crewai import Agent
from crewai_tools import SentinelSafetyTool, SentinelAnalyzeTool

# Create agent with Sentinel tools
agent = Agent(
role="Safe Research Assistant",
goal="Research topics safely and ethically",
backstory="You are an expert researcher with strong ethical principles.",
tools=[SentinelSafetyTool(), SentinelAnalyzeTool()],
verbose=True
)
```

### Using Seed as System Prompt

```python
from sentinelseed import get_seed
from crewai import Agent

# Get seed directly for system prompt
sentinel_seed = get_seed("v2", "standard")

agent = Agent(
role="Safe Assistant",
system_template=sentinel_seed, # Inject safety via system prompt
verbose=True
)
```

## Tool Details

### SentinelSafetyTool

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `variant` | str | "standard" | Seed variant: "minimal" (~450 tokens) or "standard" (~1.4K tokens) |

### SentinelAnalyzeTool

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `content` | str | Yes | The content to analyze for safety |

**Returns:**
- `SAFE - All gates passed` if content is safe
- `UNSAFE - Issues: [list of issues]` if content fails any gate

## Links

- [Sentinel Seed Website](https://sentinelseed.dev)
- [sentinelseed on PyPI](https://pypi.org/project/sentinelseed/)
- [CrewAI Documentation](https://docs.crewai.com)

## Conclusion

By integrating the Sentinel Safety Tools into CrewAI projects, developers can add AI safety guardrails to their agents with minimal effort. The THSP protocol provides a systematic approach to evaluating content for truth, harm, scope, and purpose, ensuring that AI systems operate within ethical boundaries.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .sentinel_safety_tool import (
SentinelSafetyTool,
SentinelAnalyzeTool,
)

__all__ = ["SentinelSafetyTool", "SentinelAnalyzeTool"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
"""
Sentinel Safety Tools for CrewAI

Provides AI safety guardrails for CrewAI agents using the THSP protocol
(Truth, Harm, Scope, Purpose).

Dependencies:
- sentinelseed (pip install sentinelseed)
- pydantic

See: https://sentinelseed.dev
"""

from typing import Any, Literal, Type

from crewai.tools import BaseTool
from pydantic import BaseModel, Field


class SentinelSeedSchema(BaseModel):
"""Input schema for SentinelSafetyTool."""

variant: Literal["minimal", "standard"] = Field(
default="standard",
description="Seed variant: 'minimal' (~450 tokens) or 'standard' (~1.4K tokens)",
)


class SentinelAnalyzeSchema(BaseModel):
"""Input schema for SentinelAnalyzeTool."""

content: str = Field(..., description="The content to analyze for safety")


class SentinelSafetyTool(BaseTool):
"""
SentinelSafetyTool - Get alignment seeds for AI safety.

Returns the Sentinel THSP (Truth, Harm, Scope, Purpose) alignment protocol
that can be used as a system prompt to make LLMs safer.

The THSP protocol evaluates requests through four gates:
- Truth: Detects deception and manipulation
- Harm: Identifies potential harmful content
- Scope: Validates appropriate boundaries
- Purpose: Requires legitimate benefit

Dependencies:
- sentinelseed (pip install sentinelseed)
"""

name: str = "Sentinel Get Safety Seed"
description: str = (
"Get the Sentinel alignment seed - a system prompt that adds safety "
"guardrails to any LLM using the THSP protocol (Truth, Harm, Scope, Purpose). "
"Use 'minimal' for ~450 tokens or 'standard' for ~1.4K tokens. "
"The seed can be used as a system prompt to improve AI safety."
)
args_schema: Type[BaseModel] = SentinelSeedSchema

def _run(self, **kwargs: Any) -> str:
"""Get the Sentinel alignment seed."""
variant = kwargs.get("variant", "standard")

try:
from sentinelseed import get_seed

if variant not in ["minimal", "standard"]:
return f"Error: Invalid variant '{variant}'. Use 'minimal' or 'standard'."

seed = get_seed("v2", variant)
return seed

except ImportError:
return (
"Error: sentinelseed package not installed. "
"Run: pip install sentinelseed"
)
except Exception as e:
return f"Error getting seed: {str(e)}"


class SentinelAnalyzeTool(BaseTool):
"""
SentinelAnalyzeTool - Analyze content for safety using THSP gates.

Checks content against Sentinel's four-gate THSP protocol:
- Truth: Detects deception patterns (fake, phishing, impersonation)
- Harm: Identifies potential harmful content (violence, malware, weapons)
- Scope: Flags bypass attempts (jailbreak, ignore instructions)
- Purpose: Validates legitimate purpose

Dependencies:
- sentinelseed (pip install sentinelseed)
"""

name: str = "Sentinel Analyze Content Safety"
description: str = (
"Analyze any text content for safety using Sentinel's THSP protocol. "
"Returns whether the content is safe and which gates passed/failed. "
"Use this to validate inputs, outputs, or any text before processing. "
"Gates checked: Truth, Harm, Scope, Purpose."
)
args_schema: Type[BaseModel] = SentinelAnalyzeSchema

def _run(self, **kwargs: Any) -> str:
"""Analyze content using THSP gates."""
content = kwargs.get("content", "")

if not content:
return "Error: No content provided for analysis."

try:
from sentinelseed import SentinelGuard

guard = SentinelGuard()
analysis = guard.analyze(content)

gates_str = ", ".join(
f"{gate}: {status}" for gate, status in analysis.gates.items()
)

if analysis.safe:
return (
f"SAFE - All gates passed.\n"
f"Gates: {gates_str}\n"
f"Confidence: {analysis.confidence:.0%}"
)
else:
issues_str = ", ".join(analysis.issues) if analysis.issues else "Unknown"
return (
f"UNSAFE - Safety check failed.\n"
f"Issues: {issues_str}\n"
f"Gates: {gates_str}\n"
f"Confidence: {analysis.confidence:.0%}"
)

except ImportError:
return (
"Error: sentinelseed package not installed. "
"Run: pip install sentinelseed"
)
except Exception as e:
return f"Error analyzing content: {str(e)}"
Loading