Repository: https://github.com/strands-agents/tools Stars: 1,092 | Forks: 308 | Language: Python | License: Apache-2.0 Tags: agentic, agentic-ai, agents, ai, anthropic, autonomous-agents, genai, litellm, llm, machine-learning, mcp, multi-agent-systems, ollama, opentelemetry, python, bedrock, llama, openai, strands-agents Last Updated: 2026-06-14
1. 專案概覽 (Project Overview)
1.1 這是什麼
Strands Agents Tools 是 Strands Agents 生態系中的官方工具集合 (tool collection),由 AWS 開源團隊維護。它提供超過 50 種即用型工具 (ready-to-use tools),涵蓋檔案操作、Shell 執行、網路搜尋、記憶體系統、多 Agent 協調、數學運算、影像生成、AWS 整合等面向,讓開發者只需幾行 Python 程式碼就能賦予 AI Agent 強大的實際操作能力。
1.2 誰在做
本專案隸屬 strands-agents GitHub Organization,作者為 AWS 開源團隊(authors = [{ name = "AWS", email = "opensource@amazon.com" }])。它是 Strands Agents 平台 12 個 repo 之一,專責「工具層 (Tool Layer)」——Agent 能做什麼事,取決於載入了哪些工具。
1.3 解決什麼問題
LLM (Large Language Model; 大型語言模型) 本身只能產生文字,無法操作檔案、執行程式、查詢 API 或協調其他 Agent。Strands Agents Tools 透過 tool-use protocol 讓 Agent 能:
- 讀寫檔案系統
- 執行 Shell 命令與 Python 程式碼
- 呼叫 HTTP API 與搜尋引擎
- 記住跨 session 的使用者偏好
- 啟動子 Agent (nested agent) 與群體智慧 (swarm intelligence)
- 動態連接 MCP (Model Context Protocol) 伺服器
- 操控瀏覽器與桌面
1.4 在生態系中的定位
1strands-agents 生態系(12 個 repo)
2├── sdk-python ← Agent 核心 SDK(Agent class、tool protocol、model provider)
3├── tools ← ★ 本 repo:50+ 種即用型工具
4├── agent-builder ← 視覺化 Agent 建構器
5├── mcp-server ← 靜態 MCP 伺服器整合
6├── samples ← 範例程式碼
7├── docs ← 官方文件站
8├── ...(其餘 6 個基礎設施 repo)
本 repo 是 sdk-python 的「工具擴充層」:sdk-python 定義了 @tool 裝飾器與 Agent 類別,而 tools 提供所有預製工具讓 Agent 實際可用。沒有 tools,Agent 就只是一個對話機器人;有了 tools,Agent 才能操作真實世界。
2. 核心架構 (Core Architecture)
2.1 模組層級架構
graph TB
subgraph "strands-agents/tools"
direction TB
subgraph "File & System 檔案與系統"
FR[file_read]
FW[file_write]
ED[editor]
SH[shell]
ENV[environment]
CR[cron]
end
subgraph "Web & API 網路與 API"
HTTP[http_request]
TS[tavily_search / extract / crawl / map]
EXA[exa_search / get_contents]
BD[bright_data]
RSS[rss]
end
subgraph "Memory 記憶系統"
MEM[memory — Bedrock KB]
M0[mem0_memory]
ACM[agent_core_memory]
MONGO[mongodb_memory]
ES[elasticsearch_memory]
end
subgraph "Multi-Agent 多 Agent 協調"
UA[use_agent]
UL[use_llm]
SW[swarm]
GR[graph — DAG Pipeline]
AG[agent_graph]
BA[batch — 並行工具呼叫]
A2A[a2a_client]
end
subgraph "Code & Math 程式碼與運算"
PR[python_repl]
CI[code_interpreter]
CA[calculator]
TH[think — 遞迴推理]
end
subgraph "Media 多媒體"
GI[generate_image]
GIS[generate_image_stability]
IR[image_reader]
NR[nova_reels — 影片生成]
SP[speak — 語音輸出]
SV[search_video]
CV[chat_video]
DG[diagram]
end
subgraph "Integration 整合"
AWS[use_aws]
RET[retrieve — Bedrock KB]
MC[mcp_client — 動態 MCP]
SL[slack]
BR[browser]
UC[use_computer]
LT[load_tool — 動態載入]
end
subgraph "Control Flow 控制流程"
WF[workflow]
HU[handoff_to_user]
ST[stop]
SLP[sleep]
CT[current_time]
JO[journal]
end
end
SDK["strands-agents/sdk-python
Agent class + @tool protocol"] --> FR
SDK --> HTTP
SDK --> MEM
SDK --> UA
SDK --> PR
SDK --> GI
SDK --> AWS
SDK --> WF
2.2 工具註冊與呼叫流程
sequenceDiagram
participant User as 使用者
participant Agent as Agent (SDK)
participant LLM as LLM Provider
participant Tool as Tool Module
participant Ext as External Service
User->>Agent: agent("幫我搜尋 AI 新聞")
Agent->>LLM: 傳送對話 + 可用工具清單 (TOOL_SPEC)
LLM->>Agent: tool_use: tavily_search(query="AI news")
Agent->>Tool: 呼叫 tavily_search 函式
Tool->>Ext: Tavily API 請求
Ext-->>Tool: 搜尋結果
Tool-->>Agent: ToolResult(status="success", content=[...])
Agent->>LLM: 將工具結果送回 LLM
LLM->>Agent: 整理後的自然語言回答
Agent-->>User: "以下是今天的 AI 新聞..."
2.3 工具定義模式
每個工具檔案遵循一致的結構模式:
- TOOL_SPEC 字典:定義工具名稱、描述與 JSON Schema 輸入規格(供 LLM 理解如何呼叫)
- 主函式:接收
tool: ToolUse與**kwargs(含agent參考),回傳ToolResult - Rich Console 輸出:使用
rich函式庫在終端顯示格式化結果
兩種定義方式:
| 方式 | 範例 | 適用場景 |
|---|---|---|
TOOL_SPEC + 函式 | file_read.py, batch.py | 需要精細控制 schema |
@tool 裝飾器 | use_agent.py, swarm.py | 簡潔定義,schema 自動推導 |
3. 安裝與設定 (Installation & Setup)
3.1 前置需求
- Python: 3.10 以上(支援 3.10 ~ 3.14)
- pip: 最新版本
- 選用:Tavily API Key、Exa API Key、AWS credentials(視使用工具而定)
3.2 快速安裝
1# 基本安裝(含所有核心工具)
2pip install strands-agents-tools
3
4# 安裝選用工具的額外依賴
5pip install "strands-agents-tools[mem0_memory]" # Mem0 記憶系統
6pip install "strands-agents-tools[use_browser]" # 瀏覽器自動化
7pip install "strands-agents-tools[rss]" # RSS Feed 管理
8pip install "strands-agents-tools[use_computer]" # 桌面自動化
9
10# 一次裝全部選用依賴
11pip install "strands-agents-tools[mem0_memory,use_browser,rss,use_computer]"
3.3 開發環境安裝
1# 1. Clone repo
2git clone https://github.com/strands-agents/tools.git
3cd tools
4
5# 2. 建立虛擬環境(建議用 uv)
6python3 -m venv .venv
7source .venv/bin/activate
8
9# 3. 安裝開發模式 + 開發依賴
10pip install -e ".[dev]"
11
12# 4. 安裝 pre-commit hooks
13pre-commit install
3.4 環境變數設定
根據你要使用的工具,需要設定對應的環境變數:
1# AWS Bedrock(use_aws / retrieve / memory / nova_reels / generate_image)
2export AWS_REGION=us-west-2
3export AWS_ACCESS_KEY_ID=your_key
4export AWS_SECRET_ACCESS_KEY=your_secret
5
6# Tavily 搜尋
7export TAVILY_API_KEY=tvly-xxxxxxxxxxxxx
8
9# Exa 搜尋
10export EXA_API_KEY=your_exa_key
11
12# Anthropic(use_agent 的 model_provider="anthropic")
13export ANTHROPIC_API_KEY=sk-ant-xxxxx
14
15# OpenAI
16export OPENAI_API_KEY=sk-xxxxx
17
18# 動態 model provider(use_agent 的 model_provider="env")
19export STRANDS_PROVIDER=bedrock
20export STRANDS_MODEL_ID=us.anthropic.claude-sonnet-4-20250514-v1:0
21export STRANDS_MAX_TOKENS=4096
22export STRANDS_TEMPERATURE=0.7
3.5 驗證安裝
1# 最小驗證:載入工具並建立 Agent
2from strands import Agent
3from strands_tools import file_read, current_time, calculator
4
5agent = Agent(tools=[file_read, current_time, calculator])
6result = agent("現在幾點?")
7print(result)
4. 使用方式與程式碼範例 (Usage & Code Examples)
4.1 範例一:檔案操作 Agent (File Operations Agent)
這個範例展示如何建立一個能讀寫檔案的 Agent,涵蓋 file_read、file_write、editor 三個工具。
1from strands import Agent
2from strands_tools import file_read, file_write, editor
3
4# 建立 Agent,載入三個檔案操作工具
5agent = Agent(
6 tools=[file_read, file_write, editor],
7 system_prompt="你是一個檔案管理助手,能讀取、寫入、編輯檔案。"
8)
9
10# --- 範例 1:讀取檔案(view 模式)---
11# file_read 支援多種模式:view / find / lines / search / stats / diff / time_machine
12agent.tool.file_read(
13 path="config.json", # 要讀取的檔案路徑
14 mode="view" # 模式:完整顯示 + 語法高亮
15)
16
17# --- 範例 2:搜尋檔案中的特定 pattern ---
18agent.tool.file_read(
19 path="src/app.py",
20 mode="search", # 搜尋模式
21 search_pattern="def main", # 搜尋 pattern(支援正規表達式)
22 context_lines=3 # 搜尋結果前後各顯示 3 行上下文
23)
24
25# --- 範例 3:寫入新檔案 ---
26agent.tool.file_write(
27 path="output/report.md",
28 content="# 分析報告\n\n## 摘要\n今天的分析結果如下..."
29)
30
31# --- 範例 4:使用 editor 進行精準文字取代 ---
32# editor 比 file_write 更適合修改現有檔案的特定段落
33agent.tool.editor(
34 command="str_replace", # 指令:字串取代
35 path="config.json",
36 old_str='"debug": false', # 要取代的舊字串
37 new_str='"debug": true' # 取代後的新字串
38)
關鍵解說:
file_read擁有 10 種讀取模式(view / find / lines / chunk / search / stats / preview / diff / time_machine / document),是功能最完整的讀取工具。editor支援view、create、str_replace、insert、undo_edit五種指令,適合需要精準修改而非整檔覆寫的場景。- 這三個工具搭配使用,幾乎可以處理任何檔案操作需求。
4.2 範例二:多模型子 Agent 工作流 (Multi-Model use_agent Workflow)
use_agent 是本 repo 最強大的工具之一——它能在主 Agent 內部啟動「子 Agent (nested agent)」,且每個子 Agent 可以使用不同的 LLM Provider (模型供應商)。
1from strands import Agent
2from strands_tools import use_agent, calculator, file_write
3
4# 主 Agent 使用 Bedrock Claude Sonnet(負責協調)
5agent = Agent(
6 tools=[use_agent, calculator, file_write],
7 system_prompt="你是工作流協調者,可將不同任務分派給專門的子 Agent。"
8)
9
10# --- 用法 1:繼承父 Agent 的模型 ---
11# 最簡單的用法:子 Agent 繼承父 Agent 的 model provider
12result = agent.tool.use_agent(
13 prompt="分析 Python 3.12 的新語法特性",
14 system_prompt="你是 Python 語言專家。"
15 # model_provider=None → 自動繼承父 Agent 的模型
16)
17
18# --- 用法 2:指定不同的模型 Provider ---
19# 子 Agent 使用 Anthropic 直連(而非透過 Bedrock)
20result = agent.tool.use_agent(
21 prompt="計算 2024 年 Q4 的營收成長率,假設 Q3 為 1200 萬、Q4 為 1500 萬",
22 system_prompt="你是財務分析師,計算時請使用 calculator 工具。",
23 model_provider="anthropic", # 切換到 Anthropic 直連
24 model_settings={
25 "model_id": "claude-sonnet-4-20250514", # 指定模型
26 "params": {"temperature": 0.3} # 低溫度 → 更精確
27 },
28 tools=["calculator"] # 只給子 Agent calculator 工具
29)
30
31# --- 用法 3:透過環境變數決定模型 ---
32import os
33os.environ["STRANDS_PROVIDER"] = "ollama"
34os.environ["STRANDS_MODEL_ID"] = "qwen3:4b"
35
36result = agent.tool.use_agent(
37 prompt="Review this code for security issues",
38 system_prompt="You are a security auditor.",
39 model_provider="env" # 從環境變數讀取 provider 設定
40)
關鍵解說:
model_provider支援 7 種選項:bedrock、anthropic、litellm、llamaapi、ollama、openai、env(環境變數)。tools參數讓你精細控制子 Agent 能使用哪些工具——不指定則繼承父 Agent 所有工具。- 這個機制讓你實現 cost optimization (成本優化):簡單任務用便宜模型,困難任務用強力模型。
4.3 範例三:Swarm 群體智慧 (Swarm Intelligence)
swarm 工具基於 Strands SDK 的 Swarm multi-agent pattern (多代理人模式),讓多個 Agent 自主協調、共享工作記憶。
1from strands import Agent
2from strands_tools import swarm, file_write, calculator
3
4agent = Agent(tools=[swarm, file_write, calculator])
5
6# 定義一個 3 人專家團隊
7result = agent.tool.swarm(
8 task="為一家 AI 新創公司設計完整的產品上市策略",
9 agents=[
10 {
11 "name": "market_researcher", # Agent 名稱(也是 handoff 的識別符)
12 "system_prompt": (
13 "你是市場研究專家。負責分析目標市場、競爭對手、"
14 "客戶需求與市場規模。完成後交接給 product_strategist。"
15 ),
16 "tools": ["calculator"], # 此 Agent 可用的工具
17 "model_provider": "bedrock",
18 "model_settings": {
19 "model_id": "us.anthropic.claude-sonnet-4-20250514-v1:0"
20 }
21 },
22 {
23 "name": "product_strategist",
24 "system_prompt": (
25 "你是產品策略師。根據市場研究結果,制定產品定位、"
26 "價值主張與 go-to-market 計劃。完成後交接給 writer。"
27 ),
28 "tools": ["file_write"],
29 "model_provider": "anthropic",
30 "model_settings": {"model_id": "claude-sonnet-4-20250514"}
31 },
32 {
33 "name": "writer",
34 "system_prompt": (
35 "你是商業文案專家。將策略轉化為投資人提案、"
36 "行銷文案與簡報大綱。將最終成果寫入檔案。"
37 ),
38 "tools": ["file_write"],
39 "model_provider": "openai",
40 "model_settings": {"model_id": "o4-mini"}
41 }
42 ]
43)
關鍵解說:
- Swarm 會自動注入兩個協調工具:
handoff_to_agent(將控制權交給另一個 Agent)與complete_swarm_task(宣告任務完成)。 - 每個 Agent 可以使用不同的 model provider,實現 跨模型協作 (cross-model collaboration)。
- Agent 之間共享工作記憶 (shared working memory),後續 Agent 能看到先前 Agent 的產出。
- 與
use_agent的差異:use_agent是主從架構(父呼叫子),swarm是對等架構(Agent 之間自主交接)。
4.4 範例四:DAG Pipeline 多 Agent 管線 (Graph-based Pipeline)
graph 工具使用 DAG (Directed Acyclic Graph; 有向無環圖) 來定義確定性的多 Agent 管線,適合需要嚴格執行順序的工作流。
1from strands import Agent
2from strands_tools import graph, file_write, editor
3
4agent = Agent(tools=[graph, file_write, editor])
5
6# 1. 建立 DAG 拓撲結構
7result = agent.tool.graph(
8 action="create", # 動作:建立圖
9 graph_id="research_pipeline", # 圖的唯一 ID
10 topology={
11 "nodes": [
12 {
13 "id": "researcher",
14 "role": "researcher",
15 "system_prompt": "你負責深入研究指定主題,產出研究摘要。",
16 "model_provider": "bedrock",
17 "model_settings": {
18 "model_id": "us.anthropic.claude-sonnet-4-20250514-v1:0"
19 }
20 },
21 {
22 "id": "analyst",
23 "role": "analyst",
24 "system_prompt": "你根據研究摘要,進行資料分析與洞察萃取。",
25 "model_provider": "bedrock",
26 "model_settings": {
27 "model_id": "us.anthropic.claude-3-5-haiku-20241022-v1:0"
28 }
29 },
30 {
31 "id": "reporter",
32 "role": "reporter",
33 "system_prompt": "你將分析結果整理成完整報告並寫入檔案。",
34 "tools": ["file_write", "editor"] # 此節點專屬的工具
35 }
36 ],
37 "edges": [
38 {"from": "researcher", "to": "analyst"}, # researcher → analyst
39 {"from": "analyst", "to": "reporter"} # analyst → reporter
40 ],
41 "entry_points": ["researcher"] # DAG 的起始節點
42 }
43)
44
45# 2. 在圖上執行任務
46result = agent.tool.graph(
47 action="execute",
48 graph_id="research_pipeline",
49 task="研究 CRISPR 基因編輯在罕見疾病治療中的最新進展"
50)
51
52# 3. 查看圖的狀態
53status = agent.tool.graph(
54 action="status",
55 graph_id="research_pipeline"
56)
關鍵解說:
graph使用 Strands SDK 的GraphBuilder類別建構 DAG,確保執行順序的確定性。- 與
swarm的差異:swarm是自主協調(Agent 自己決定交接),graph是確定性管線(開發者預先定義拓撲)。 - 每個 node 可以有獨立的
model_provider與model_settings,實現 per-node 模型配置。 edges定義了資料流向——上游 node 的輸出自動傳播到下游 node 作為 context。
5. 進階功能 (Advanced Features)
5.1 動態 MCP Client (Dynamic MCP Client)
mcp_client 工具讓 Agent 能在 runtime (執行階段) 連接到任意 MCP Server (MCP 伺服器),動態載入遠端工具。這與 Strands SDK 的靜態 MCP 整合不同——靜態整合需要在建立 Agent 前就設定好,而動態 MCP 可以在對話過程中隨時連接新的伺服器。
1from strands import Agent
2from strands_tools import mcp_client
3
4agent = Agent(tools=[mcp_client])
5
6# 連接 stdio 傳輸的 MCP Server
7agent.tool.mcp_client(
8 action="connect",
9 connection_id="my_tools", # 連線識別符
10 transport="stdio", # 傳輸協定:stdio / sse / streamable_http
11 command="python",
12 args=["my_mcp_server.py"]
13)
14
15# 列出伺服器上的可用工具
16tools = agent.tool.mcp_client(
17 action="list_tools",
18 connection_id="my_tools"
19)
20
21# 呼叫遠端工具
22result = agent.tool.mcp_client(
23 action="call_tool",
24 connection_id="my_tools",
25 tool_name="calculate",
26 tool_args={"x": 10, "y": 20}
27)
28
29# 將遠端工具直接載入 Agent 的工具登錄表
30agent.tool.mcp_client(
31 action="load_tools",
32 connection_id="my_tools"
33)
34# 載入後可以直接呼叫:agent.tool.calculate(x=10, y=20)
安全警告:
mcp_client允許 Agent 自主連接外部 MCP Server 並載入不受信任的工具。在 production (生產環境) 中使用務必謹慎。環境變數STRANDS_MCP_TIMEOUT(預設 30 秒)可控制連線超時。
5.2 Batch 並行工具呼叫 (Parallel Tool Invocation)
batch 工具讓 LLM 在單次回應中同時呼叫多個工具,大幅減少來回的延遲。
1from strands import Agent
2from strands_tools import batch, http_request, current_time, use_aws
3
4agent = Agent(tools=[batch, http_request, current_time, use_aws])
5
6# 一次同時執行三個獨立操作
7result = agent.tool.batch(
8 invocations=[
9 {
10 "name": "current_time",
11 "arguments": {"timezone": "Asia/Taipei"}
12 },
13 {
14 "name": "http_request",
15 "arguments": {
16 "method": "GET",
17 "url": "https://api.ipify.org?format=json"
18 }
19 },
20 {
21 "name": "use_aws",
22 "arguments": {
23 "service_name": "s3",
24 "operation_name": "list_buckets",
25 "parameters": {},
26 "region": "us-east-1"
27 }
28 }
29 ]
30)
5.3 Think 遞迴推理 (Recursive Thinking)
think 工具讓 Agent 進行多輪深度分析,每個思考循環可以使用不同的模型。
1from strands import Agent
2from strands_tools import think
3
4agent = Agent(tools=[think])
5
6result = agent.tool.think(
7 thought="評估 mRNA 療法在實體腫瘤中的可行性,考慮遞送系統、免疫原性與成本",
8 cycle_count=3, # 進行 3 輪遞迴思考
9 thinking_system_prompt=( # 自訂思考指引
10 "每一輪思考請從不同角度切入:\n"
11 "第 1 輪:技術可行性\n"
12 "第 2 輪:臨床證據\n"
13 "第 3 輪:商業可行性"
14 ),
15 model_provider="anthropic", # 思考用的模型
16 model_settings={"model_id": "claude-sonnet-4-20250514"}
17)
ThoughtProcessor 類別管理整個思考流程:每一輪都建立獨立的 prompt、追蹤循環計數、並以 Rich panel 格式化輸出結果。
5.4 Memory 記憶系統 (Memory Systems)
本 repo 提供 5 種記憶後端 (memory backends),讓 Agent 在不同 session 之間保留資訊:
| 工具 | 後端 | 特色 |
|---|---|---|
memory | Amazon Bedrock Knowledge Bases | AWS 原生,支援 metadata 過濾 |
agent_core_memory | Amazon Bedrock Agent Core | AWS 託管記憶服務 |
mem0_memory | Mem0 | 開源記憶層,支援 user/agent 雙維度 |
mongodb_memory | MongoDB Atlas | 語義搜尋 via AWS Bedrock Titan Embeddings |
elasticsearch_memory | Elasticsearch | 語義搜尋 via AWS Bedrock Titan Embeddings |
1from strands import Agent
2from strands_tools import mem0_memory
3
4agent = Agent(tools=[mem0_memory])
5
6# 儲存記憶
7agent.tool.mem0_memory(
8 action="store",
9 content="使用者偏好用繁體中文回覆,且是生物資訊分析師",
10 user_id="user_001"
11)
12
13# 檢索相關記憶
14memories = agent.tool.mem0_memory(
15 action="retrieve",
16 query="使用者的專業背景",
17 user_id="user_001"
18)
5.5 Browser & Computer Use 瀏覽器與桌面控制
1from strands import Agent
2from strands_tools.browser import LocalChromiumBrowser
3
4# 建立本地瀏覽器實例
5browser = LocalChromiumBrowser()
6agent = Agent(tools=[browser.browser])
7
8# Agent 可以瀏覽網頁、填寫表單、擷取內容
9agent("前往 https://example.com 並擷取頁面標題")
use_computer 則提供桌面層級的自動化:滑鼠移動、鍵盤輸入、截圖與應用程式管理。
5.6 A2A Client (Agent-to-Agent Protocol)
a2a_client 實作了 Agent-to-Agent Protocol,讓不同框架的 Agent 之間可以互相溝通。
1from strands import Agent
2from strands_tools.a2a_client import A2AClientToolProvider
3
4# 建立 A2A client,指定已知的遠端 Agent 位址
5provider = A2AClientToolProvider(
6 known_agent_urls=["http://localhost:9000"]
7)
8
9agent = Agent(tools=provider.tools)
10agent("請透過 A2A 與遠端 Agent 溝通,詢問今天的天氣")
6. Agent 可呼叫性分析 (Agent Callability Analysis)
6.1 呼叫方式總覽
| 介面 | 支援度 | 說明 |
|---|---|---|
| Python API | ✅ 原生支援 | from strands_tools import tool_name → agent.tool.tool_name(...) |
| MCP | ✅ 雙向支援 | 靜態整合(via sdk-python)+ 動態整合(via mcp_client 工具) |
| CLI | ⚠️ 間接支援 | 需透過 shell 工具或 strands-agents/agent-builder |
| REST API | ⚠️ 間接支援 | 需自行包裝(搭配 FastAPI/Flask)或使用 http_request 工具 |
| A2A Protocol | ✅ 支援 | 透過 a2a_client 工具與其他 A2A 相容 Agent 互操作 |
6.2 工具載入模式
1# 方式 1:靜態載入(建立 Agent 時)
2from strands_tools import file_read, shell, calculator
3agent = Agent(tools=[file_read, shell, calculator])
4
5# 方式 2:動態載入(runtime 時)
6from strands_tools import load_tool
7agent = Agent(tools=[load_tool])
8agent.tool.load_tool(path="custom_tool.py", name="my_custom_tool")
9
10# 方式 3:動態 MCP 載入(runtime 連接遠端工具)
11from strands_tools import mcp_client
12agent = Agent(tools=[mcp_client])
13agent.tool.mcp_client(action="connect", connection_id="remote", ...)
14agent.tool.mcp_client(action="load_tools", connection_id="remote")
6.3 與 MCP Server repo 的關係
- strands-agents/mcp-server:將 Strands Agent 本身作為 MCP Server 暴露給外部客戶端(Claude Desktop、Cursor 等)。
- strands-agents/tools 的 mcp_client:讓 Strands Agent 作為 MCP Client 連接外部 MCP Server。
兩者方向相反但互補:一個「對外提供」,一個「對外取用」。
7. 與生態系的關係 (Ecosystem Relationships)
7.1 strands-agents 全生態系對照表
| Repo | 角色 | 與 tools 的關係 |
|---|---|---|
| sdk-python | 核心 SDK | tools 的上游依賴;定義 @tool / Agent / ToolResult 等核心 protocol |
| tools | ★ 工具集合 | 本 repo。提供 50+ 即用型工具 |
| agent-builder | 視覺化建構器 | 使用 tools repo 的工具作為 Agent 的能力來源 |
| mcp-server | MCP 伺服器 | 讓 Strands Agent 可被外部 MCP Client 呼叫;tools 中的 mcp_client 則反向連接外部 MCP Server |
| samples | 範例程式碼 | 大量範例展示如何組合 tools repo 的工具 |
| docs | 官方文件 | 包含每個工具的使用指南 |
7.2 依賴關係
1strands-agents-tools
2├── strands-agents >= 1.0.0 ← 核心 SDK(必須)
3├── rich >= 14.0.0 ← 終端格式化輸出
4├── sympy >= 1.12.0 ← 符號數學(calculator 用)
5├── pillow >= 12.1.1 ← 影像處理
6├── slack_bolt >= 1.23.0 ← Slack 整合
7├── markdownify >= 1.0.0 ← HTML → Markdown 轉換
8├── requests >= 2.28.0 ← HTTP 請求
9├── aiohttp >= 3.8.0 ← 非同步 HTTP
10├── botocore >= 1.39.7 ← AWS SDK 基礎
11└── [optional]
12 ├── mem0ai ← Mem0 記憶
13 ├── playwright ← 瀏覽器自動化
14 └── twelvelabs ← 影片搜尋/分析
7.3 Model Provider 支援
utils/models/ 子目錄封裝了 7 種 model provider 的建立邏輯:
| Provider | 檔案 | 說明 |
|---|---|---|
| Bedrock | bedrock.py | AWS Bedrock(預設推薦) |
| Anthropic | anthropic.py | Anthropic API 直連 |
| OpenAI | openai.py | OpenAI API |
| LiteLLM | litellm.py | 統一多 provider 介面 |
| Ollama | ollama.py | 本地部署模型 |
| LlamaAPI | llamaapi.py | Llama API |
| Writer | writer.py | Writer API |
create_model() 函式根據 provider 參數自動選擇對應的工廠函式,讓 use_agent、think、swarm、graph 等多 Agent 工具能無縫切換模型。
8. 優缺點分析 (Strengths & Limitations)
8.1 優勢 (Strengths)
| 面向 | 說明 |
|---|---|
| 工具數量與覆蓋面 | 50+ 工具涵蓋檔案、網路、記憶、多 Agent、媒體、AWS、桌面控制等面向,是同類框架中最完整的工具集之一 |
| 多模型支援 | 透過 use_agent / swarm / graph,單一工作流可同時使用 Bedrock、Anthropic、OpenAI、Ollama 等不同 provider 的模型 |
| Multi-Agent 三模式 | 提供 use_agent(主從)、swarm(自主協調)、graph(DAG 確定性管線)三種多 Agent 協作模式,覆蓋不同場景需求 |
| 動態擴充性 | load_tool(載入本地工具)+ mcp_client(連接遠端 MCP 工具)讓工具集可在 runtime 無限擴充 |
| Rich Console 輸出 | 所有工具統一使用 rich 函式庫格式化終端輸出,開發體驗優良 |
| 測試覆蓋 | 每個工具都有對應的單元測試(tests/)與整合測試(tests_integ/) |
| Apache-2.0 授權 | 商用友善 |
8.2 限制 (Limitations)
| 面向 | 說明 |
|---|---|
| Windows 支援 | shell、cron 等工具不支援 Windows |
| AWS 偏向 | 預設 memory 後端為 AWS Bedrock KB;影像/影片生成預設用 AWS 服務;非 AWS 使用者需額外設定 |
| 安全性 | mcp_client 的動態工具載入、shell 的指令執行、python_repl 的程式碼執行都有潛在安全風險,需要在 production 環境謹慎使用 |
| 依賴體積 | 核心依賴包含 slack_bolt、pillow、sympy 等,即使不使用 Slack/影像/數學功能也會被安裝 |
| 文件分散 | 部分工具的文件在 README 的大表格中,部分在 docs/ 子目錄,部分只在原始碼 docstring 中 |
| 版本尚在 Beta | Development Status :: 4 - Beta,API 可能在後續版本有 breaking changes |
9. 實戰應用場景 (Real-world Use Cases)
9.1 場景一:自動化研究助手 (Automated Research Assistant)
情境:研究團隊需要定期追蹤 AI 領域的最新論文、產業動態,並產出摘要報告。
1from strands import Agent
2from strands_tools import (
3 tavily_search, http_request, file_write,
4 calculator, think, use_agent
5)
6
7# 主 Agent:研究協調者
8research_agent = Agent(
9 tools=[tavily_search, http_request, file_write, calculator, think, use_agent],
10 system_prompt=(
11 "你是 AI 研究助手。工作流程:\n"
12 "1. 用 tavily_search 搜尋最新 AI 論文與新聞\n"
13 "2. 用 http_request 取得詳細內容\n"
14 "3. 用 think 進行深度分析\n"
15 "4. 用 file_write 產出結構化報告"
16 )
17)
18
19# 啟動研究流程
20research_agent(
21 "搜尋過去一週關於 protein language model 的最新論文和突破性進展,"
22 "分析技術趨勢,並產出一份 Markdown 研究報告存為 weekly_report.md"
23)
使用的工具鏈:tavily_search → http_request → think(3 輪分析)→ file_write
9.2 場景二:多 Agent 程式碼審查管線 (Multi-Agent Code Review Pipeline)
情境:團隊想建立自動化的程式碼審查系統,由不同專業的 Agent 分工檢查。
1from strands import Agent
2from strands_tools import graph, file_read, file_write, shell
3
4agent = Agent(tools=[graph, file_read, file_write, shell])
5
6# 建立 3 階段程式碼審查管線
7agent.tool.graph(
8 action="create",
9 graph_id="code_review",
10 topology={
11 "nodes": [
12 {
13 "id": "security_reviewer",
14 "role": "security",
15 "system_prompt": (
16 "你是安全審查專家。檢查程式碼中的 SQL injection、"
17 "XSS、hardcoded secrets、不安全的 deserialization 等漏洞。"
18 ),
19 "tools": ["file_read", "shell"]
20 },
21 {
22 "id": "performance_reviewer",
23 "role": "performance",
24 "system_prompt": (
25 "你是效能優化專家。檢查 N+1 query、記憶體洩漏、"
26 "不必要的迴圈、可並行化的操作。"
27 ),
28 "tools": ["file_read"]
29 },
30 {
31 "id": "report_writer",
32 "role": "reporter",
33 "system_prompt": (
34 "你是技術文件撰寫專家。根據安全與效能審查結果,"
35 "整理成分級(Critical / High / Medium / Low)的審查報告。"
36 ),
37 "tools": ["file_write"]
38 }
39 ],
40 "edges": [
41 {"from": "security_reviewer", "to": "report_writer"},
42 {"from": "performance_reviewer", "to": "report_writer"}
43 ],
44 "entry_points": ["security_reviewer", "performance_reviewer"]
45 }
46)
47
48# 執行審查(security 與 performance 並行 → reporter 彙整)
49agent.tool.graph(
50 action="execute",
51 graph_id="code_review",
52 task="審查 src/ 目錄下所有 Python 檔案"
53)
設計亮點:security_reviewer 與 performance_reviewer 定義為平行入口 (entry_points),兩者的輸出同時傳給 report_writer,實現並行審查 + 彙整報告。
9.3 場景三:Swarm 集體情報分析 (Swarm Intelligence for Competitive Analysis)
情境:行銷團隊需要快速分析 3 個競爭對手的產品策略。
1from strands import Agent
2from strands_tools import swarm, tavily_search, file_write
3
4agent = Agent(tools=[swarm, tavily_search, file_write])
5
6result = agent.tool.swarm(
7 task=(
8 "分析以下三家公司的 AI Agent 產品策略:\n"
9 "1. LangChain\n"
10 "2. CrewAI\n"
11 "3. AutoGen\n"
12 "每家公司需分析:產品定位、技術架構、社群規模、商業模式。"
13 "最後產出對比表格。"
14 ),
15 agents=[
16 {
17 "name": "langchain_analyst",
18 "system_prompt": "你專門分析 LangChain 的產品策略與技術架構。",
19 "tools": ["tavily_search"]
20 },
21 {
22 "name": "crewai_analyst",
23 "system_prompt": "你專門分析 CrewAI 的產品策略與技術架構。",
24 "tools": ["tavily_search"]
25 },
26 {
27 "name": "autogen_analyst",
28 "system_prompt": "你專門分析 AutoGen 的產品策略與技術架構。",
29 "tools": ["tavily_search"]
30 },
31 {
32 "name": "synthesizer",
33 "system_prompt": (
34 "你是策略分析師。收集所有分析師的研究結果,"
35 "整理成對比表格並提出策略建議。將報告寫入檔案。"
36 ),
37 "tools": ["file_write"]
38 }
39 ]
40)
Swarm 協調流程:三個分析師 Agent 各自搜尋資料後,自主判斷何時交接給 synthesizer 彙整。Swarm 的自組織特性讓 Agent 根據任務進度自主決定協作順序,無需人為指定。
附錄:完整工具清單速查表
| 類別 | 工具名稱 | 一句話說明 |
|---|---|---|
| 檔案 | file_read | 10 種模式讀取檔案(view / search / diff / time_machine 等) |
| 檔案 | file_write | 寫入檔案 |
| 檔案 | editor | 精準編輯(str_replace / insert / undo_edit) |
| 系統 | shell | 執行 Shell 命令 |
| 系統 | environment | 管理環境變數 |
| 系統 | cron | 排程 cron 任務 |
| 網路 | http_request | HTTP 請求(GET / POST 等)+ 認證 |
| 搜尋 | tavily_search / tavily_extract / tavily_crawl / tavily_map | Tavily 搜尋、擷取、爬取、地圖 |
| 搜尋 | exa_search / exa_get_contents | Exa 智慧搜尋與內容擷取 |
| 搜尋 | bright_data | 網路爬取與結構化資料擷取 |
| 記憶 | memory | Bedrock KB 記憶 |
| 記憶 | mem0_memory | Mem0 開源記憶層 |
| 記憶 | agent_core_memory | Bedrock Agent Core 記憶 |
| 記憶 | mongodb_memory | MongoDB Atlas 語義搜尋記憶 |
| 記憶 | elasticsearch_memory | Elasticsearch 語義搜尋記憶 |
| 多 Agent | use_agent | 建立子 Agent(支援跨模型) |
| 多 Agent | use_llm | 建立純 LLM 子迴圈 |
| 多 Agent | swarm | 群體智慧(自主協調) |
| 多 Agent | graph | DAG 確定性管線 |
| 多 Agent | agent_graph | Agent 關係圖視覺化 |
| 多 Agent | batch | 並行工具呼叫 |
| 多 Agent | a2a_client | A2A Protocol 跨 Agent 通訊 |
| 程式碼 | python_repl | Python 程式碼執行(含安全確認) |
| 程式碼 | code_interpreter | 沙箱程式碼執行(多語言) |
| 運算 | calculator | 符號數學運算 |
| 推理 | think | 多輪遞迴推理 |
| 媒體 | generate_image / generate_image_stability | AI 影像生成 |
| 媒體 | image_reader | 影像讀取與分析 |
| 媒體 | nova_reels | Amazon Nova 影片生成 |
| 媒體 | speak | 語音輸出(TTS) |
| 媒體 | search_video / chat_video | TwelveLabs 影片搜尋與對話 |
| 媒體 | diagram | AWS / UML / 基礎圖表 |
| 整合 | use_aws | AWS 服務操作 |
| 整合 | retrieve | Bedrock KB 檢索 |
| 整合 | mcp_client | 動態 MCP Server 連接 |
| 整合 | slack | Slack 訊息與事件 |
| 整合 | browser | Chromium 瀏覽器自動化 |
| 整合 | use_computer | 桌面自動化 |
| 整合 | load_tool | 動態載入自訂工具 |
| 整合 | rss | RSS Feed 訂閱與管理 |
| 控制 | workflow | 多步驟工作流定義與執行 |
| 控制 | handoff_to_user | 交接控制權給使用者 |
| 控制 | stop | 終止 Agent 執行 |
| 控制 | sleep | 暫停執行 |
| 控制 | current_time | 取得當前時間 |
| 控制 | journal | 結構化日誌 |
Comments