2.4.3 Web_Server¶
Web Server¶
AgentUniverse provides a web server based on Gunicorn+Flask. You can call the developed Agent services through the preset APIs in the web server.
Web Server Launch¶
You need to start the web server after launching the AgentUniverse application. Here is an example of how to launch it:
from agentuniverse.agent_serve.web.web_booster import start_web_server
from agentuniverse.base.agentuniverse import AgentUniverse
AgentUniverse().start()
start_web_server()
Windows Users¶
If you are using AgentUniverse on Windows, due to Gunicorn compatibility issues, AgentUniverse will run the Flask program directly. You can modify the start port in start_web_server, like this::
from agentuniverse.agent_serve.web.web_booster import start_web_server
start_web_server(bind='127.0.0.1:8888')
Web Server Configuration¶
The configuration of the web server consists of four levels in order of increasing priority: native Gunicorn default configuration, AgentUniverse default configuration, configuration file settings, and startup configuration. For Gunicorn's native default configuration, please refer to the official documentation for the corresponding version of Gunicorn.
AgentUniverse Default Configuration¶
DEFAULT_GUNICORN_CONFIG = {
'bind': '127.0.0.1:8000',
'workers': 5,
'backlog': 2048,
'worker_class': 'gthread',
'threads': 4,
'timeout': 60,
'keepalive': 10
}
Configuration File Path¶
The configuration path for the web server is specified in AgentUniverse's main configuration file config.toml.
[SUB_CONFIG_PATH]
# Gunicorn config file path, an absolute path or a relative path based on the dir where the current config file is located.
gunicorn_config_path = './gunicorn_config.toml'
Configuration File¶
[GUNICORN_CONFIG]
bind = '127.0.0.1:8000'
backlog = 2048
worker_class = 'gthread'
threads = 4
workers = 5
timeout = 60
keepalive = 10
Startup Configuration¶
You can also configure the web server at startup as follows: