sagemaker.train.custom_agent_lambda

sagemaker.train.custom_agent_lambda#

CustomAgentLambda — Lambda-based agent environment for Agentic RFT.

Classes

CustomAgentLambda(lambda_arn)

Lambda-based agent environment for Agentic RFT.

class sagemaker.train.custom_agent_lambda.CustomAgentLambda(lambda_arn: str)[source]#

Bases: object

Lambda-based agent environment for Agentic RFT.

Creates and wraps Lambda functions that serve as agent environments or bridges between SageMaker and custom agent environments (e.g., LangSmith, EKS, Fargate).

Parameters:

lambda_arn – ARN of the Lambda function.

classmethod create(source: str, function_name: str | None = None, role: str | None = None, runtime: str = 'python3.12', handler: str = 'lambda_function.handler', timeout: int = 900, memory_size: int = 256, environment: dict | None = None, sagemaker_session=None) CustomAgentLambda[source]#

Create a new Lambda function and return an CustomAgentLambda.

The source parameter accepts three formats:

  • S3 URI (s3://bucket/key.zip): deploys from an S3 artifact.

  • Local file path: reads the file, packages it as a zip, and uploads.

  • Inline code string: packages the raw code as a zip and uploads.

Detection order: S3 URI → existing local path → inline code.

Parameters:
  • source – S3 URI, local file path, or inline Python code string.

  • function_name – Lambda function name. If not provided, a unique name is generated automatically.

  • role – IAM role ARN for the Lambda execution role.

  • runtime – Lambda runtime (default: "python3.12").

  • handler – Lambda handler (default: "lambda_function.handler").

  • timeout – Lambda timeout in seconds (default: 900).

  • memory_size – Lambda memory in MB (default: 256).

  • environment – Dict of environment variables for the Lambda.

  • sagemaker_session – Optional SageMaker session for role resolution.

Returns:

CustomAgentLambda wrapping the created Lambda ARN.

Raises:

ValueError – If source is empty.

classmethod get(lambda_arn: str) CustomAgentLambda[source]#

Wrap an existing Lambda ARN.

Validates the Lambda exists by calling GetFunction.

Parameters:

lambda_arn – ARN of an existing Lambda function.

Returns:

CustomAgentLambda wrapping the Lambda ARN.

Raises:

botocore.exceptions.ClientError – If the Lambda does not exist.