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
Optional[Any]

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

context
Optional[Any]

Serverless context object (Lambda context, etc.).

force_mode
Optional[str]

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
Optional[str]

Host override for server mode.

port
Optional[int]

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

1from signalwire import AgentBase
2
3agent = AgentBase(name="my-agent", route="/agent")
4agent.set_prompt_text("You are a helpful assistant.")
5
6if __name__ == "__main__":
7 agent.run()

AWS Lambda handler

1from signalwire import AgentBase
2
3agent = AgentBase(name="lambda-agent")
4agent.set_prompt_text("You are a helpful assistant.")
5
6def handler(event, context):
7 return agent.run(event=event, context=context)

Google Cloud Function

1from signalwire import AgentBase
2
3agent = AgentBase(name="gcf-agent")
4agent.set_prompt_text("You are a helpful assistant.")
5
6def main(request):
7 return agent.run(event=request)