近期,亚马逊云科技宣布推出Strands Agents SDK 1.0版本。这标志着亚马逊云科技,在推动AI Agents构建流程更简单、成果更可靠且可落地生产应用的道路上,向前迈出了重要一步。
Strands Agents是一款开源的SDK,采用模型驱动的方法,仅需几行代码即可构建并运行AI Agents。无论是简单还是复杂的Agent应用场景,Strands Agents都具备适用性,且支持从本地开发到生产环境部署的全流程。
自2025年5月发布Strands Agents SDK预览版以来,其在GitHub上已收获超过2000点赞,在PyPI上的下载量也突破了15万次。Strands Agents 1.0为多Agents应用提供了与单Agent应用同等的简便性,同时新增四种基础组件,并支持Agent to Agent(A2A)协议。
为了将多Agents架构投入生产应用,Strands Agents SDK 1.0版本还引入了全新的会话管理器,可从远程数据存储中检索Agen状态,并在整个SDK中改进了异步支持。
同时,为方便用户灵活使用任意模型构建Agent,亚马逊云科技联合Anthropic、Meta等合作伙伴,新增了对五个主流模型提供商API的兼容支持。
本文将详细介绍这些更新内容,完整的代码示例可在strandsagents.com上获取。
简化多Agents协作模式
多Agents协作模式能让各具专长的AI Agents协同工作,即通过任务分配、知识共享和行动协调,共同解决单一Agent无法独立应对的复杂问题。
Strands Agents 1.0版本推出了四种直观易用的基础组件,使多Agents协作编排变得如同创建单Agents时组合模型、工具与提示词一样简单自然。
1
Agents-as-Tools:
让分层委托变得简单
Agents-as-Tools模式将具备专业能力的Agent,转化为可供其他Agent调用的智能工具,支持分层委托机制:作为协调者的Agent可在动态咨询领域专家Agent的同时,始终掌控请求处理的主导权。
这种设计模拟了人类团队的协作方式:项目经理无需掌握所有领域知识,只需知道针对不同任务应向哪位专家请教即可。
from strands import Agent, tool
from strands_tools import calculator, file_write, python_repl, journal @tool def web_search(query: str) -> str: return "Dummy web search results here!" # Create specialized agents research_analyst_agent = Agent( system_prompt="You are a research specialist who gathers and analyzes information about local startup markets", tools=[web_search, calculator, file_write, python_repl] ) travel_advisor_agent = Agent( system_prompt="You are a travel expert who helps with trip planning and destination advice", tools=[web_search, journal] ) # Convert the agents into tools @tool def research_analyst(query: str) -> str: response = research_analyst_agent(query) return str(response) # Orchestrator naturally delegates to specialists executive_assistant = Agent( tools=[research_analyst, travel_advisor] )
result = executive_assistant("I have a business meeting in Portland next week. Suggest a nice place to stay near the local startup scene, and suggest a few startups to visit")
左右滑动查看完整示意
本简化示例定义了旅行Agent和研究Agent,它们拥有针对各自专业领域的定制化提示词和工具。行政助理Agent可调用这些专业Agent,以获取对用户请求的参考意见,并负责将其他Agent提供的信息整合后,生成响应用户的最终回复。
有关Agents-as-Tools模式的详细信息,请参阅Strands Agents文档。
Strands Agents文档——Agents-as-Tools:
https://strandsagents.com/latest/user-guide/concepts/multi-agent/agents-as-tools/
2
任务移交:
明确转移控制权
遇到超出自身专业范围的任务时,任务移交机制允许Agent将处理责任明确移交给人类,同时在移交过程中完整保留对话上下文。
Strands Agents提供了内置的handoff_to_user工具,任务可借此工具无缝转移控制权,并保持对话历史与上下文信息的连贯性,如同客服代表向客户询问更多信息细节时的场景。
from strands import Agentfrom strands_tools import handoff_to_user
SYSTEM_PROMPT="""Answer the user's support query. Ask them questions with the handoff_to_user tool when you need more information"""# Include the handoff_to_user tool in our agent's tool listagent = Agent( system_prompt=SYSTEM_PROMPT, tools=[handoff_to_user])# The agent calls the handoff_to_user tool which includes the question for the customeragent("I have a question about my order.")
左右滑动查看完整示意
Agent在接收提示词时,也可直接向用户提问。
from strands import Agent
SYSTEM_PROMPT="""Answer the user's support query. Ask them questions when you need more information"""
agent = Agent( system_prompt=SYSTEM_PROMPT,)# The agent asks questions by streaming them back as textagent("I have a question about my order.")
左右滑动查看完整示意
3
群体协作:
自组织协作团队
群体协作模式可创建自主Agent团队,这些团队通过共享内存动态协调行动,使多个专业Agent能够协同完成复杂任务。
您可将这种模式想象成一场头脑风暴会议:专家们相互借鉴彼此的创意,团队内部自行组织讨论,最终产出最佳集体成果。
import logging
from strands import Agent from strands.multiagent import Swarm from strands_tools import memory, calculator, file_write # Enables Strands debug logs level, and prints to stderrlogging.getLogger("strands.multiagent").setLevel(logging.DEBUG) logging.basicConfig( format="%(levelname)s | %(name)s | %(message)s", handlers=[logging.StreamHandler()] ) researcher = Agent( name="researcher", system_prompt="You research topics thoroughly using your memory and built-in knowledge", tools=[memory] ) analyst = Agent( name="analyst", system_prompt="You analyze data and create insights", tools=[calculator, memory] ) writer = Agent( name="writer", system_prompt="You write comprehensive reports based on research and analysis", tools=[file_write, memory] ) # Swarm automatically coordinates agents market_research_team = Swarm([researcher, analyst, writer]) result = market_research_team( "What is the history of AI since 1950? Create a comprehensive report"
)
左右滑动查看完整示意
有关群体协作模式的详细信息,请参阅Strands Agents文档。
Strands Agents文档——群体协作模式:
https://strandsagents.com/latest/user-guide/concepts/multi-agent/swarm/
4
图式流程:
确定性工作流控制
图式流程功能支持用户定义具有条件路由和决策节点的显式Agent工作流,尤其适用于需要严格遵循特定步骤、审批环节或质量关卡的过程。
如同精心设计的流水线或审批链,图式流程可确保Agent每次都能按照预设的业务规则,以正确顺序完成各项任务。
from strands import Agent
from strands.multiagent import GraphBuilder analyzer_agent = Agent( name="analyzer", system_prompt="Analyze customer requests and categorize them", tools=[text_classifier, sentiment_analyzer] ) normal_processor = Agent( name="normal_processor", system_prompt="Handle routine requests automatically", tools=[knowledge_base, auto_responder] ) critical_processor = Agent( name="critical_processor", system_prompt="Handle critical requests quickly", tools=[knowledge_base, escalate_to_support_agent] ) # Build deterministic workflow builder = GraphBuilder() builder.add_node(analyzer_agent, "analyze") builder.add_node(normal_processor, "normal_processor") builder.add_node(critical_processor, "critical_processor") # Define conditional routing def is_approved(state): return True def is_critical(state): return False builder.add_edge("analyze", "normal_processor", condition=is_approved) builder.add_edge("analyze", "critical_processor", condition=is_critical) builder.set_entry_point("analyze") customer_support_graph = builder.build() # Execute the graph with user input
results = customer_support_graph("I need help with my order!")
左右滑动查看完整示意
有关图式流程的详细信息,请参阅Strands Agents文档。
Strands Agents文档——图式流程:
https://strandsagents.com/latest/user-guide/concepts/multi-agent/graph/
这些多Agents模式均经过精心设计,支持逐步采用与自由组合。您可从单一Agent起步,将专业Agent作为工具加以集成,逐步升级为群体协作模式,再随着需求增长通过图式流程实现整体编排。
通过灵活混搭不同模式,您可构建出高度复杂的系统:群体协作中可嵌入图式流程,图式流程也能对群体协作进行统筹调度,且任何模式均可调用配备有其他Agent作为工具的Agent。
from strands import Agent, tool
from strands.multiagent import GraphBuilder, Swarm from strands_tools import memory, calculator, python_repl, file_write # Start simple with a single agent agent = Agent(tools=[memory]) # Create specialist agents that a lead orchestrator agent can consult data_analyst = Agent(name="analyst", tools=[calculator, python_repl]) @tool def data_analyst_tool(query: str) -> str: return str(data_analyst(query)) analyst_orchestrator = Agent(tools=[memory, data_analyst_tool]) # Agents-as-tools # Compose patterns together - a graph that uses a swarm researcher = Agent(name="researcher", tools=[memory]) writer = Agent(name="writer", tools=[file_write]) research_swarm = Swarm([researcher, analyst_orchestrator, writer]) review_agent = Agent(system_prompt="Review the research quality and suggest improvements") builder = GraphBuilder() builder.add_node(research_swarm, "research") # Swarm as graph node builder.add_node(review_agent, "review") builder.add_edge("research", "review") graph = builder.build() # The patterns nest naturally - swarms in graphs, agents as tools everywhere
result = graph("How has green energy evolved over the last few years?")
左右滑动查看完整示意
基于A2A协议的多Agents系统
Strands Agents 1.0支持A2A协议,该协议是一项开放标准,能让不同来源的Agent实现无缝通信。任何Strands Agents均可通过封装具备A2A能力,从而接入网络并遵循A2A协议。此外,来自外部机构的A2A Agents也可直接应用于所有Strands多Agents协作模式中。
from strands import Agent
from strands.multiagent.a2a import A2AServer
from strands_tools.a2a_client import A2AClientToolProvider
# Serve your agent via A2A protocol
local_agent = Agent(name="analyzer", tools=[web_search, data_analysis])
a2a_agent = A2AServer(agent=local_agent, port=9000)
a2a_agent.serve() # AgentCard available at http://localhost:9000/.well-known/agent.json # Use remote A2A agents
partner_agent_url = "https://partner.com"
cloud_agent_url = "https://cloud.ai"
# Connect to remote A2A enabled agents
a2a_tool_provider = A2AClientToolProvider(known_agent_urls=[partner_agent_url, cloud_agent_url])
# Orchestrate remote agents
orchestrator = Agent(tools=[a2a_tool_provider.tools])
左右滑动查看完整示意
由于A2A协议提供了Agent card等功能(Agent card功能可对Agent能力进行标准化描述),因此支持A2A协议的多Agents系统能够轻松发现并连接到由其他团队或组织创建的Agent。Strands Agents会根据您为Agent配置的工具,自动生成Agent card。
有关完整的工作运行示例以及如何开始进行A2A集成,请查看示例代码库以及Strands A2A协议文档。
示例代码库:
https://github.com/strands-agents/samples/tree/main/03-integrations/Native-A2A-Support
Strands A2A协议文档:
https://strandsagents.com/latest/user-guide/concepts/multi-agent/agent-to-agent/
可投入生产使用
在Strands Agents正式公开发布之前,Amazon Q Developer团队和Amazon Glue团队等亚马逊云科技内部团队,就已在生产环境中应用该服务。
与此同时,亚马逊云科技与全球数百家客户紧密协作,不断扩展Strands Agents功能以满足生产需求,包括以下功能:
引入会话管理抽象层,以支持数据持久化存储至外部数据存储库,以及从其中恢复数据。
优化结构化输出。
增强异步支持能力。
1
持久化会话管理
新增SessionManager会话管理抽象层,能够实现Agent对话内容及状态的自动持久化存储与恢复。借助这一功能,Agent可将完整的对话历史记录保存至诸如Amazon S3等存储后端,即便计算资源重启,也能无缝恢复对话。
以下是一项基于基础文件实现持久化存储的示例。
from strands import Agent
from strands.session.file_session_manager import FileSessionManager # Create a session manager with file-based storage Session_manager = FileSessionManager(session_id=”customer_support”, base_dir="./agent_sessions") # Agent automatically persists all conversations agent = Agent( id="support_bot_1", session_manager=session_manager, tools=[knowledge_base, ticket_system] ) # Messages are automatically saved as the conversation progresses agent("Help me reset my password") agent("I can't access my email") # Later, even after a restart, restore the full conversation restored_session_manager = FileSessionManager(session_id=”customer_support”, base_dir="./agent_sessions") restored_agent = Agent( id="support_bot_1", session_manager=restored_session_manager, tools=[knowledge_base, ticket_system] )
# Agent remembers entire conversation history and can continue seamlessly
左右滑动查看完整示意
您可通过数据访问对象(Data Access Object,DAO)模式,利用存储后端实现方案来扩展这一抽象层,同时Strands Agents默认包含本地文件系统和Amazon S3两种存储后端。系统会为每个Agent分配一个用于追踪的唯一标识符,并能在同一会话中处理多个并发运行的Agent,以应对多Agents场景,确保Agent在部署、扩容事件以及系统重启等情况下,能够始终保持上下文连贯性。
有关会话管理的更多信息,请参阅Strands Agents文档。
Strands Agents文档——会话管理:
https://strandsagents.com/latest/user-guide/concepts/agents/session-management/
2
原生异步支持与性能优化
生产环境中的工作负载对可靠性和响应性能有着极高要求。Strands Agents 1.0版本对Strands的事件循环架构进行了优化,使其在整个技术栈中支持异步操作。现在,工具和模型提供方均可异步运行且不会造成阻塞,从而实现了真正意义上的并发执行。
全新的stream_async方法能够实时传输所有Agent事件,包括文本、工具使用情况、推理步骤等,并且内置取消支持功能,可在用户离开时停止传输。
import asyncio
from fastapi import FastAPI from fastapi.responses import StreamingResponse from strands import Agent from strands_tools import calculator app = FastAPI() @app.post("/chat") async def chat_endpoint(message: str): async def stream_response(): agent = Agent(tools=[web_search, calculator]) # Stream agent responses in real-time async for event in agent.stream_async(message): if"data" in event: yield f"data: {event['data']}\n\n" elif "current_tool_use" in event: yield f"event: tool\ndata: Using {event['current_tool_use']['name']}\n\n" return StreamingResponse(stream_response(), media_type="text/event-stream") # Concurrent agent evaluation async def evaluate_models_concurrently(prompt: str): async def stream(agent: Agent): print(f"STARTING: {agent.name}") async for event in agent.stream_async(prompt): # handle events print(f"ENDING: {agent.name}") return event[“result”] # last event is the agent result agents = [ Agent(name="claude", model="us.anthropic.claude-3-7-sonnet-20250219-v1:0”), Agent(name="deepseek”, model="us.deepseek.r1-v1:0”), Agent(name="nova", model="us.amazon.nova-pro-v1:0") ] # Execute all agents concurrently responses = await asyncio.gather(*[stream(agent) for agent in agents])
return responses
左右滑动查看完整示意
有关原生异步支持的详细信息,请参阅Strands Agents文档。
Strands Agents文档——原生异步支持:
https://strandsagents.com/latest/user-guide/concepts/streaming/async-iterators/
3
扩展的模型提供方支持
客户反馈称,他们希望针对不同任务能灵活选用不同模型。为此,Strands Agents获得了模型提供方社区的大力支持。Anthropic、Meta等模型提供方积极贡献,使Strands Agents能够直接通过代码调用其模型API。通过模型提供方的API基础设施访问Strands Agents,开发者可专注于构建AI解决方案,无需管理基础设施。
这些新增功能与预览版发布时对Amazon Bedrock、OpenAI以及通过LiteLLM接入的、任何与OpenAI兼容的端点的支持形成互补。借助Strands Agents,您可为每个Agent选用不同模型,或者无需修改工具和逻辑代码,即可灵活切换模型及模型提供方。
from strands import Agentfrom strands.models import BedrockModelfrom strands.models.openai import OpenAIModelfrom strands.models.anthropic import AnthropicModel
# Configure different model providersbedrock_model = BedrockModel( model_id="us.amazon.nova-pro-v1:0", temperature=0.3, top_p=0.8, region_name="us-west-2")
openai_model = OpenAIModel( client_args={"api_key": "your-api-key",}, model_id="gpt-4o", params={"max_tokens": 1000,"temperature": 0.7,})
anthropic_model = AnthropicModel( client_args={"api_key": "your-api-key",}, max_tokens=1028, model_id="claude-3-7-sonnet-20250219", params={"temperature": 0.5,})# Swap models or use different models for different agents in the same systemresearcher = Agent( name="researcher", model=anthropic_model, tools=[web_search])
writer = Agent( name="writer", model=openai_model, tools=[document_formatter])
analyzer = Agent( name="analyzer", model=bedrock_model, tools=[data_processor])
左右滑动查看完整示意
Strands社区在推动Strands Agents的更新发展中发挥了至关重要的作用。社区成员们不仅亲自使用Strands Agents,还积极反馈意见、直接贡献代码等,为项目发展建言献策。
从0.1.0版本发展到1.0版本,共有150多个拉取请求(Pull Request,PR)被合并到Strands Agents,其中22%是由社区成员贡献的。社区成员还帮助修复漏洞、添加模型提供方、编写文档、新增功能,以及对类进行重构以提升性能。
在此,亚马逊云科技衷心向每一位为Strands Agents发展贡献力量的成员致以最诚挚的感谢,正是您的努力,让Strands Agents成为将Agent从原型设计快速推进到生产应用的极便捷途径。
人工智能的发展趋势是多Agents协作,Strands Agents 1.0的发布,正标志着这一未来愿景已具备投入实际生产应用的条件。
即刻访问strandsagents.com,开启您的构建之旅吧!
本篇作者
Ryan Coleman
亚马逊云科技产品经理,专注于AI开发者工具和Agent框架领域。他拥有丰富的DevOps与开源技术经验,致力于帮助开发者借助大语言模型的强大能力,构建智能、可扩展的软件系统。
Belle Guttman
亚马逊云科技Agentic AI工程团队的负责人,主要负责Strands SDK以及Amazon Q Developer产品中的Agent对话功能。她拥有软件工程背景,致力于用简洁的解决方案帮助客户攻克复杂的技术难题。
星标不迷路,开发更极速!
关注后记得星标「亚马逊云开发者」
听说,点完下面4个按钮
就不会碰到bug了!
点击阅读原文查看博客!获得更详细内容!