***

title: run
slug: /reference/python/agents/agent-server/run
description: Start the multi-agent server with automatic environment detection.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

Universal entry point that detects the execution environment and starts the server
accordingly. In standard server mode it launches uvicorn; in serverless environments
(AWS Lambda, CGI) it processes the incoming request and returns a response.

<Note>
  This method blocks in server mode. For production deployments behind gunicorn or
  another ASGI server, use `server.app` directly instead of calling `run()`.
</Note>

## **Parameters**

<ParamField path="event" type="Optional[Any]" toc={true}>
  Serverless event object (AWS Lambda, Google Cloud Functions). Pass the Lambda handler's
  `event` parameter here. Ignored in server mode.
</ParamField>

<ParamField path="context" type="Optional[Any]" toc={true}>
  Serverless context object (AWS Lambda, Google Cloud Functions). Pass the Lambda handler's
  `context` parameter here. Ignored in server mode.
</ParamField>

<ParamField path="host" type="Optional[str]" toc={true}>
  Override the host set in the constructor. Only applies in server mode.
</ParamField>

<ParamField path="port" type="Optional[int]" toc={true}>
  Override the port set in the constructor. Only applies in server mode.
</ParamField>

## **Returns**

`None` in server mode (blocks until shutdown). In Lambda mode, returns a response `dict`
with `statusCode`, `headers`, and `body`. In CGI mode, returns the formatted response string.

## **Examples**

### Server Mode

```python {9}
from signalwire import AgentServer
from signalwire import AgentBase

agent = AgentBase(name="my-agent", route="/agent")
agent.set_prompt_text("You are a helpful assistant.")

server = AgentServer(host="0.0.0.0", port=3000)
server.register(agent)
server.run()
```

### AWS Lambda

```python {11}
from signalwire import AgentServer
from signalwire import AgentBase

agent = AgentBase(name="my-agent", route="/agent")
agent.set_prompt_text("You are a helpful assistant.")

server = AgentServer()
server.register(agent)

def lambda_handler(event, context):
    return server.run(event, context)
```

### Gunicorn (external ASGI server)

```python {12}
from signalwire import AgentServer
from signalwire import AgentBase

agent = AgentBase(name="my-agent", route="/agent")
agent.set_prompt_text("You are a helpful assistant.")

server = AgentServer()
server.register(agent)

# Expose the FastAPI app for gunicorn:
# gunicorn app:app -k uvicorn.workers.UvicornWorker
app = server.app
```

<Tip>
  If `SWML_SSL_ENABLED` is set to `true` in the environment along with `SWML_SSL_CERT_PATH`
  and `SWML_SSL_KEY_PATH`, the server starts with HTTPS automatically.
</Tip>