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

# run

> Start the multi-agent server with automatic environment detection.

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.

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

## **Parameters**

**`event`** `Optional[Any]`

Serverless event object (AWS Lambda, Google Cloud Functions). Pass the Lambda handler's
`event` parameter here. Ignored in server mode.

---

**`context`** `Optional[Any]`

Serverless context object (AWS Lambda, Google Cloud Functions). Pass the Lambda handler's
`context` parameter here. Ignored in server mode.

---

**`host`** `Optional[str]`

Override the host set in the constructor. Only applies in server mode.

---

**`port`** `Optional[int]`

Override the port set in the constructor. Only applies in server mode.

---

## **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
```

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.