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

# run

> Smart entry point that auto-detects the runtime environment and starts the agent accordingly.

[serve]: /docs/server-sdks/reference/python/agents/agent-base/serve

[handle-serverless-request]: /docs/server-sdks/reference/python/agents/agent-base/serverless

Universal entry point that automatically detects the execution environment and starts
the agent in the appropriate mode. In server environments it calls
[`serve()`][serve]. In serverless
environments (Lambda, Cloud Functions, Azure Functions, CGI) it delegates to
[`handle_serverless_request()`][handle-serverless-request].

Use `run()` as your default entry point. It makes your agent code portable across
development, Docker, and serverless deployments without changes.

## **Parameters**

Serverless event object. Pass the Lambda event, Cloud Functions request, or
Azure Functions HttpRequest here.

Serverless context object (Lambda context, etc.).

Override automatic environment detection. Valid values:

* `"server"` -- Force web server mode
* `"lambda"` -- Force AWS Lambda mode
* `"cgi"` -- Force CGI mode
* `"google_cloud_function"` -- Force Google Cloud Functions mode
* `"azure_function"` -- Force Azure Functions mode

Host override for server mode.

Port override for server mode.

## **Returns**

`Optional[dict]` -- In serverless modes, returns the platform-specific response object.
In server mode, blocks until shutdown and returns `None`.

## **Examples**

### Standard entry point

```python {7}
from signalwire import AgentBase

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

if __name__ == "__main__":
    agent.run()
```

### AWS Lambda handler

```python {7}
from signalwire import AgentBase

agent = AgentBase(name="lambda-agent")
agent.set_prompt_text("You are a helpful assistant.")

def handler(event, context):
    return agent.run(event=event, context=context)
```

### Google Cloud Function

```python {7}
from signalwire import AgentBase

agent = AgentBase(name="gcf-agent")
agent.set_prompt_text("You are a helpful assistant.")

def main(request):
    return agent.run(event=request)
```