AgentsAgentBase

run

View as MarkdownOpen in Claude

Universal entry point that automatically detects the execution environment and starts the agent in the appropriate mode. In server environments it calls serve(). In serverless environments (Lambda, Cloud Functions, Azure Functions, CGI) it delegates to 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

event
dict[str, Any] | NoneDefaults to None

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

context
AnyDefaults to None

Serverless context object (Lambda context, etc.).

force_mode
str | NoneDefaults to None

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
str | NoneDefaults to None

Host override for server mode.

port
int | NoneDefaults to None

Port override for server mode.

Returns

str | dict[str, Any] | None — In serverless modes, returns the platform-specific response object: a str in CGI mode, a dict otherwise. In server mode, blocks until shutdown and returns None.

Examples

Standard entry point

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

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

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)