***

title: run
slug: /reference/python/agents/agent-base/run
description: Smart entry point that auto-detects the runtime environment and starts the agent accordingly.
max-toc-depth: 3
---------------------

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

[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].

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

## **Parameters**

<ParamField path="event" type="Optional[Any]" toc={true}>
  Serverless event object. Pass the Lambda event, Cloud Functions request, or
  Azure Functions HttpRequest here.
</ParamField>

<ParamField path="context" type="Optional[Any]" toc={true}>
  Serverless context object (Lambda context, etc.).
</ParamField>

<ParamField path="force_mode" type="Optional[str]" toc={true}>
  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
</ParamField>

<ParamField path="host" type="Optional[str]" toc={true}>
  Host override for server mode.
</ParamField>

<ParamField path="port" type="Optional[int]" toc={true}>
  Port override for server mode.
</ParamField>

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