EVEMISSTechnology

Repository 指南 · 原始碼導讀 · v1

huggingface / smolagents · 原始碼導讀

這份導讀用四個站點帶開發者走過 smolagents repository:定位用的地標、進入點的執行追蹤、依靜態呼叫次數找出的核心函式庫模組,以及高度耦合的修改目標。所有的區塊描述和角色反映的都是分析器的靜態推論,而不是執行時的證明。

原始 repository
huggingface/smolagents
授權
Apache-2.0 · 開源授權
分析的版本 · 最後驗證
30bb1161095dbae2271e6bc3cc4c219cc3897a57 ·

原始專案有更新,但本指南引用的程式碼沒有變動。預設分支已前進到 c30b115286e0,2026-10-03 檢查。版本差異比對了 6 個變動的檔案,本指南引用的程式碼區域都沒有變動。本頁描述的仍是版本 30bb1161095d;整個 repository 的統計數字(檔案數、呼叫次數等)指的是那個版本。

本頁中文由負責的 AI 編輯依英文正式版本 v1 翻譯;程式碼名稱、路徑、行號與數字都經確定性檢查,與英文版一致。陳述與依據表保留英文原文,因為那是獨立驗證者核對過的紀錄。看英文原文

huggingface/smolagents:原始碼導讀

本頁用語說明
Entrypoint record(進入點記錄)
分析器標記為「程式可能從這裡開始執行」的檔案。附有 __main__ guard 摘錄時,表示檔案裡有 if __name__ == "__main__": 區塊,摘錄顯示它呼叫了什麼;沒有摘錄時,只是依檔名判斷。
Bounded static execution path(有界靜態執行路徑)
不執行程式、直接從原始碼重建出的呼叫鏈,走到固定步數就停。它說明在紙面上能追到多遠,不代表實際執行時會發生什麼。
Unresolved boundary(未解析邊界)
靜態路徑停下的地方:下一個呼叫進入外部函式庫,或不執行就無法確定。這是本次分析的邊界,不是 repository 的缺陷。
Static relations(靜態關係)
在原始碼中找到的呼叫與 import。「external or unresolved」表示指向分析範圍以外。
Module role(模組角色)
分析器依呼叫進出次數推論的檔案標籤(例如 core、entry/orchestration、leaf)。它描述的是在呼叫圖中的位置,不是作者的設計意圖。
Test-like files(類測試檔案)
名稱或位置看起來像測試的檔案。本次分析只計數,不執行。
Observed · inferred · author-claimed · unresolved
每句話的依據:直接讀自分析的檔案;由分析器從檔案推論;repository 作者自述(metadata、README);或本次分析無法確定。
Verified(已驗證)
本頁有兩種用法。在分析器的記錄裡(「verified provenance」「verified entrypoint」),它表示這筆記錄是直接從分析的檔案讀到的,也就是本指南所說的 observed;以進入點來說,就是檔案裡確實有 __main__ guard 的文字。分析器在 2026-10-04 修正後,只有 cli.py、main.py 這類像進入點的檔名、沒有 guard 的檔案,會記為 inferred(推測);在那之前分析的指南仍把這類檔案標成 verified,它依然只是對檔案用途的推測。它不代表程式被執行或測試過。「最後驗證」是這份指南最後一次通過本實驗室檢查的日期,檢查對象是所標示版本的分析記錄,不是對 repository 本身的審查。

怎麼使用這份導讀

這份導讀勾勒出一條有結構的閱讀順序,共四個站點:repository 的定位地標、執行路徑、核心函式庫模組,以及修改的影響範圍。指南裡引用的每一個行號範圍,都指向被分析版本 30bb1161095dbae2271e6bc3cc4c219cc3897a57 的檔案。

程式碼區塊是分析器可依行定位的語意單位,代表 module、function、class 和控制流分支這類結構區域。區塊描述和「為什麼」的註解,是靜態分析產生的推論性解讀,附帶信心評分,而不是執行時的證明。

第 1 站:定位

