AWS Machine Learning Blog 08月22日
Inline code nodes now supported in Amazon Bedrock Flows in public preview
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

Amazon Bedrock Flows现已推出内联代码节点公测版,允许用户直接在工作流中编写Python脚本,无需单独的AWS Lambda函数即可处理简单逻辑,如数据预处理和响应格式化。此功能极大地简化了生成式AI应用的开发流程,降低了企业采用门槛和维护成本,加速了AI解决方案的落地。用户可以通过API或AWS管理控制台创建和管理代码,同时支持OpenCV、SciPy等流行Python包,并提供节点执行追踪功能,提升了开发效率和可观测性。

💡 **简化工作流管理与开发**:内联代码节点允许开发者直接在Amazon Bedrock Flows中编写Python脚本,无需创建和维护独立的AWS Lambda函数,显著减少了管理复杂工作流的运维开销,尤其适用于大规模用户和流程场景,使开发流程更加聚焦于AI应用逻辑本身。

⚙️ **灵活的数据处理能力**:该功能支持在调用大型语言模型(LLM)之前进行数据预处理(如提取JSON字段、格式化文本、值归一化),以及在模型输出后进行后处理(如提取实体、格式化下游系统所需JSON、应用业务规则)。这使得数据转换和模型结果的适配更加直接和高效。

🚀 **支持复杂用例与常用库**:内联代码节点能够处理多步骤的复杂生成式AI工作流,并支持调用如OpenCV、SciPy、pypdf等流行的Python库,为开发者提供了更强大的工具集来构建功能丰富的AI应用,满足更广泛的业务需求。

🔧 **开发者友好的创建与管理**:用户可以通过Amazon Bedrock API和AWS管理控制台轻松创建和管理内联代码节点,提供直观的Python代码编辑器和示例代码模板,降低了使用门槛,使得即使不熟悉底层基础设施的用户也能自行构建复杂的AI工作流。

👁️ **增强的可观测性**:为提供无缝的用户体验,内联代码节点支持追踪每个节点的输入和输出,用户可以通过API启用追踪功能并发送至Amazon CloudWatch日志,从而深入了解每个处理步骤的细节,便于调试和性能优化。

Today, we are excited to announce the public preview of support for inline code nodes in Amazon Bedrock Flows. With this powerful new capability, you can write Python scripts directly within your workflow, alleviating the need for separate AWS Lambda functions for simple logic. This feature streamlines preprocessing and postprocessing tasks (like data normalization and response formatting), simplifying generative AI application development and making it more accessible across organizations. By removing adoption barriers and reducing maintenance overhead, the inline code feature accelerates enterprise adoption of generative AI solutions, resulting in faster iteration cycles and broader participation in AI application building.

Organizations using Amazon Bedrock Flows now can use inline code nodes to design and deploy workflows for building more scalable and efficient generative AI applications fully within the Amazon Bedrock environment while achieving the following:

In this post, we discuss the benefits of this new feature, and show how to use inline code nodes in Amazon Bedrock Flows.

Benefits of inline code in Amazon Bedrock Flows

Thomson Reuters, a global information services company providing essential news, insights, and technology solutions to professionals across legal, tax, accounting, media, and corporate sectors, handles complex, multi-step generative AI use cases that require simple preprocessing and postprocessing as part of the workflow. With the inline code feature in Amazon Bedrock Flows, Thomson Reuters can now benefit from the following:

Solution overview

In the following sections, we show how to create a simple Amazon Bedrock flow and add inline code nodes. Our example showcases a practical application where we’ll construct a flow that processes user requests for music playlists, incorporating both preprocessing and postprocessing inline code nodes to handle data validation and response formatting.

Prerequisites

Before implementing the new capabilities, make sure you have the following:

After these components are in place, you can proceed with using Amazon Bedrock Flows with inline code capabilities in your generative AI use case.

Create your flow using inline code nodes

Complete the following steps to create your flow:

    On the Amazon Bedrock console, choose Flows under Builder tools in the navigation pane. Create a new flow, for example, easy-inline-code-flow. For detailed instructions on creating a flow, see Amazon Bedrock Flows is now generally available with enhanced safety and traceability. Add an inline code node. (For this example, we create two nodes for two separate prompts).

