File size: 6,624 Bytes
046508a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# Deployment Guide for Job Application Agent

## Option 1: LangGraph Cloud (Easiest & Recommended)

### Prerequisites
- LangGraph CLI installed (`langgraph-cli` in requirements.txt)
- `langgraph.json` already configured βœ…

### Steps

1. **Install LangGraph CLI** (if not already):
```powershell
pip install langgraph-cli
```

2. **Login to LangGraph Cloud**:
```powershell
langgraph login
```

3. **Deploy your agent**:
```powershell
langgraph deploy
```

4. **Get your API endpoint** - LangGraph Cloud provides a REST API automatically

### Cost
- **Free tier**: Limited requests/month
- **Paid**: Pay-per-use pricing

### Pros
- βœ… Zero infrastructure management
- βœ… Built-in state persistence
- βœ… Automatic API generation
- βœ… LangSmith integration
- βœ… Perfect for LangGraph apps

### Cons
- ⚠️ Vendor lock-in
- ⚠️ Limited customization

---

## Option 2: Railway.app (Simple & Cheap)

### Steps

1. **Create a FastAPI wrapper** (create `api.py`):
```python
from fastapi import FastAPI, File, UploadFile
from job_writing_agent.workflow import JobWorkflow
import tempfile
import os

app = FastAPI()

@app.post("/generate")
async def generate_application(
    resume: UploadFile = File(...),
    job_description: str,
    content_type: str = "cover_letter"
):
    # Save resume temporarily
    with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp:
        tmp.write(await resume.read())
        resume_path = tmp.name
    
    try:
        workflow = JobWorkflow(
            resume=resume_path,
            job_description_source=job_description,
            content=content_type
        )
        result = await workflow.run()
        return {"result": result}
    finally:
        os.unlink(resume_path)
```

2. **Create `Procfile`**:
```
web: uvicorn api:app --host 0.0.0.0 --port $PORT
```

3. **Deploy to Railway**:
   - Sign up at [railway.app](https://railway.app)
   - Connect GitHub repo
   - Railway auto-detects Python and runs `Procfile`

### Cost
- **Free tier**: $5 credit/month
- **Hobby**: $5/month for 512MB RAM
- **Pro**: $20/month for 2GB RAM

### Pros
- βœ… Very simple deployment
- βœ… Auto-scaling
- βœ… Free tier available
- βœ… Automatic HTTPS

### Cons
- ⚠️ Need to add FastAPI wrapper
- ⚠️ State management needs Redis/Postgres

---

## Option 3: Render.com (Similar to Railway)

### Steps

1. **Create `render.yaml`**:
```yaml
services:
  - type: web
    name: job-writer-api
    env: python
    buildCommand: pip install -r requirements.txt
    startCommand: uvicorn api:app --host 0.0.0.0 --port $PORT
    envVars:
      - key: OPENROUTER_API_KEY
        sync: false
      - key: TAVILY_API_KEY
        sync: false
```

2. **Deploy**:
   - Connect GitHub repo to Render
   - Render auto-detects `render.yaml`

### Cost
- **Free tier**: 750 hours/month (sleeps after 15min inactivity)
- **Starter**: $7/month (always on)

### Pros
- βœ… Free tier for testing
- βœ… Simple YAML config
- βœ… Auto-deploy from Git

### Cons
- ⚠️ Free tier sleeps (cold starts)
- ⚠️ Need FastAPI wrapper

---

## Option 4: Fly.io (Good Free Tier)

### Steps

1. **Install Fly CLI**:
```powershell
iwr https://fly.io/install.ps1 -useb | iex
```

2. **Create `Dockerfile`**:
```dockerfile
FROM python:3.12-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8080"]
```

3. **Deploy**:
```powershell
fly launch
fly deploy
```

### Cost
- **Free tier**: 3 shared-cpu VMs, 3GB storage
- **Paid**: $1.94/month per VM

### Pros
- βœ… Generous free tier
- βœ… Global edge deployment
- βœ… Docker-based (flexible)

### Cons
- ⚠️ Need Docker knowledge
- ⚠️ Need FastAPI wrapper

---

## Option 5: AWS Lambda (Serverless - Pay Per Use)

### Steps

1. **Create Lambda handler** (`lambda_handler.py`):
```python
import json
from job_writing_agent.workflow import JobWorkflow

def lambda_handler(event, context):
    # Parse event
    body = json.loads(event['body'])
    
    workflow = JobWorkflow(
        resume=body['resume_path'],
        job_description_source=body['job_description'],
        content=body.get('content_type', 'cover_letter')
    )
    
    result = workflow.run()
    
    return {
        'statusCode': 200,
        'body': json.dumps({'result': result})
    }
```

2. **Package and deploy** using AWS SAM or Serverless Framework

### Cost
- **Free tier**: 1M requests/month
- **Paid**: $0.20 per 1M requests + compute time

### Pros
- βœ… Pay only for usage
- βœ… Auto-scaling
- βœ… Very cheap for low traffic

### Cons
- ⚠️ 15min timeout limit
- ⚠️ Cold starts
- ⚠️ Complex setup
- ⚠️ Need to handle state externally

---

## Recommendation

**For your use case, I recommend:**

1. **Start with LangGraph Cloud** - Easiest, built for your stack
2. **If you need more control β†’ Railway** - Simple, good free tier
3. **If you need serverless β†’ AWS Lambda** - Cheapest for low traffic

---

## Quick Start: FastAPI Wrapper (for Railway/Render/Fly.io)

Create `api.py` in your project root:

```python
from fastapi import FastAPI, File, UploadFile, HTTPException
from fastapi.responses import JSONResponse
from job_writing_agent.workflow import JobWorkflow
import tempfile
import os
import asyncio

app = FastAPI(title="Job Application Writer API")

@app.get("/")
def health():
    return {"status": "ok"}

@app.post("/generate")
async def generate_application(
    resume: UploadFile = File(...),
    job_description: str,
    content_type: str = "cover_letter"
):
    """Generate job application material."""
    # Save resume temporarily
    with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp:
        content = await resume.read()
        tmp.write(content)
        resume_path = tmp.name
    
    try:
        workflow = JobWorkflow(
            resume=resume_path,
            job_description_source=job_description,
            content=content_type
        )
        
        # Run workflow (assuming it's async or can be wrapped)
        result = await asyncio.to_thread(workflow.run)
        
        return JSONResponse({
            "status": "success",
            "result": result
        })
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))
    finally:
        # Cleanup
        if os.path.exists(resume_path):
            os.unlink(resume_path)

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)
```

Then update `requirements.txt` to ensure FastAPI and uvicorn are included (they already are βœ…).