深入實作細節之前,先從 repository 的地標和檔案層級的區塊開始。定位課程標出了這些 module 容器:

  • examples/structured_output_tool.py:1-77:module examples/structured_output_tool.py,為被分析的原始碼檔案提供檔案層級容器(信心值 0.9)。
  • src/smolagents/cli.py:1-294:module src/smolagents/cli.py,為被分析的原始碼檔案提供檔案層級容器(信心值 0.76)。
  • src/smolagents/vision_web_browser.py:1-247:module src/smolagents/vision_web_browser.py,為被分析的原始碼檔案提供檔案層級容器(信心值 0.9)。
  • examples/open_deep_research/app.py:1-11:module examples/open_deep_research/app.py,為被分析的原始碼檔案提供檔案層級容器(信心值 0.76)。
  • examples/open_deep_research/run.py:1-125:module examples/open_deep_research/run.py,為被分析的原始碼檔案提供檔案層級容器(信心值 0.76)。
  • examples/open_deep_research/run_gaia.py:1-312:module examples/open_deep_research/run_gaia.py,為被分析的原始碼檔案提供檔案層級容器(信心值 0.76)。

第 2 站:執行的故事

接著,追蹤靜態重建出的、圍繞進入點和邊界的執行路徑。從分析器的 90 條有界路徑中,列出了五條樣本追蹤:從 examples/async_agent/main.py 出發的路徑走到 Route 和 Starlette,從 examples/open_deep_research/app.py 出發的路徑則走到 create_agent、GradioUI 和 demo.launch,全都停在未解析的邊界。

  • examples/async_agent/main.py:1-49:module examples/async_agent/main.py,為被分析的原始碼檔案提供檔案層級容器(信心值 0.76)。
  • examples/open_deep_research/app.py:10-11:main_guard __main__,控制 Python 檔案被直接執行(而不只是被 import)時應該跑的程式碼(信心值 0.99)。
  • examples/open_deep_research/app.py:1-11:module examples/open_deep_research/app.py,為被分析的原始碼檔案提供檔案層級容器(信心值 0.76)。

第 3 站:核心程式碼

分析器核心程式碼課程的 8 個區塊中,沒有一個位在函式庫程式碼裡,8 個全都在範例檔案中。因此,函式庫閱讀集是 AI Frontier 實驗室依靜態呼叫次數做的確定性挑選,不是分析器的課程。

  • 範例的核心程式碼區塊:examples/open_deep_research/app.py:10-11(main_guard __main__)、examples/agent_from_any_llm.py:43-52(function get_weather),以及 examples/multiple_tools.py 裡的函式 16-48(get_weather)、52-84(convert_currency)、88-115(get_news_headlines)、119-144(get_joke)、148-170(get_time_in_timezone)和 174-191(get_random_fact)。
  • src/smolagents/local_python_executor.py:service/core 候選,有 195 個呼入和 190 個呼出。
    • src/smolagents/local_python_executor.py:1417-1569:function evaluate_ast,封裝一個具名的操作,連到 103 條下游呼叫或 import 關係(信心值 0.76)。
    • src/smolagents/local_python_executor.py:825-918:function evaluate_call,封裝一個具名的操作,連到 48 條下游呼叫或 import 關係(信心值 0.76)。
  • src/smolagents/models.py:service/core 候選,有 60 個呼入和 66 個呼出。
    • src/smolagents/models.py:860-1135:class TransformersModel,把相關的行為歸在同一個類別邊界裡(信心值 0.99)。
    • src/smolagents/models.py:1859-2060:class AmazonBedrockModel,把相關的行為歸在同一個類別邊界裡(信心值 0.99)。
  • src/smolagents/agents.py:service/core 候選,有 16 個呼入和 80 個呼出。
    • src/smolagents/agents.py:268-1212:class MultiStepAgent,把相關的行為歸在同一個類別邊界裡(信心值 0.99)。
    • src/smolagents/agents.py:1505-1803:class CodeAgent,把相關的行為歸在同一個類別邊界裡(信心值 0.99)。
  • src/smolagents/utils.py:service/core 候選,有 56 個呼入和 8 個呼出。
    • src/smolagents/utils.py:285-373:function instance_to_source,封裝一個操作,連到 42 條下游呼叫或 import 關係(信心值 0.76)。
    • src/smolagents/utils.py:528-606:class Retrying,把相關的行為歸在同一個類別邊界裡(信心值 0.97)。

第 4 站:修改會波及哪裡

