Skip to content

Commit 995d0f5

Browse files
committed
add autogen sample
0 parents  commit 995d0f5

File tree

17 files changed

+5491
-0
lines changed

17 files changed

+5491
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
FROM mcr.microsoft.com/devcontainers/python:3.13-bookworm

.devcontainer/devcontainer.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile",
4+
"context": ".."
5+
},
6+
"features": {
7+
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
9+
"ghcr.io/devcontainers/features/aws-cli:1": {}
10+
}
11+
}

.github/workflows/deploy.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
environment: playground
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- name: Checkout Repo
18+
uses: actions/checkout@v4
19+
20+
- name: Deploy
21+
uses: DefangLabs/[email protected]
22+
with:
23+
config-env-vars: MISTRAL_API_KEY
24+
env:
25+
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}

.gitignore

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Environment variables
2+
.env
3+
.env.local
4+
.env.production
5+
6+
# Python
7+
__pycache__/
8+
*.py[cod]
9+
*$py.class
10+
*.so
11+
.Python
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
/myenv
29+
30+
# Node.js
31+
node_modules/
32+
npm-debug.log*
33+
yarn-debug.log*
34+
yarn-error.log*
35+
.pnpm-debug.log*
36+
37+
# Frontend build
38+
frontend/dist/
39+
frontend/build/
40+
41+
# IDE
42+
.vscode/
43+
.idea/
44+
*.swp
45+
*.swo
46+
*~
47+
48+
# OS
49+
.DS_Store
50+
.DS_Store?
51+
._*
52+
.Spotlight-V100
53+
.Trashes
54+
ehthumbs.db
55+
Thumbs.db
56+
57+
# Logs
58+
*.log
59+
logs/
60+
61+
# Runtime data
62+
pids
63+
*.pid
64+
*.seed
65+
*.pid.lock
66+
67+
# Coverage directory used by tools like istanbul
68+
coverage/
69+
70+
# nyc test coverage
71+
.nyc_output
72+
73+
# Dependency directories
74+
jspm_packages/
75+
76+
# Optional npm cache directory
77+
.npm
78+
79+
# Optional eslint cache
80+
.eslintcache
81+
82+
# Microbundle cache
83+
.rpt2_cache/
84+
.rts2_cache_cjs/
85+
.rts2_cache_es/
86+
.rts2_cache_umd/
87+
88+
# Optional REPL history
89+
.node_repl_history
90+
91+
# Output of 'npm pack'
92+
*.tgz
93+
94+
# Yarn Integrity file
95+
.yarn-integrity
96+
97+
# parcel-bundler cache (https://parceljs.org/)
98+
.cache
99+
.parcel-cache
100+
101+
# next.js build output
102+
.next
103+
104+
# nuxt.js build output
105+
.nuxt
106+
107+
# vuepress build output
108+
.vuepress/dist
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Agentic Autogen
2+
3+
[![1-click-deploy](https://raw.githubusercontent.com/DefangLabs/defang-assets/main/Logos/Buttons/SVG/deploy-with-defang.svg)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-agentic-autogen-template%26template_owner%3DDefangSamples)
4+
5+
This sample shows an agentic Autogen application using Mistral and FastAPI, deployed with Defang. For demonstration purposes, it will require a Mistral API key (see [Configuration](#configuration) for more details). However, you are free to modify it to use a different LLM, say the Defang OpenAI Access Gateway service, as an alternative. Note that the Vite React frontend is served through the FastAPI backend so that they can be treated as one service in production.
6+
7+
## Prerequisites
8+
9+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
11+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
12+
13+
## Development
14+
15+
To run the application locally, you can use the following command:
16+
17+
```bash
18+
docker compose up --build
19+
```
20+
21+
## Configuration
22+
23+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):
24+
25+
> Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
26+
27+
### `MISTRAL_API_KEY`
28+
An API key to access the [MistralAI] LLM.
29+
```bash
30+
defang config set MISTRAL_API_KEY
31+
```
32+
33+
## Deployment
34+
35+
> [!NOTE]
36+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
37+
38+
### Defang Playground
39+
40+
Deploy your application to the Defang Playground by opening up your terminal and typing:
41+
```bash
42+
defang compose up
43+
```
44+
45+
### BYOC
46+
47+
If you want to deploy to your own cloud account, you can [use Defang BYOC](https://docs.defang.io/docs/tutorials/deploy-to-your-cloud).
48+
49+
---
50+
51+
Title: Agentic Autogen
52+
53+
Short Description: An Autogen agent application using Mistral and FastAPI, deployed with Defang.
54+
55+
Tags: Agent, Autogen, Mistral, FastAPI, Vite, React, Python, JavaScript, AI
56+
57+
Languages: Python, JavaScript

compose.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
services:
3+
autogen:
4+
build:
5+
context: ./src
6+
dockerfile: Dockerfile
7+
ports:
8+
- "3000:3000"
9+
environment:
10+
- MISTRAL_API_KEY=${MISTRAL_API_KEY}
11+
restart: unless-stopped
12+
healthcheck:
13+
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
14+
interval: 30s
15+
timeout: 10s
16+
retries: 3

src/.dockerignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Default .dockerignore file for Defang
2+
**/__pycache__
3+
**/.direnv
4+
**/.DS_Store
5+
**/.envrc
6+
**/.git
7+
**/.github
8+
**/.idea
9+
**/.next
10+
**/.vscode
11+
**/compose.*.yaml
12+
**/compose.*.yml
13+
**/compose.yaml
14+
**/compose.yml
15+
**/docker-compose.*.yaml
16+
**/docker-compose.*.yml
17+
**/docker-compose.yaml
18+
**/docker-compose.yml
19+
**/node_modules
20+
**/Thumbs.db
21+
# Dockerfile
22+
# *.Dockerfile
23+
# Ignore our own binary, but only in the root to avoid ignoring subfolders
24+
defang
25+
defang.exe
26+
# Ignore our project-level state
27+
.defang
28+
29+
**/myenv

src/Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# ------------ FRONTEND BUILD STAGE ------------ #
2+
FROM node:22-alpine AS frontend-build
3+
4+
WORKDIR /frontend
5+
6+
# Copy only package files first (cache optimization)
7+
COPY frontend/package*.json ./
8+
RUN npm ci
9+
10+
# Copy rest of the frontend source
11+
COPY frontend/ ./
12+
RUN npm run build
13+
14+
15+
# ------------ BACKEND STAGE ------------ #
16+
FROM python:3.13-slim AS backend
17+
18+
WORKDIR /app
19+
20+
# Install build dependencies for Python packages
21+
RUN apt-get update && apt-get install -y \
22+
gcc \
23+
curl \
24+
&& rm -rf /var/lib/apt/lists/*
25+
26+
# Install dependencies
27+
COPY backend/requirements.txt ./
28+
RUN pip install --no-cache-dir -r requirements.txt
29+
30+
# Copy backend code
31+
COPY backend/ ./
32+
33+
# Copy built frontend into backend's static folder
34+
COPY --from=frontend-build /frontend/dist ./static
35+
36+
# Optionally expose the same port for both backend and frontend
37+
EXPOSE 3000
38+
39+
# Healthcheck endpoint
40+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
41+
CMD curl -f http://localhost:3000/health || exit 1
42+
43+
# Start the backend server (which serves both API + frontend files)
44+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3000"]

0 commit comments

Comments
 (0)