-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
209 lines (176 loc) · 5.93 KB
/
start.sh
File metadata and controls
209 lines (176 loc) · 5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
# Startup script for Sandboxed LangGraph Agent with Azure OpenAI support
# Works on Linux and macOS
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Helper functions
print_header() {
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}========================================${NC}"
}
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠ $1${NC}"
}
print_error() {
echo -e "${RED}✗ $1${NC}"
}
# Main script
print_header "Sandboxed LangGraph Agent - Startup Script"
# Check Python version
echo ""
echo "Checking Python version..."
if ! command -v python3 &> /dev/null; then
print_error "Python 3 is not installed. Please install Python 3.11 or higher."
exit 1
fi
PYTHON_VERSION=$(python3 --version | cut -d' ' -f2)
REQUIRED_VERSION="3.11"
if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$PYTHON_VERSION" | sort -V | head -n1)" != "$REQUIRED_VERSION" ]; then
print_error "Python $REQUIRED_VERSION or higher is required. Found: $PYTHON_VERSION"
exit 1
fi
print_success "Python $PYTHON_VERSION detected"
# Check Docker
echo ""
echo "Checking Docker..."
if ! command -v docker &> /dev/null; then
print_error "Docker is not installed. Please install Docker first."
exit 1
fi
if ! docker ps &> /dev/null; then
print_error "Docker is not running. Please start Docker."
exit 1
fi
print_success "Docker is running"
# Check for uv package manager
echo ""
echo "Checking for uv package manager..."
if ! command -v uv &> /dev/null; then
print_warning "uv not found. Installing uv..."
curl -LsSf https://astral.sh/uv/install.sh | sh > /dev/null 2>&1
# Add uv to PATH for this session
export PATH="$HOME/.cargo/bin:$PATH"
if ! command -v uv &> /dev/null; then
print_error "Failed to install uv. Please install manually: https://github.com/astral-sh/uv"
exit 1
fi
print_success "uv installed"
else
print_success "uv is available"
fi
# Create virtual environment if it doesn't exist
echo ""
if [ ! -d "venv" ]; then
echo "Creating virtual environment with uv..."
uv venv venv --python python3
print_success "Virtual environment created"
else
print_success "Virtual environment already exists"
fi
# Activate virtual environment
echo ""
echo "Activating virtual environment..."
source venv/bin/activate
print_success "Virtual environment activated"
# Install dependencies using uv
echo ""
echo "Installing dependencies with uv (this is much faster than pip)..."
uv pip install -r requirements.txt
print_success "Dependencies installed"
# Setup .env file
echo ""
if [ ! -f ".env" ]; then
echo "Creating .env file from .env.example..."
cp .env.example .env
print_warning ".env file created. Please configure your API keys!"
echo ""
echo "To use Azure OpenAI, edit .env and set:"
echo " - LLM_PROVIDER=azure"
echo " - AZURE_OPENAI_API_KEY=your_api_key"
echo " - AZURE_OPENAI_ENDPOINT=your_endpoint"
echo " - AZURE_OPENAI_DEPLOYMENT=your_deployment_name"
echo ""
read -p "Press Enter to open .env file in default editor (or Ctrl+C to skip)..."
${EDITOR:-nano} .env
else
print_success ".env file already exists"
fi
# Check LLM provider configuration
echo ""
echo "Checking LLM configuration..."
if [ -f ".env" ]; then
source .env
if [ "$LLM_PROVIDER" = "azure" ]; then
print_success "LLM Provider: Azure OpenAI"
# Validate Azure config
if [ -z "$AZURE_OPENAI_API_KEY" ] || [ "$AZURE_OPENAI_API_KEY" = "your_azure_openai_api_key_here" ]; then
print_error "AZURE_OPENAI_API_KEY is not set in .env file"
exit 1
fi
if [ -z "$AZURE_OPENAI_ENDPOINT" ] || [ "$AZURE_OPENAI_ENDPOINT" = "https://your-resource-name.openai.azure.com/" ]; then
print_error "AZURE_OPENAI_ENDPOINT is not set in .env file"
exit 1
fi
if [ -z "$AZURE_OPENAI_DEPLOYMENT" ] || [ "$AZURE_OPENAI_DEPLOYMENT" = "your_deployment_name" ]; then
print_error "AZURE_OPENAI_DEPLOYMENT is not set in .env file"
exit 1
fi
print_success "Azure OpenAI configuration validated"
elif [ "$LLM_PROVIDER" = "anthropic" ]; then
print_success "LLM Provider: Anthropic Claude"
if [ -z "$ANTHROPIC_API_KEY" ] || [ "$ANTHROPIC_API_KEY" = "your_anthropic_api_key_here" ]; then
print_error "ANTHROPIC_API_KEY is not set in .env file"
exit 1
fi
print_success "Anthropic configuration validated"
else
print_warning "Unknown LLM_PROVIDER: $LLM_PROVIDER (defaulting to anthropic)"
fi
fi
# Build Docker image
echo ""
echo "Checking Docker image..."
if ! docker image inspect sandbox-agent:latest &> /dev/null; then
echo "Building Docker image (this may take a few minutes)..."
docker compose -f docker/docker-compose.yml build
print_success "Docker image built"
else
print_success "Docker image already exists"
read -p "Rebuild Docker image? (y/N): " rebuild
if [ "$rebuild" = "y" ] || [ "$rebuild" = "Y" ]; then
docker compose -f docker/docker-compose.yml build
print_success "Docker image rebuilt"
fi
fi
# Run test
echo ""
print_header "Running Test Task"
echo ""
echo "Running a simple test task..."
echo ""
python3 -m src.main run "Print 'Hello from Azure OpenAI!' to a file called test.txt"
echo ""
print_success "Test completed!"
echo ""
print_header "Setup Complete!"
echo ""
echo "Your sandbox agent is ready to use with Azure OpenAI!"
echo ""
echo "Usage examples:"
echo " python3 -m src.main run \"your task here\""
echo " python3 -m src.main info"
echo " python3 -m src.main status"
echo " python3 -m src.main example hello"
echo ""
echo "To switch between Anthropic and Azure OpenAI:"
echo " Edit .env and change LLM_PROVIDER=azure or LLM_PROVIDER=anthropic"
echo ""