規劃修改時,請優先考慮這些區塊,因為靜態圖顯示它們周圍的耦合較強,下游的連結也很多:

  • src/smolagents/local_python_executor.py:1417-1569:function evaluate_ast,封裝一個操作,連到 103 條下游呼叫或 import 關係(信心值 0.76)。
  • src/smolagents/local_python_executor.py:1450-1569:if evaluate_ast,依一個看得到的條件在控制流路徑之間選擇(信心值 0.76)。
  • src/smolagents/local_python_executor.py:1444-1447:if evaluate_ast,依一個看得到的條件在控制流路徑之間選擇(信心值 0.76)。
  • src/smolagents/local_python_executor.py:1448-1449:straight_line evaluate_ast,把相鄰的循序陳述式歸成一個有界的區域(信心值 0.96)。
  • src/smolagents/local_python_executor.py:825-918:function evaluate_call,封裝一個操作,連到 48 條下游呼叫或 import 關係(信心值 0.76)。
  • examples/open_deep_research/scripts/text_web_browser.py:263-353:function SimpleTextBrowser._fetch_page,封裝一個操作,連到 47 條下游呼叫或 import 關係(信心值 0.76)。

這份導讀看不到的東西

這份導讀受限於靜態分析的限制和分析器的不確定性:

  • 動態行為沒有解析:靜態分析無法解析反射、執行期依賴注入、動態 import、monkey-patching、產生的程式碼、框架在執行期的接線或動態分派。
  • 指令沒有驗證:安裝、執行與建置的推論並不完整,安裝指令也沒有驗證。
  • 清單檔不完整:依賴記錄只來自 v0.10 解析的 requirements 形式清單檔,不包含 pyproject.toml 的依賴表。
  • 逐行擷取的文件陳述:README 的陳述可能抓到程式碼行而不是說明性的陳述,最多只能當作作者自述。
  • 分析器的邊界:manifest 的能力項目描述的是 RepoLumen,而不是被分析的 repository。
  • 不確定性課程:分析器指出有 6888 條靜態關係仍是未解析的外部目標,不確定性課程裡也沒有獨立的程式碼區塊。

所有的區塊說明和角色分類,都是附帶信心評分的靜態推論,而不是執行時的證明。

這次分析無法確定的事

這些是撰寫模型對分析記錄自己的說明。lim_3、exec_* 或 claim_… 這類識別碼指的是那次分析裡的記錄;陳述與依據表引用的也是同一批記錄。

  • 分析器留下 6888 條未解析或外部的靜態關係。
  • 核心程式碼課程裡沒有任何函式庫程式碼區塊,所以需要用呼叫次數的啟發式規則來挑選函式庫模組。
陳述與依據 — 26 條陳述,26 條經獨立驗證者確認(英文原文)

Every substantive statement above is a claim bound to grounding IDs of the analyzed revision. Global grounding IDs are namespaced by the analysis run.

