T
traeai
Sign in
返回首页
AWS Machine Learning Blog

From idea to AI app: Creating intelligent research assistants with Strands

7.8Score
From idea to AI app: Creating intelligent research assistants with Strands

TL;DR · AI Summary

By using Strands Agents and AWS services, the author built a fully functional AI research assistant in just 30 lines of code, simplifying the process of developing AI applications.

Key Takeaways

  • Using Strands Agents and AWS services allows you to build a fully functional AI
  • Strands Agents provide a simple way to create intelligent agents capable of perf
  • The framework supports everything from single agents to multi-agent networks and

Outline

Jump quickly between sections.

  1. Introduce the challenges faced when building AI applications and the solution.

  2. ·AWS Options

    Introduce multiple options provided by AWS for building agentic AI applications.

  3. Describe the features and extension capabilities of Kiro.

  4. Detail the features and advantages of Strands Agents.

  5. Explain how Strands Agents simplify AI development in AWS environments.

  6. List prerequisites needed before diving into the solution.

Mindmap

See how the topics connect at a glance.

查看大纲文本(无障碍 / 无 JS 友好)
  • 从想法到 AI 应用:使用 Strands 创建智能研究助手
    • AWS 选项
      • Amazon Bedrock
      • Kiro
      • Strands Agents
    • 为什么选择 Strands Agents
      • 简化 AI 开发
      • 灵活的架构
      • 生产就绪
    • 先决条件
      • AWS 账户
      • 用户配置
      • 安装 Kiro
      • 配置 AWS 凭证

Highlights

Key sentences worth saving and sharing.

  • Through the use of Strands Agents and AWS services, the author built a fully functional AI research assistant in just 30 lines of code.

    Paragraph 2

    ⬇︎ 下载 PNG𝕏 分享到 X
  • Strands Agents provide a simple way to create intelligent agents capable of performing tasks such as research, analysis, and content generation.

    Paragraph 4

    ⬇︎ 下载 PNG𝕏 分享到 X
  • The framework supports everything from single agents to multi-agent networks and hierarchical systems, making it suitable for projects of various scales.

    Paragraph 4

    ⬇︎ 下载 PNG𝕏 分享到 X
#Strands Agents#AWS#AI Application Development
Open original article

Building an AI app shouldn't require a PhD in machine learning (ML) or months of wrestling with complex architectures. Yet that's exactly what happens when you try to orchestrate multiple API calls, manage conversation state, and create agents that can reason on their own. I've seen straightforward AI ideas balloon into sprawling projects that demand specialized knowledge in natural language processing and distributed systems. But here's what changed: using Strands Agents and AWS services, I built a fully functional AI research assistant in just 30 lines of code. In this post, I walk you through exactly how I did it—from initial concept to working application.

Amazon Web Services (AWS) offers multiple options for building agentic AI applications. Amazon Bedrock provides access to foundation models (FMs) that can power intelligent agents, while services like Kiro enable developer-focused AI assistance directly within the IDE. You can use these tools to create custom AI agents tailored to specific use cases and domains.

Kiro is an AI-powered IDE that writes code so developers can focus on decisions. Kiro Powers extend the Kiro IDE with specialized, on-demand capabilities by packaging MCP servers, steering files, and hooks into reusable units. The Strands power, for example, bundles SDK documentation search, getting started guides, and correct API patterns so Kiro can scaffold agents accurately. With over 50 curated powers from AWS, partners, and the community—covering design, deployment, security, and observability—developers install with one click and start building immediately.

Strands Agents is an open source framework that directly addresses these development challenges by providing a straightforward way to create intelligent agents that can perform tasks like research, analysis, and content generation. Strands Agents combine the capabilities of large language models (LLMs) with custom logic and APIs through Python code. For more information about Strands Agents, see Introducing Strands Agents, an Open Source AI Agents Software Development Kit (SDK).

Why Choose Strands Agents: Simplified AI Development for AWS Environments

