Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Environments
.env**
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# IDE
.idea/
.vscode/
*.swp
*.swo

# Git
.git
.gitignore

# Misc
.DS_Store
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# syntax=docker/dockerfile:1.3
FROM python:3.12-slim
COPY --from=ghcr.io/astral-sh/uv:0.6.4 /uv /uvx /bin/

# Install system dependencies
RUN apt-get update && apt-get install -y \
htop \
vim \
curl \
tar \
python3-dev \
postgresql-client \
build-essential \
libpq-dev \
gcc \
cmake \
netcat-openbsd \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Install tctl (Temporal CLI)
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 && \
tar -xzf /tmp/tctl.tar.gz -C /usr/local/bin && \
chmod +x /usr/local/bin/tctl && \
rm /tmp/tctl.tar.gz

RUN uv pip install --system --upgrade pip setuptools wheel

ENV UV_HTTP_TIMEOUT=1000

# Copy just the requirements file to optimize caching
COPY 010_agent_chat/requirements.txt /app/requirements.txt

WORKDIR /app/

# Install the required Python packages
RUN uv pip install --system -r requirements.txt

# Copy the project code
COPY 010_agent_chat/project /app/project

# Run the ACP server using uvicorn
CMD ["uvicorn", "project.acp:acp", "--host", "0.0.0.0", "--port", "8000"]

# When we deploy the worker, we will replace the CMD with the following
# CMD ["python", "-m", "run_worker"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# [Agentic] Agent Chat with Guardrails

This tutorial demonstrates how to implement streaming multiturn tool-enabled chat with input and output guardrails using Temporal workflows in AgentEx agents.

## Overview

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.

## Guardrails

### Input Guardrails
- **Spaghetti Guardrail**: Blocks any mention of "spaghetti" in user messages
- **Soup Guardrail**: Blocks any mention of "soup" in user messages

### Output Guardrails
- **Pizza Guardrail**: Prevents the AI from mentioning "pizza" in responses
- **Sushi Guardrail**: Prevents the AI from mentioning "sushi" in responses

## Testing the Guardrails

To see the guardrails in action:

1. **Test Input Guardrails:**
- Try: "Tell me about spaghetti"
- Try: "What's your favorite soup?"
- The guardrails will block these messages before they reach the AI

2. **Test Output Guardrails:**
- Ask: "What are popular Italian foods?" (may trigger pizza guardrail)
- Ask: "What are popular Japanese foods?" (may trigger sushi guardrail)
- The AI may generate responses containing these words, but the guardrails will block them

## Implementation Details

The guardrails are implemented as functions that:
- Check the input/output for specific content
- Return a `GuardrailFunctionOutput` with:
- `tripwire_triggered`: Whether to block the content
- `output_info`: Metadata about the check
- `rejection_message`: Custom message shown when content is blocked

See `workflow.py` for the complete implementation.
Loading
Loading