Skip to content

Commit

Permalink
ag2 and agentchat runtimes added
Browse files Browse the repository at this point in the history
  • Loading branch information
davorrunje committed Dec 2, 2024
1 parent 750da19 commit 76c0a0e
Show file tree
Hide file tree
Showing 37 changed files with 107 additions and 662 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ from typing import Any

from autogen.agentchat import ConversableAgent
from fastagency import UI
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.runtimes.ag2 import AutoGenWorkflows

llm_config = {
"config_list": [
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/en/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ from typing import Any

from autogen.agentchat import ConversableAgent
from fastagency import UI
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.runtimes.ag2 import AutoGenWorkflows

llm_config = {
"config_list": [
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/en/user-guide/runtimes/autogen/websurfer.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Once you run it, FastAgency automatically detects the appropriate app to execute
╰─────────────────────────╯

[INFO] Importing autogen.base.py
[INFO] Initializing FastAgency <FastAgency title=FastAgency application> with workflows: <fastagency.runtimes.autogen. autogen.AutoGenWorkflows object at 0x109a51610> and UI: <fastagency.ui.console.console.ConsoleUI object at 0x109adced0>
[INFO] Initializing FastAgency <FastAgency title=FastAgency application> with workflows: <fastagency.runtimes.ag2. autogen.AutoGenWorkflows object at 0x109a51610> and UI: <fastagency.ui.console.console.ConsoleUI object at 0x109adced0>
[INFO] Initialized FastAgency: <FastAgency title=FastAgency application>

╭──── Importable FastAgency app ────╮
Expand Down Expand Up @@ -226,7 +226,7 @@ Once you run it, FastAgency automatically detects the appropriate app to execute
╰────────────────────────╯

[INFO] Importing autogen.base.py
[INFO] Initializing FastAgency <FastAgency title=FastAgency application> with workflows: <fastagency.runtimes.autogen.autogen.AutoGenWorkflows object at 0x11368cbd0> and UI: <fastagency.ui.console.console.ConsoleUI object at 0x13441c510>
[INFO] Initializing FastAgency <FastAgency title=FastAgency application> with workflows: <fastagency.runtimes.ag2.autogen.AutoGenWorkflows object at 0x11368cbd0> and UI: <fastagency.ui.console.console.ConsoleUI object at 0x13441c510>
[INFO] Initialized FastAgency: <FastAgency title=FastAgency application>

╭─── Importable FastAgency app ────╮
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/en/user-guide/runtimes/autogen/whatsapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ Once you run it, FastAgency automatically detects the appropriate app to execute
2024-11-06 12:05:31,512 [INFO] Patched Operation.function_name
2024-11-06 12:05:31,512 [INFO] Patched fastapi_code_generator.__main__.generate_code
2024-11-06 12:05:31,512 [INFO] Patched Parser.__apply_discriminator_type,
2024-11-06 12:05:31,712 [INFO] Initializing FastAgency <FastAgency title=FastAgency application> with workflows: <fastagency.runtimes.autogen.autogen.AutoGenWorkflows object at 0xffffafd51810> and UI: <fastagency.ui.console.console.ConsoleUI object at 0xffffa043ccd0>
2024-11-06 12:05:31,712 [INFO] Initializing FastAgency <FastAgency title=FastAgency application> with workflows: <fastagency.runtimes.ag2.autogen.AutoGenWorkflows object at 0xffffafd51810> and UI: <fastagency.ui.console.console.ConsoleUI object at 0xffffa043ccd0>
2024-11-06 12:05:31,712 [INFO] Initialized FastAgency: <FastAgency title=FastAgency application>

╭───────────────────── Importable FastAgency app ──────────────────────╮
│ │
│ from docs.docs_src.user_guide.runtimes.autogen.whatsapp import app │
│ from docs.docs_src.user_guide.runtimes.ag2.whatsapp import app │
│ │
╰──────────────────────────────────────────────────────────────────────╯

Expand Down Expand Up @@ -258,12 +258,12 @@ Once you run it, FastAgency automatically detects the appropriate app to execute
2024-11-06 12:01:56,374 [INFO] Patched Operation.function_name
2024-11-06 12:01:56,374 [INFO] Patched fastapi_code_generator.__main__.generate_code
2024-11-06 12:01:56,374 [INFO] Patched Parser.__apply_discriminator_type,
2024-11-06 12:01:56,611 [INFO] Initializing FastAgency <FastAgency title=FastAgency application> with workflows: <fastagency.runtimes.autogen.autogen.AutoGenWorkflows object at 0xffff88721840> and UI: <fastagency.ui.console.console.ConsoleUI object at 0xffff89e50760>
2024-11-06 12:01:56,611 [INFO] Initializing FastAgency <FastAgency title=FastAgency application> with workflows: <fastagency.runtimes.ag2.autogen.AutoGenWorkflows object at 0xffff88721840> and UI: <fastagency.ui.console.console.ConsoleUI object at 0xffff89e50760>
2024-11-06 12:01:56,611 [INFO] Initialized FastAgency: <FastAgency title=FastAgency application>

╭──────────────────────── Importable FastAgency app ────────────────────────╮
│ │
│ from docs.docs_src.user_guide.runtimes.autogen.whatsapp_tool import app │
│ from docs.docs_src.user_guide.runtimes.ag2.whatsapp_tool import app │
│ │
╰───────────────────────────────────────────────────────────────────────────╯

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
upstream nats_fastapi_backend {
# Enable sticky sessions with IP hash
ip_hash;


}

upstream fastapi_backend {
# Enable sticky sessions with IP hash
ip_hash;


}

upstream mesop_backend {
# Enable sticky sessions with IP hash
ip_hash;
Expand All @@ -32,47 +18,9 @@ map $fly_machine_id $sticky_action {
default "replay"; # Cookie exists but doesn't match - need to replay
}

# Fastapi server block
server {
listen $FASTAPI_PORT;
server_name localhost;

# Security headers
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
add_header X-XSS-Protection "1; mode=block";

location / {
# Handle cookie setting
if ($sticky_action = "set_cookie") {
add_header Set-Cookie "fly-machine-id=$FLY_MACHINE_ID; Max-Age=518400; Path=/";
}

# Handle replay
if ($sticky_action = "replay") {
add_header Fly-Replay "instance=$fly_machine_id";
return 307;
}

proxy_pass http://fastapi_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_buffering off;

# WSGI support
proxy_set_header X-Forwarded-Host $server_name;

# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
# Mesop server block
# Main server block
server {
listen $MESOP_PORT;
listen $SERVICE_PORT;
server_name localhost;

# Security headers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#!/bin/bash

# Accept env variable for PORT
export NATS_FASTAPI_PORT=${NATS_FASTAPI_PORT:-8000}
export FASTAPI_PORT=${FASTAPI_PORT:-8008}


FASTAPI_PORT=${FASTAPI_PORT:-8008}


export MESOP_PORT=${MESOP_PORT:-8888}
export SERVICE_PORT=$MESOP_PORT

# Default number of workers if not set
WORKERS=${WORKERS:-1}
Expand All @@ -16,23 +20,10 @@ echo "Fly machine ID: $FLY_MACHINE_ID"
# Generate nginx config
for ((i=1; i<$WORKERS+1; i++))
do
PORT=$((MESOP_PORT + i))
sed -i "19i\ server 127.0.0.1:$PORT;" nginx.conf.template
done

for ((i=1; i<$WORKERS+1; i++))
do
PORT=$((FASTAPI_PORT + i))
sed -i "12i\ server 127.0.0.1:$PORT;" nginx.conf.template
done

for ((i=1; i<$WORKERS+1; i++))
do
PORT=$((NATS_FASTAPI_PORT + i))
PORT=$((SERVICE_PORT + i))
sed -i "5i\ server 127.0.0.1:$PORT;" nginx.conf.template
done

envsubst '${NATS_FASTAPI_PORT},${FASTAPI_PORT},${MESOP_PORT},${FLY_MACHINE_ID}' < nginx.conf.template >/etc/nginx/conf.d/default.conf
envsubst '${SERVICE_PORT},${FLY_MACHINE_ID}' < nginx.conf.template >/etc/nginx/conf.d/default.conf
echo "Nginx config:"
cat /etc/nginx/conf.d/default.conf

Expand All @@ -41,20 +32,14 @@ nginx -g "daemon off;" &


# Run uvicorn server
# Start multiple single-worker uvicorn instances on consecutive ports
for ((i=1; i<$WORKERS+1; i++))
do
PORT=$((FASTAPI_PORT + i))
echo "Starting fastapi uvicorn on port $PORT"
uvicorn my_fastagency_app.deployment.main_1_fastapi:app --workers=1 --host 0.0.0.0 --port $PORT > /dev/stdout 2>&1 &
done
uvicorn my_fastagency_app.deployment.main_1_fastapi:app --host 0.0.0.0 --port $FASTAPI_PORT > /dev/stdout 2>&1 &


# Run gunicorn server
# Start multiple single-worker gunicorn instances on consecutive ports
for ((i=1; i<$WORKERS+1; i++))
do
PORT=$((MESOP_PORT + i))
PORT=$((SERVICE_PORT + i))
echo "Starting gunicorn on port $PORT"
gunicorn --workers=1 my_fastagency_app.deployment.main_2_mesop:app --bind 0.0.0.0:$PORT > /dev/stdout 2>&1 &
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,3 @@ primary_region = 'ams'
memory = '1gb'
cpu_kind = 'shared'
cpus = 1

[[services]]
http_checks = []
internal_port = 8008
processes = ["app"]
protocol = "tcp"
script_checks = []

[services.concurrency]
type = "connections"

[[services.ports]]
handlers = ["tls", "http"]
port = 8008
[[services]]
http_checks = []
internal_port = 8888
processes = ["app"]
protocol = "tcp"
script_checks = []

[services.concurrency]
type = "connections"

[[services.ports]]
handlers = ["tls", "http"]
port = 8888
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ else
echo -e "\033[0;32mAlready logged into fly.io\033[0m"
fi

export FLY_APP_NAME=$(grep "^app = " fly.toml | awk -F"'" '{print $2}')
export FLY_APP_NAME=my-fastagency-app

echo -e "\033[0;32mRegistering app name in fly.io\033[0m"
if flyctl apps create $FLY_APP_NAME; then
Expand All @@ -27,6 +27,6 @@ if flyctl apps create $FLY_APP_NAME; then
cat registered_app_domain.txt
else
echo -e "\033[1;31mError: App name is not available.\033[0m"
echo -e "\033[1;31mPlease change the app name in fly.toml and run this script again.\033[0m"
echo -e "\033[1;31mPlease change the app name in fly.toml and scripts/register_to_fly_io.sh and run this script again.\033[0m"
exit 1
fi
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
upstream nats_fastapi_backend {
# Enable sticky sessions with IP hash
ip_hash;


}

upstream fastapi_backend {
# Enable sticky sessions with IP hash
ip_hash;


}

upstream mesop_backend {
# Enable sticky sessions with IP hash
ip_hash;
Expand All @@ -32,9 +18,9 @@ map $fly_machine_id $sticky_action {
default "replay"; # Cookie exists but doesn't match - need to replay
}

# Mesop server block
# Main server block
server {
listen $MESOP_PORT;
listen $SERVICE_PORT;
server_name localhost;

# Security headers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/bash

# Accept env variable for PORT
export NATS_FASTAPI_PORT=${NATS_FASTAPI_PORT:-8000}
export FASTAPI_PORT=${FASTAPI_PORT:-8008}



export MESOP_PORT=${MESOP_PORT:-8888}
export SERVICE_PORT=$MESOP_PORT

# Default number of workers if not set
WORKERS=${WORKERS:-1}
Expand All @@ -16,36 +18,26 @@ echo "Fly machine ID: $FLY_MACHINE_ID"
# Generate nginx config
for ((i=1; i<$WORKERS+1; i++))
do
PORT=$((MESOP_PORT + i))
sed -i "19i\ server 127.0.0.1:$PORT;" nginx.conf.template
done

for ((i=1; i<$WORKERS+1; i++))
do
PORT=$((FASTAPI_PORT + i))
sed -i "12i\ server 127.0.0.1:$PORT;" nginx.conf.template
done

for ((i=1; i<$WORKERS+1; i++))
do
PORT=$((NATS_FASTAPI_PORT + i))
PORT=$((SERVICE_PORT + i))
sed -i "5i\ server 127.0.0.1:$PORT;" nginx.conf.template
done

envsubst '${NATS_FASTAPI_PORT},${FASTAPI_PORT},${MESOP_PORT},${FLY_MACHINE_ID}' < nginx.conf.template >/etc/nginx/conf.d/default.conf
envsubst '${SERVICE_PORT},${FLY_MACHINE_ID}' < nginx.conf.template >/etc/nginx/conf.d/default.conf
echo "Nginx config:"
cat /etc/nginx/conf.d/default.conf

# Start nginx
nginx -g "daemon off;" &


# Run uvicorn server
uvicorn my_fastagency_app.deployment.main_:app --host 0.0.0.0 --port $FASTAPI_PORT > /dev/stdout 2>&1 &


# Run gunicorn server
# Start multiple single-worker gunicorn instances on consecutive ports
for ((i=1; i<$WORKERS+1; i++))
do
PORT=$((MESOP_PORT + i))
PORT=$((SERVICE_PORT + i))
echo "Starting gunicorn on port $PORT"
gunicorn --workers=1 my_fastagency_app.deployment.main:app --bind 0.0.0.0:$PORT > /dev/stdout 2>&1 &
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,3 @@ primary_region = 'ams'
memory = '1gb'
cpu_kind = 'shared'
cpus = 1

[[services]]
http_checks = []
internal_port = 8888
processes = ["app"]
protocol = "tcp"
script_checks = []

[services.concurrency]
type = "connections"

[[services.ports]]
handlers = ["tls", "http"]
port = 8888
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ else
echo -e "\033[0;32mAlready logged into fly.io\033[0m"
fi

export FLY_APP_NAME=$(grep "^app = " fly.toml | awk -F"'" '{print $2}')
export FLY_APP_NAME=my-fastagency-app

echo -e "\033[0;32mRegistering app name in fly.io\033[0m"
if flyctl apps create $FLY_APP_NAME; then
Expand All @@ -27,6 +27,6 @@ if flyctl apps create $FLY_APP_NAME; then
cat registered_app_domain.txt
else
echo -e "\033[1;31mError: App name is not available.\033[0m"
echo -e "\033[1;31mPlease change the app name in fly.toml and run this script again.\033[0m"
echo -e "\033[1;31mPlease change the app name in fly.toml and scripts/register_to_fly_io.sh and run this script again.\033[0m"
exit 1
fi
Loading

0 comments on commit 76c0a0e

Please sign in to comment.