Strands Agents addresses the core challenges you face when building AI applications through its model-driven approach. Instead of complex hardcoding, it uses LLMs for autonomous reasoning and planning, so you can create agents with only a prompt and tools list while the LLM handles the logic and tool usage.

The framework's flexible architecture supports everything from single agents to multi-agent networks and hierarchical systems, making it suitable for projects of various scales. You can integrate external functions and APIs through the @tool decorator, while the model-agnostic design works with various LLM providers including Amazon Bedrock, Anthropic, and OpenAI.

For AWS environments, Strands integrates naturally with services like Amazon Bedrock and AWS Lambda, and it's already production-ready. AWS teams use it in services like Amazon Q and AWS Glue. The open source framework is Apache-2.0 licensed with active community contributions, and the same code runs smoothly in both local development and production environments. Real-time streaming responses make it a good fit for interactive applications that need immediate feedback.

For more information about the technical deep dive, see Strands Agents SDK: A Technical Deep Dive into Agent Architectures and Observability.

Prerequisites

Before you dive into the solution, make sure that you have the following in place:

  • An AWS account.
  • A user configured in AWS IAM Identity Center or Builder ID.
  • Install Kiro.
  • Configure AWS credentials to access Amazon Bedrock — Set up authentication using AWS IAM Identity Center (the recommended approach for human access). Run the following commands to configure and log in:
code
aws configure sso

aws sso login --profile research-assistant

Code

  • Next, attach a scoped inline AWS Identity and Access Management (IAM) policy to the role or permission set that you use. This policy grants only the necessary permissions for this tutorial—invoking the Claude Sonnet model through Amazon Bedrock.
code
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "bedrock:InvokeModel",
        "bedrock:Converse"
      ],
      "Resource": "arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-5-sonnet-20241022-v2:0"
    }
  ]
}

YAML

Image 1

Solution Overview

Building an Intelligent Research Assistant

This section demonstrates how Strands Agents simplify the development of agentic AI capabilities. Our example research assistant illustrates how you can easily integrate intelligent features into your applications with minimal code. You begin by creating an agent using the Agent() initialization, then define the agent's behavior through prompt engineering. Next, you add autonomous research capabilities by providing tools and processing responses for clean output.

The solution requires only 30 lines of code, showcasing how Strands can reduce AI development complexity into straightforward implementation. Although we use Streamlit for visualization, the core functionality lies in Strands' ability to handle autonomous reasoning, tool selection, and task execution with minimal intervention from you.

Getting Started with Strands Agents:

You'll start by building a simple Q&A-style research assistant using Strands Agents. In your IDE, install the Strands Agents SDK:

Kiro -> Terminal

pip install strands-agents

Code

We also need Streamlit for our research assistant, so use the following command to install Streamlit:

pip install streamlit

Code

Next, create your first agent as a Python file. Let's name it research.py.

code
from strands import Agent

# Create an agent with default settings
agent = Agent()

# Ask the agent a question
agent("Tell me about agentic AI")

Python

Image 2

That's it. You've just created your first AI agent. Now, let's see what it can do when you run it.

In your terminal, run the following command:

python -u research.py

Code

With this foundation laid, let's enhance our implementation by using prompt engineering to create a more advanced research assistant. We'll build a web interface using Streamlit that allows dynamic topic input and provides comprehensive research reports powered by Strands Agents.

AI-Assisted Development with Kiro: Generating Our Research Assistant Implementation

Let's speed up our development process by leveraging Kiro to generate our research assistant code through natural language prompting and conversation. We'll describe our requirements in natural language, and Kiro can help us create a functional research assistant application using Strands Agents and Streamlit.

Follow these steps:

  1. Open Kiro.
  2. Create a new Python file (e.g., research_assistant.py).
  3. Provide the following prompt:
code
Create a Streamlit research assistant app using the strands Agent library with these exact requirements:

1. App title: "Research Assistant" with subtitle "Enter a topic to get research analysis and recommendations"
2. Text input field with placeholder "e.g., renewable energy, artificial intelligence" 
3. "Generate Research Report" button that when clicked:
   - Shows spinner with "Researching and analyzing..." message
   - Redirects stdout to prevent terminal output interference (import sys, os, and use devnull)
   - Creates Agent() instance
   - Uses this exact prompt template: "You are a research assistant. For the topic '{topic}': 1. Overview of the topic in about 50 words 2. Find recent 2 articles about {topic} in 20 words each 3. Things to know relevant to the topic and description as prerequisites in 20 words each like if topic is agentic ai then prereq is machine learning and generative ai 4. 2 key contributors and well known people in this field of research topic including their bio in 25 words each 5. Give relevant 2 urls to read more and any research papers from https://arxiv.org/"
   - Displays response using st.subheader(f"Research Report: {topic}") and st.write(response.message['content'][0]['text'])
   - Restores stdout in the finally block
   - Shows warning if no topic is entered

Use try/finally pattern for stdout redirection. Keep the code minimal and functional.

Python

Kiro will generate the complete implementation, which we can then save and run.

Here is the code generated by Kiro.

code
import sys
import os
import streamlit as st
from strands import Agent

st.title("Research Assistant")
st.write("Enter a topic to get research analysis and recommendations")

topic = st.text_input("Research Topic", placeholder="e.g., renewable energy, artificial intelligence")

if st.button("Generate Research Report"):
    if topic:
        with st.spinner("Researching and analyzing..."):
            old_stdout = sys.stdout
            try:
                sys.stdout = open(os.devnull, "w")
                agent = Agent()
                response = agent(
                    f"You are a research assistant. For the topic '{topic}': "
                    f"1. Overview of the topic in about 50 words "
                    f"2. Find recent 2 articles about {topic} in 20 words each "
                    f"3. Things to know relevant to the topic and description as prerequisites in 20 words each "
                    f"like if topic is agentic ai then prereq is machine learning and generative ai "
                    f"4. 2 key contributors and well known people in this field of research topic including their bio in 25 words each "
                    f"5. Give relevant 2 urls to read more and any research papers from https://arxiv.org/"
                )
            finally:
                sys.stdout = old_stdout

            st.subheader(f"Research Report: {topic}")
            st.write(response.message["content"][0]["text"])
    else:
        st.warning("Please enter a topic to research.")

Python

Note: Without a web-browsing tool, the agent generates URLs based on its training knowledge. These may not reflect the latest papers. _For live retrieval, add an appropriate MCP server as a tool_.

Responsible Selection of MCP Servers

  • 固定 MCP 服务器的版本或提交哈希(例如,pip install "arxiv-mcp==X.Y.Z")。
  • 在安装之前,请审阅源代码。我推荐使用 Amazon Bedrock 原生检索(知识库/RAG)用于生产环境。
  • 对于面向客户的部署或跨组织部署,通过您的组织的法律和安全审查流程路由第三方 MCP 服务器。
  • MCP 服务器共享代理进程的权限,包括进程中可用的任何 AWS 凭证。将其视为您信任边界的组成部分。

_对于生产工作负载,考虑使用AWS 管理的远程 MCP 服务器通过 Amazon Bedrock AgentCore,这些服务器提供进程隔离、集中式身份验证,并消除本地凭证暴露。_

生产安全性注意事项

  • 验证用户输入。 在将字符串传递给代理之前,限制主题长度并剥离不可打印字符(参见本文中的代码)。
  • 启用 Amazon Bedrock Guardrails。 将一个 guardrail 附加到模型调用以防止提示注入和不安全输出过滤。有关更多信息,请参阅 使用 Amazon Bedrock Guardrails 检测和过滤有害内容
  • 开启日志记录。 启用 Amazon Bedrock 模型调用日志和 AWS CloudTrail 数据事件在 bedrock:InvokeModelbedrock:Converse 上,以便您可以归因于误用并重建事件。
  • 控制成本。 设置 Amazon Bedrock 按需配额警报和每会话查询上限,以防止主题泛滥/成本耗尽。
  • 分类持久化数据。 如果您存储了对话历史记录,在写入之前对数据进行分类并删除敏感值。
  • 审查共同责任模型。 请参阅 AWS 共同责任模型 了解 AWS 管理和您拥有的内容之间的划分。