Claim Epistemic status Verifier Grounding (global IDs)
c1 The walkthrough provides a reading order across orientation, execution story, core code, and change-guide stops for the analyzed revision. inferred supported analysis_c0e49dab7c5999ba:summary_repository
c2 Line ranges correspond to semantic blocks analyzed in revision 30bb1161095dbae2271e6bc3cc4c219cc3897a57. inferred supported analysis_c0e49dab7c5999ba:summary_repository
c3 A block is the analyzer's line-addressable semantic unit whose description and why annotations represent static inferences with confidence ratings. inferred supported analysis_c0e49dab7c5999ba:summary_repository
c4 The orientation lesson presents file-level module blocks as initial landmarks across library source files and example scripts. inferred supported analysis_c0e49dab7c5999ba:block_1e9ca140392fbb, analysis_c0e49dab7c5999ba:block_f02cafea88d687, analysis_c0e49dab7c5999ba:block_eea2df89f501eb, analysis_c0e49dab7c5999ba:block_6f6f0b6d1c2f49, analysis_c0e49dab7c5999ba:block_45cc601644f798, analysis_c0e49dab7c5999ba:block_28c0761c61205b
c5 Library landmarks in orientation include cli.py and vision_web_browser.py module containers. inferred supported analysis_c0e49dab7c5999ba:block_f02cafea88d687, analysis_c0e49dab7c5999ba:block_eea2df89f501eb
c6 Example landmarks in orientation include structured_output_tool.py, app.py, run.py, and run_gaia.py module containers. inferred supported analysis_c0e49dab7c5999ba:block_1e9ca140392fbb, analysis_c0e49dab7c5999ba:block_6f6f0b6d1c2f49, analysis_c0e49dab7c5999ba:block_45cc601644f798, analysis_c0e49dab7c5999ba:block_28c0761c61205b
c7 The execution-story lesson comprises three blocks in example files, including module containers and a direct-execution guard. inferred supported analysis_c0e49dab7c5999ba:block_d2aff49b136602, analysis_c0e49dab7c5999ba:block_460b7820df8970, analysis_c0e49dab7c5999ba:block_6f6f0b6d1c2f49
c8 Verified entrypoints exist in examples/open_deep_research/app.py and examples/async_agent/main.py. observed supported analysis_c0e49dab7c5999ba:py_entry_eb911c5c2fc4, analysis_c0e49dab7c5999ba:entry_4
c9 Five listed static execution paths start at example entrypoints and terminate at unresolved boundaries including Route, Starlette, create_agent, GradioUI, and demo.launch. inferred supported analysis_c0e49dab7c5999ba:exec_fcb626546464, analysis_c0e49dab7c5999ba:exec_4295bbf65082, analysis_c0e49dab7c5999ba:exec_5beaf01e7396, analysis_c0e49dab7c5999ba:exec_6e6d72c98a2e, analysis_c0e49dab7c5999ba:exec_9cb721a97873
c10 Zero of the 8 blocks in the core-code lesson lie in library code, with all 8 situated in example scripts. inferred supported analysis_c0e49dab7c5999ba:block_460b7820df8970, analysis_c0e49dab7c5999ba:block_f45451473fc538, analysis_c0e49dab7c5999ba:block_081041dfdbfe2a, analysis_c0e49dab7c5999ba:block_bc22c33999f05b, analysis_c0e49dab7c5999ba:block_c8c1b3685a0423, analysis_c0e49dab7c5999ba:block_d210f5e926cb90, analysis_c0e49dab7c5999ba:block_8e30e3b6e9c264, analysis_c0e49dab7c5999ba:block_69c92184efb0b3
c11 The example core blocks include a main guard in app.py and helper tool functions in agent_from_any_llm.py and multiple_tools.py. inferred supported analysis_c0e49dab7c5999ba:block_460b7820df8970, analysis_c0e49dab7c5999ba:py_func_1c4baa16ed8e, analysis_c0e49dab7c5999ba:py_func_aa15747569cb, analysis_c0e49dab7c5999ba:py_func_ef4bb992cb76, analysis_c0e49dab7c5999ba:py_func_6a1aa31c9d89, analysis_c0e49dab7c5999ba:py_func_d54247b5976b, analysis_c0e49dab7c5999ba:py_func_197c4f69930c, analysis_c0e49dab7c5999ba:py_func_e12da752344f
c12 The library reading set represents the AI Frontier lab's deterministic selection from static call degree rather than an analyzer lesson. inferred supported analysis_c0e49dab7c5999ba:role_22, analysis_c0e49dab7c5999ba:role_24, analysis_c0e49dab7c5999ba:role_18, analysis_c0e49dab7c5999ba:role_30
c13 local_python_executor.py is an inferred service/core candidate with 195 incoming and 190 outgoing calls, containing evaluate_ast and evaluate_call. inferred supported analysis_c0e49dab7c5999ba:role_22, analysis_c0e49dab7c5999ba:block_6899bc945c0fba, analysis_c0e49dab7c5999ba:block_f3a7b8f5d26753
c14 models.py is an inferred service/core candidate with 60 incoming and 66 outgoing calls, containing TransformersModel and AmazonBedrockModel. inferred supported analysis_c0e49dab7c5999ba:role_24, analysis_c0e49dab7c5999ba:block_6eff0f96143cf2, analysis_c0e49dab7c5999ba:block_5ee1f5f5b70dab
c15 agents.py is an inferred service/core candidate with 16 incoming and 80 outgoing calls, containing MultiStepAgent and CodeAgent. inferred supported analysis_c0e49dab7c5999ba:role_18, analysis_c0e49dab7c5999ba:block_2582e498705539, analysis_c0e49dab7c5999ba:block_92a499ba73e8fc
c16 utils.py is an inferred service/core candidate with 56 incoming and 8 outgoing calls, containing instance_to_source and Retrying. inferred supported analysis_c0e49dab7c5999ba:role_30, analysis_c0e49dab7c5999ba:block_c6a741b1277323, analysis_c0e49dab7c5999ba:block_dfbd2075b52015
c17 Static symbol records confirm function and class declarations for evaluate_ast, evaluate_call, TransformersModel, AmazonBedrockModel, MultiStepAgent, CodeAgent, instance_to_source, and Retrying. observed supported analysis_c0e49dab7c5999ba:py_func_48fc32624983, analysis_c0e49dab7c5999ba:py_func_5555e1787798, analysis_c0e49dab7c5999ba:py_class_7a3d7b9f3f1e, analysis_c0e49dab7c5999ba:py_class_09449356725a, analysis_c0e49dab7c5999ba:py_class_377b3e5cef4b, analysis_c0e49dab7c5999ba:py_class_7318d423d2f8, analysis_c0e49dab7c5999ba:py_func_44c37904d251, analysis_c0e49dab7c5999ba:py_class_241dc8b1dce0
c18 The change-guide lesson highlights six blocks exhibiting elevated static coupling across the python executor and an example browser script. inferred supported analysis_c0e49dab7c5999ba:block_6899bc945c0fba, analysis_c0e49dab7c5999ba:block_e2a4dedff69eeb, analysis_c0e49dab7c5999ba:block_f353f4add4f3f4, analysis_c0e49dab7c5999ba:block_cfc20611aa18a3, analysis_c0e49dab7c5999ba:block_f3a7b8f5d26753, analysis_c0e49dab7c5999ba:block_cefc1c86a7ba1b
c19 Inside local_python_executor.py, evaluate_ast connects to 103 downstream relations and contains nested if and straight-line blocks. inferred supported analysis_c0e49dab7c5999ba:block_6899bc945c0fba, analysis_c0e49dab7c5999ba:block_e2a4dedff69eeb, analysis_c0e49dab7c5999ba:block_f353f4add4f3f4, analysis_c0e49dab7c5999ba:block_cfc20611aa18a3
c20 evaluate_call in the executor and SimpleTextBrowser._fetch_page in an example script connect to 48 and 47 downstream relations respectively. inferred supported analysis_c0e49dab7c5999ba:block_f3a7b8f5d26753, analysis_c0e49dab7c5999ba:block_cefc1c86a7ba1b
c21 Static analysis cannot resolve dynamic dispatch, reflection, dynamic imports, monkey-patching, generated code, runtime dependency injection, or framework wiring. observed supported analysis_c0e49dab7c5999ba:lim_1
c22 Build and installation commands are partial inferences not verified by static analysis. observed supported analysis_c0e49dab7c5999ba:lim_2
c23 Dependencies are parsed only from requirements-style manifests, leaving pyproject.toml tables unparsed. observed supported analysis_c0e49dab7c5999ba:lim_3
c24 README extractions are line-based heuristics that should be treated as author claims at best. observed supported analysis_c0e49dab7c5999ba:lim_4
c25 Capability fields in the manifest describe the analyzer rather than repository capabilities. observed supported analysis_c0e49dab7c5999ba:lim_5
c26 All block descriptions and role assignments represent static inferences with confidence scores rather than runtime proof. inferred supported analysis_c0e49dab7c5999ba:summary_repository

來源、權利與說明 · attribution-license-templates/v0.1

權利聲明。原始 repository 託管於 GitHub。其原始碼、文件、名稱、媒體與相關素材的權利,仍屬各自的作者、貢獻者與其他權利人所有,並受該 repository 的授權條款約束。

Original repository hosted on GitHub. Repository source code, documentation, names, media, and related project materials remain subject to the rights of their respective authors, contributors, and other rights holders and to applicable repository license terms.

平台聲明。GitHub 是所連結 repository 的來源託管平台。GitHub 與相關標誌為 GitHub, Inc. 的商標。除非另有明確說明,EVEMISS Technology 與 GitHub 之間沒有隸屬或背書關係。

GitHub is the source hosting platform for the linked repository. GitHub and related marks are trademarks of GitHub, Inc. EVEMISS Technology is not affiliated with or endorsed by GitHub unless explicitly stated otherwise.

這一頁怎麼來的。本頁由對應版本的 repository 分析與 AI 輔助的編輯工具產生。技術陳述綁定所分析的版本;原始 repository 更新後,可能重新驗證。

This page was produced using revision-aware repository analysis and AI-assisted editorial tooling. Technical claims are tied to the analyzed repository revision and may be revalidated when the source repository changes.

本頁包含 AI 輔助分析,並經 EVEMISS Technology 人工與 AI 協力審閱。 · 回報權利疑慮 · 回到概覽