Amazon Bedrock provides different node types to build your prompt flow. For this example, we use an inline code node instead of calling a Lambda function for custom code for a generative AI-powered application. There are two inline code nodes in the flow. We have extended the sample from the documentation Create a flow with a single prompt. The new node type Inline Code is on the Nodes tab in the left pane.

    Add some code to process in the Preprocessing_InlineCode node before sending it to the prompt node prompt_1. Python 3 is only supported at the time of writing. In this example, we check if the number of songs requested by the user is more than 10 and it’s set to 10.

There is a Python code editor and sample code templates as well for writing the code.

We use the following code:

import jsondef __func():    try:        if userprompt['number'] > 10:            userprompt['number']=10            return userprompt        else:            return userprompt                except Exception as e:        return {            "error": "Invalid input format",            "details": str(e)        }__func()
    In the Postprocessing_Inline Code node, we check the number of words in the response and feed the data to the next prompt node, prompt_2.

def __func():    # Remove extra whitespace and count    cleaned_text = ' '.join(playlist.split())    word_count = len(cleaned_text.split())    return{        "playlist": playlist,     "word_count": word_count    }__func()
    Test the flow with the following prompt:
Sample input for the Flow Input node {  "genre": "pop",    "number": 8  }

Input to the inline code node (Python function) must be treated as untrusted user input, and appropriate parsing, validation, and data handling should be implemented.

You can see the output as shown in the following screenshot. The system also provides access to node execution traces, offering detailed insights into each processing step, real-time performance metrics, and highlighting any issues that occurred during the flow’s execution. Traces can be enabled using an API and sent to an Amazon CloudWatch log. In the API, set the enableTrace field to true in an InvokeFlow request. Each flowOutputEvent in the response is returned alongside a flowTraceEvent.

You have now successfully created and executed an Amazon Bedrock flows using inline code nodes. You can also use Amazon Bedrock APIs to programmatically execute this flow. For additional details on how to configure flows with enhanced safety and traceability, see Amazon Bedrock Flows is now generally available with enhanced safety and traceability.

Considerations

When working with inline code nodes in Amazon Bedrock Flows, the following are the important things to note:

Conclusion

The integration of inline code nodes in Amazon Bedrock Flows marks a significant advancement in democratizing generative AI development, reducing the complexity of managing separate Lambda functions for basic processing tasks. This enhancement responds directly to enterprise customers’ needs for a more streamlined development experience, helping developers focus on building sophisticated AI workflows rather than managing infrastructure.

Inline code in Amazon Bedrock Flows is now available in public preview in the following AWS Regions: US East (N. Virginia, Ohio), US West (Oregon) and Europe (Frankfurt). To get started, open the Amazon Bedrock console or Amazon Bedrock APIs to begin building flows with Amazon Bedrock Flows. To learn more, refer to Create your first flow in Amazon Bedrock and Track each step in your flow by viewing its trace in Amazon Bedrock.

We’re excited to see the innovative applications you will build with these new capabilities. As always, we welcome your feedback through AWS re:Post for Amazon Bedrock or your usual AWS contacts. Join the generative AI builder community at community.aws to share your experiences and learn from others.


About the authors

Shubhankar Sumar is a Senior Solutions Architect at AWS, where he specializes in architecting generative AI-powered solutions for enterprise software and SaaS companies across the UK. With a strong background in software engineering, Shubhankar excels at designing secure, scalable, and cost-effective multi-tenant systems on the cloud. His expertise lies in seamlessly integrating cutting-edge generative AI capabilities into existing SaaS applications, helping customers stay at the forefront of technological innovation.

Jesse Manders is a Senior Product Manager on Amazon Bedrock, the AWS Generative AI developer service. He works at the intersection of AI and human interaction with the goal of creating and improving generative AI products and services to meet our needs. Previously, Jesse held engineering team leadership roles at Apple and Lumileds, and was a senior scientist in a Silicon Valley startup. He has an M.S. and Ph.D. from the University of Florida, and an MBA from the University of California, Berkeley, Haas School of Business.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Amazon Bedrock Flows 内联代码 生成式AI Python脚本 工作流自动化
相关文章