如果您想更好地理解代码,可以问 Kiro _Can you explain code in context?_

Image 3

Kiro 如下回应:

Image 4

在初始开发过程中,代理的输出在 Streamlit 接口中正确流式传输,但也会出现在终端中,导致突然截断。虽然这不影响应用程序的功能,但在开发环境中创建了不必要的噪音。通过进一步与 Kiro 的交流,我改进了代码,包含标准输出重定向,以验证代理的响应仅显示在预期界面中。

这展示了使用 Kiro 编码的一个关键优势——通过自然语言反馈迭代改进实现。当遇到此类边缘情况时,您可以描述所需行为,Kiro 将帮助相应地修改代码——例如,尝试询问 Kiro 添加空或格式错误代理响应的错误处理。

现在让我们看看我们改进的应用程序的运行情况。

让您的代理活起来

在终端中,导航到保存 research_assistant.py 文件的目录并运行以下命令:

streamlit run research_assistant.py

代码

这将启动 Streamlit 应用。

注意: 默认情况下,streamlit run 绑定到 127.0.0.1,因此 UI 只能从该机器访问。不要在没有添加身份验证、CSRF 保护和 Amazon Bedrock 成本上限的情况下将其暴露到 LAN(–server.address=0.0.0.0)或互联网上。浏览器 DNS 重新绑定到本地主机是一个已知的本地开发者工具问题。考虑使用 Streamlit 内置的身份验证或通过经过身份验证的大门反向代理来供任何共享使用。

在运行上述命令后,您将看到以下提示。您可以选择将电子邮件留为空白。

_欢迎使用 Streamlit!_

_如果您希望接收有用的入门邮件、新闻、优惠、促销和偶尔的礼品,请在此下方输入您的电子邮件地址。否则,请将此字段留空白。_

_电子邮件:_

接下来,您将获得打开 Streamlit 应用的链接。

Image 5
Image 6

您可以输入感兴趣的主题并选择 生成研究报告。

Image 7

这将生成如下研究报告:

Image 8

如果您想获取不同的报告或其他详细信息,可以在有文件上下文时让 Kiro 修改代码,或者您可以自行修改代码。

结论

在这篇文章中,我们探讨了如何使用 Strands Agents 加速代理人工智能应用的开发。通过结合 Strands 的模型驱动方法和 Kiro 的代码生成能力,我演示了如何通过最少的代码构建复杂的 AI 特性。

Our exploration shows that Strands Agents can reduce complex AI development through intuitive agent creation, while Kiro can enhance your productivity through AI-assisted coding. The resulting applications are both powerful and maintainable, and you can quickly make custom modifications through prompt engineering. As AI continues to evolve, tools like Strands Agents and Kiro are making it increasingly accessible for you to create intelligent, autonomous applications that can enhance your specific use cases and workflows.

License & Disclaimer

The example code in this post is licensed under MIT-0. This post and its code are provided as-is without warranty; readers are responsible for the security, cost, and operational posture of any system they deploy based on this guidance.

Considerations Before Using in Production

  • Cost — Each research query consumes Amazon Bedrock tokens; set a quota alarm and a per-session query cap before exposing this app beyond a single user.
  • Data — Research topics and the model's output are sent to a foundation model; do not submit confidential or regulated data without appropriate controls.
  • Operational — The tutorial ships with no audit trail, no input validation, and no authentication on the Streamlit UI. See the _Security Considerations for Production_ section above before reusing this pattern.
  • * *

About the Author

AI may generate inaccurate information. Please verify important content.