Skip to content

Commit 38f882b

Browse files
Merge pull request #96 from scaleapi/bill/guardrails
Feat: Guardrail support
2 parents 1724792 + a8bbc9d commit 38f882b

File tree

14 files changed

+4814
-43
lines changed

14 files changed

+4814
-43
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
23+
# Environments
24+
.env**
25+
.venv
26+
env/
27+
venv/
28+
ENV/
29+
env.bak/
30+
venv.bak/
31+
32+
# IDE
33+
.idea/
34+
.vscode/
35+
*.swp
36+
*.swo
37+
38+
# Git
39+
.git
40+
.gitignore
41+
42+
# Misc
43+
.DS_Store
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# syntax=docker/dockerfile:1.3
2+
FROM python:3.12-slim
3+
COPY --from=ghcr.io/astral-sh/uv:0.6.4 /uv /uvx /bin/
4+
5+
# Install system dependencies
6+
RUN apt-get update && apt-get install -y \
7+
htop \
8+
vim \
9+
curl \
10+
tar \
11+
python3-dev \
12+
postgresql-client \
13+
build-essential \
14+
libpq-dev \
15+
gcc \
16+
cmake \
17+
netcat-openbsd \
18+
&& apt-get clean \
19+
&& rm -rf /var/lib/apt/lists/*
20+
21+
# Install tctl (Temporal CLI)
22+
RUN curl -L https://github.com/temporalio/tctl/releases/download/v1.18.1/tctl_1.18.1_linux_arm64.tar.gz -o /tmp/tctl.tar.gz && \
23+
tar -xzf /tmp/tctl.tar.gz -C /usr/local/bin && \
24+
chmod +x /usr/local/bin/tctl && \
25+
rm /tmp/tctl.tar.gz
26+
27+
RUN uv pip install --system --upgrade pip setuptools wheel
28+
29+
ENV UV_HTTP_TIMEOUT=1000
30+
31+
# Copy just the requirements file to optimize caching
32+
COPY 010_agent_chat/requirements.txt /app/requirements.txt
33+
34+
WORKDIR /app/
35+
36+
# Install the required Python packages
37+
RUN uv pip install --system -r requirements.txt
38+
39+
# Copy the project code
40+
COPY 010_agent_chat/project /app/project
41+
42+
# Run the ACP server using uvicorn
43+
CMD ["uvicorn", "project.acp:acp", "--host", "0.0.0.0", "--port", "8000"]
44+
45+
# When we deploy the worker, we will replace the CMD with the following
46+
# CMD ["python", "-m", "run_worker"]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# [Agentic] Agent Chat with Guardrails
2+
3+
This tutorial demonstrates how to implement streaming multiturn tool-enabled chat with input and output guardrails using Temporal workflows in AgentEx agents.
4+
5+
## Overview
6+
7+
This example extends the basic agent chat functionality by adding guardrails that can filter both user inputs and AI outputs. This is useful for content moderation, compliance, or preventing certain topics from being discussed.
8+
9+
## Guardrails
10+
11+
### Input Guardrails
12+
- **Spaghetti Guardrail**: Blocks any mention of "spaghetti" in user messages
13+
- **Soup Guardrail**: Blocks any mention of "soup" in user messages
14+
15+
### Output Guardrails
16+
- **Pizza Guardrail**: Prevents the AI from mentioning "pizza" in responses
17+
- **Sushi Guardrail**: Prevents the AI from mentioning "sushi" in responses
18+
19+
## Testing the Guardrails
20+
21+
To see the guardrails in action:
22+
23+
1. **Test Input Guardrails:**
24+
- Try: "Tell me about spaghetti"
25+
- Try: "What's your favorite soup?"
26+
- The guardrails will block these messages before they reach the AI
27+
28+
2. **Test Output Guardrails:**
29+
- Ask: "What are popular Italian foods?" (may trigger pizza guardrail)
30+
- Ask: "What are popular Japanese foods?" (may trigger sushi guardrail)
31+
- The AI may generate responses containing these words, but the guardrails will block them
32+
33+
## Implementation Details
34+
35+
The guardrails are implemented as functions that:
36+
- Check the input/output for specific content
37+
- Return a `GuardrailFunctionOutput` with:
38+
- `tripwire_triggered`: Whether to block the content
39+
- `output_info`: Metadata about the check
40+
- `rejection_message`: Custom message shown when content is blocked
41+
42+
See `workflow.py` for the complete implementation.

0 commit comments

Comments
 (0)