<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shem Yu on Medium]]></title>
        <description><![CDATA[Stories by Shem Yu on Medium]]></description>
        <link>https://medium.com/@shemyu?source=rss-21873f5519c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6-4qCorH49eWhHgx</url>
            <title>Stories by Shem Yu on Medium</title>
            <link>https://medium.com/@shemyu?source=rss-21873f5519c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 02:59:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shemyu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AI Agent 專案架構最佳實踐]]></title>
            <link>https://medium.com/@shemyu/ai-agent-%E5%B0%88%E6%A1%88%E6%9E%B6%E6%A7%8B%E6%9C%80%E4%BD%B3%E5%AF%A6%E8%B8%90-8d8613fde368?source=rss-21873f5519c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d8613fde368</guid>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[google-adk]]></category>
            <category><![CDATA[project-structure]]></category>
            <dc:creator><![CDATA[Shem Yu]]></dc:creator>
            <pubDate>Sun, 20 Apr 2025 15:13:52 GMT</pubDate>
            <atom:updated>2025-04-20T15:13:52.251Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1boNDVORayxOep1FZBB5Zw.png" /></figure><p>為了解專案架構最佳實踐，針對大廠 solution 進行全面調研：</p><ol><li><a href="https://www.anthropic.com/engineering/claude-code-best-practices">Claude Code Best Practice</a> : Claude Code 使用的最佳實踐手冊</li><li><a href="https://github.com/huggingface/smolagents">Hugging Face smolagents</a> : Hugging Face 自產的 agent 專案，參考架構</li><li><a href="https://github.com/qx-labs/agents-deep-research">qx-labs agents-deep-research</a> : 開發社群友情推薦 agent 專案</li><li><a href="https://github.com/mannaandpoem/OpenManus/tree/main/app">OpenManus</a> : 知名 agent 專案，參考架構</li></ol><h3>Claude Code Best Practice</h3><p>透過 CLAUDE.md 對專案進行客製化的定義，限制發散性強的 Agent LLM 統一專案的：</p><ol><li>開發風格</li><li>常用的 bash command</li><li>核心專案架構</li><li>測試的方式（統一測試架構）</li><li>naming practice</li><li>虛擬環境定義</li><li>其他你想客製化定義（用以限制發散性）</li></ol><p>CLAUDE.md 如同 system prompt 需要 tuning，因此需要在使用過程中持續優化，必要時推薦使用 <a href="https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/prompt-improver#improved-prompt">Prompt Improver</a> 一款 Claude 官方出的提示詞優化工具進行優化。</p><p>文件主要討論如何在使用 Claude Code 常見的一些問題上進行修正，<strong>並非專案最佳實踐架構</strong>，更貼近如何讓 Claude Code 開發時更貼近過往專案開發成果，避免專案不一致降低可讀性。</p><h3>HuggingFace smolagents</h3><p>專案架構較為扁平，tree:</p><pre>smolagents/<br>└── src/smolagents/<br>    ├── prompts/                   # yaml based prompt 模板<br>    ├── __init__.py<br>    ├── _function_type_hints_utils.py  # function 簽名/類型以及轉換相關工具<br>    ├── agent_types.py            # Agent 相關 Data Class 定義<br>    ├── agents.py                 # Core Agent Class：MultiStepAgent、ToolCallingAgent、CodeAgent<br>    ├── cli.py                    # CLI 功能定義<br>    ├── default_tools.py          # SmolAgents 預設的工具包<br>    ├── gradio_ui.py              # Gradio Web UI<br>    ├── local_python_executor.py  # python executor + Exceptions + etc...<br>    ├── mcp_client.py             # 簡易 MCP Client 類別定義<br>    ├── memory.py                 # 記憶管理相關 Data Class, Class 定義<br>    ├── models.py                 # 模型抽象層，標準化各種來源模型介面<br>    ├── monitoring.py             # 結合記憶的 logger 設計<br>    ├── remote_executors.py       # 基於 python executor 實踐各種包括容器內的 python executor<br>    ├── tool_validation.py        # tool 檢查<br>    ├── tools.py                  # Tool based Class<br>    ├── utils.py                  # 通用小工具<br>    └── vision_web_browser.py     # CV based 的網頁瀏覽工具</pre><p>架構優勢：</p><ol><li>扁平、簡單、易懂</li><li>扁平，但功能模組仍切割清晰</li><li>yaml based 的 prompt 設計，基礎又簡單</li></ol><p>缺陷：</p><ol><li>最初設計時應該沒有這麼雜亂，但隨著越來越多協定產生，架構顯得雜亂</li><li>ui, cli 等使用者介面與核心功能混雜，可讀性糟</li><li>缺少配置相關資訊，沒有明確進入點</li></ol><h3>qx-labs/agents-deep-research</h3><p>專案架構稍有模組化，但屬於較小規模專案。</p><pre>.<br>├── deep_researcher/            # 核心模組<br>│   ├── __init__.py<br>│   ├── deep_research.py        # DeepResearcher 主流程<br>│   ├── iterative_research.py   # IterativeResearcher 主流程<br>│   ├── llm_config.py           # LLM 配置管理<br>│   ├── main.py                 # CLI 入口<br>│   ├── agents/                 # Agent 相關定義，以及 Root Agent 實作<br>│   │   ├── __init__.py<br>│   │   ├── baseclass.py        <br>│   │   ├── knowledge_gap_agent.py<br>│   │   ├── long_writer_agent.py<br>│   │   ├── planner_agent.py<br>│   │   ├── proofreader_agent.py<br>│   │   ├── thinking_agent.py<br>│   │   ├── tool_selector_agent.py<br>│   │   ├── writer_agent.py<br>│   │   └── tool_agents/        # Sub Agent 實作<br>│   │       └── ...<br>│   ├── tools/                  # Tools 實作<br>│   │   ├── __init__.py<br>│   │   ├── crawl_website.py<br>│   │   └── web_search.py<br>│   └── utils/                  # 小工具<br>│       ├── __init__.py<br>│       ├── markdown.css<br>│       ├── md_to_pdf.py<br>│       └── os.py</pre><p>架構優勢：</p><ol><li>第一層級功能模組分離清晰：agents, tools, utils，協作上各司其職，保持單一職責原則</li><li>agents 進入點明確，root , sub agent(tool agent) 架構清晰，可讀性高</li></ol><p>缺陷：</p><ol><li>tools 並未引用 MCP 架構，無明確切分 prompt, data resource 以及 tools</li><li>agents 模組層級過淺，導致 root agent 雜亂</li></ol><h3>OpenManus</h3><p>當初 <strong>Manus</strong> 很火的時候，隔天馬上出現的 <strong>OpenManus</strong>。專案架構定義上很有自己的風格，將模組區分為六大類且保持單一職責，一層的模組深度讓專案整體可讀性上升，共用模組保留頂層且有效抽象配置，並且透過 pydantic 實作的 schema.py 做到簡易清晰的資料驗證。</p><pre>.<br>app/<br>├── agent/             # 各類 Agent 實作<br>├── flow/              # 任務或工作流程管理<br>├── mcp/               # 多功能執行（MCP）相關<br>├── prompt/            # Prompt 範本與管理<br>├── sandbox/           # 沙箱執行環境<br>├── tool/              # 各種工具封裝<br>├── __init__.py        # 套件初始化<br>├── bedrock.py         # Amazon Bedrock 介面<br>├── config.py          # 全域與 LLM 配置<br>├── exceptions.py      # 自訂例外定義<br>├── llm.py             # LLM 呼叫封裝<br>├── logger.py          # 日誌與監控設定<br>└── schema.py          # 資料模型／驗證規範</pre><p>架構優勢：</p><p>不小心都寫在上面了，剛好照著順序調研下來，這個專案的架構是我個人認為當中最靠近 Clean Code 原則且易讀性高的。</p><ol><li>模組切分明確，保持單一職責原則</li><li>專案可讀性高，易於測試、維護</li><li>有效抽象配置</li><li>明確的資料 Schema 驗證、定義</li></ol><p>缺陷：</p><ol><li>部分模組仍過於扁平，可以進一步模組化</li><li>部分模組定義與大廠定義不同，如 MCP 協定相關收整了 prompt tools 等</li></ol><h3>總結</h3><p>基於 MCP 提出的 tools, resource, prompt 以及 Google ADK 保留 multi-agent on single server 以及 A2A 作為跨伺服器溝通協定的架構，最後綜合基於調研來的成果（偷起來）保留以下優點：</p><ol><li>所有專案都保持了單一職責分離的良好設計</li><li>依照用例配置分層</li><li>可擴展性、插件式入口設計</li><li>命名明確且保持一致性增加可讀性</li><li>單向依賴、最小耦合，不會 import 自己當前所在模組內容</li></ol><pre>prjt-myagent/<br>├── .env                   # 根級環境變數（全局設定）<br>├── .env.sample            <br>├── .gitignore             <br>├── Makefile               # 常用指令<br>├── README.md              <br>├── pyproject.toml         <br>├── setup.py               <br>├── pytest.ini             <br>├── uv.lock                # uv 套件鎖定檔<br>│<br>├── myagent/               # 核心程式庫<br>│   ├── __init__.py        <br>│   │<br>│   ├── agents/            # Agent 應用入口 &amp; 環境設定 基於 Google ADK<br>│   │   ├── sub_agent/.    # 子 Agent<br>│   │   ├── .env           # Agent 專屬環境變數<br>│   │   ├── .env.example   <br>│   │   ├── __init__.py<br>│   │   └── agent.py       # 定義 UI Agent 啟動程式<br>│   │<br>│   ├── core/              # 核心功能區塊<br>│   │   ├── README.md      # core 模組說明<br>│   │   ├── __init__.py<br>│   │   ├── crawler/       # 各種爬蟲實作（如網站、API）<br>│   │   ├── feature_engineering/  # 特徵工程、數據轉換<br>│   │   └── notion/        # Notion API 整合<br>│   │<br>│   ├── mcp/               # MCP Server &amp; CLI<br>│   │   ├── __init__.py<br>│   │   ├── main.py        # 啟動 MCP Server 服務<br>│   │   ├── prompts/       # MCP 專用 Prompt 範本<br>│   │   ├── resources/     # 靜態資源（模板、文件等）<br>│   │   └── tools/         # MCP 可註冊的工具實作<br>│   │<br>│   ├── models/            # 資料結構定義<br>│   │   ├── README.md      <br>│   │   ├── __init__.py<br>│   │   ├── feed.py        # Feed 物件 schema<br>│   │   └── notion.py      # Notion 物件 schema<br>│   │<br>│   └── utils/             # 共用小工具與設定<br>│       ├── __init__.py<br>│       ├── logger.py<br>│       └── config.py      # 全局程式配置讀寫<br>│<br>├── examples/              # 使用範例程式碼<br>│   └── …<br>│<br>└── tests/                 # 單元測試 &amp; 整合測試<br>    └── …</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d8613fde368" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[容器化技術]Podman的初體驗]]></title>
            <link>https://medium.com/@shemyu/%E5%AE%B9%E5%99%A8%E5%8C%96%E6%8A%80%E8%A1%93-podman%E7%9A%84%E5%88%9D%E9%AB%94%E9%A9%97-f85cc07beff6?source=rss-21873f5519c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f85cc07beff6</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[container-security]]></category>
            <category><![CDATA[rootless]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[podman]]></category>
            <dc:creator><![CDATA[Shem Yu]]></dc:creator>
            <pubDate>Tue, 27 Sep 2022 03:36:05 GMT</pubDate>
            <atom:updated>2022-09-27T03:36:05.323Z</atom:updated>
            <content:encoded><![CDATA[<p>最近因緣際會接觸了，由提供企業級 Linux 作業系統（Enterprise Linux）的 Red Hat 所開發，據說可以無痛轉移的容器化技術 Podman。</p><p><a href="https://podman.io/">Podman</a></p><h3>What is Podman?</h3><p>Podman 如上所述其實與 Docker 同為容器化技術，相較於 Docker 最大的區別就是 Daemonless（也可說 Rootless），因此有更嚴謹的權限控管，提升了安全性。</p><p>根據官方文件開門見山地告訴你，他可以做到 rootless（當然也可以 root），而甚至 alias docker=pdoman 就可以無痛體驗 podman 帶給你的容器化技術體驗。</p><blockquote>What is Podman? Podman is a daemonless container engine for developing, managing, and running OCI Containers on your Linux System. Containers can either be run as root or in rootless mode. Simply put: alias docker=podman. More details <a href="https://podman.io/whatis.html">here</a>.</blockquote><p>但真的這麼容易嗎？以下開始分享我使用的相關經驗，也順便做個筆記。</p><h3>Installation</h3><p>以 MacOS（本人使用 Macbook 進行開發）來比較，安裝 Podman 可以透過 brew 指令簡單的安裝、初始化並啟動。</p><p><a href="https://podman.io/getting-started/installation">Podman</a></p><pre>$ brew install podman<br>$ podman machine init<br>$ podman machine start<br>$ podman info</pre><blockquote>小主觀環節&gt; 相較於先前嘗試不透過 docker desktop 去安裝 docker，甚至跳過 docker daemon 的我，真的覺得這部分比較之下簡單了一些，更不用說如果你是 Windows。</blockquote><h3>Basic CLI</h3><p>基礎的指令真的如官方文件聲稱的一般，如果你是一位熟悉 docker 指令的使用者，那對於 podman 指令真的是無痛入門。</p><p>相關指令也不多做贅述，附上文檔。</p><p><a href="https://docs.podman.io/en/latest/Commands.html">Podman</a></p><h3>常見問題篇</h3><p>這邊主要是我想分享或筆記的部分，為未來踩到相關狀況的我或其他人，留下一點點幫助。</p><h4>there might not be enough IDs available in the namespace</h4><p>首先是 rootless 引申出的權限問題，使用 root 下的體驗與 docker 相去無異，但是如果你跟我一樣是個權限菜雞，那可能在 rootless 模式下會遇到與我相同的瓶頸。</p><p>最初我是在遠端主機下使用 podman pull &lt;image&gt; 時遇到問題。</p><pre>ERRO[0000] cannot find mappings for user &lt;user_name&gt;: No subuid ranges found for user &quot;&lt;user_name&gt;&quot; in /etc/subuid</pre><p>對於習慣 root 的 docker 使用者，第一次看到 uid, subuid 真的腦袋中只有「Ｏ小」的感覺。所以這邊就順便帶過這次稍微學習到的容器化技術基本概念，容器化技術在 Linux 環境下就是透過 UID/GID 等數值搭配系統上的 /etc/passwd, /etc/group 等數值配對出該運行角色為何種身份。</p><p>甚至 uid 的大小順序也是有意義的，以 Centos6 為例子：</p><pre>UID=0 # root<br>UID &gt;= 500 # 一般用戶<br>0 &lt; UID &lt; 500 # 虛擬使用者</pre><p>因此我們回到上面的錯誤，該錯誤指出在 rootless 模式下使用 podman 指令，是需要執行指令使用者在 /etc/subuid（/etc/subgid 也是）下有配置好 subuid, subgid ranges 的。</p><p>官方文件當中有以 RHEL（Red Hat Enterprise Linux）做舉例，幫大家總結為以下幾點：</p><ol><li>rootless 模式下一定要為你調用 podman 之使用者，手動配置 subuid/subgid</li><li>配置 subuid/subgid：rootless 之 UID/GID 不能在 range 範圍當中</li><li>配置 subuid/subgid：range 之間彼此不得交集</li><li>配置 subuid/subgid：建議每個 user 最大配置 65536 subuid/subgid</li><li>配置 subuid/subgid：起始 UID/GID 不要低於 1000</li><li>配置 subuid/subgid：建議可以重複使用已經存在的 user 及其 UID/GID</li></ol><blockquote>Upgrade to rootless containers<br>If you have upgraded from RHEL 7, you must configure subuid and subgid values manually for any existing user you want to be able to use rootless podman.</blockquote><blockquote>Using an existing user name and group name (for example, jill), set the range of accessible user and group IDs that can be used for their containers. Here are a couple of warnings:</blockquote><blockquote>Don’t include the rootless user’s UID and GID in these ranges<br>If you set multiple rootless container users, use unique ranges for each user<br>We recommend 65536 UIDs and GIDs for maximum compatibility with existing container images, but the number can be reduced<br>Never use UIDs or GIDs under 1000 or reuse UIDs or GIDs from existing user accounts (which, by default, start at 1000)</blockquote><blockquote>Here is an example:</blockquote><blockquote># echo “jill:165537:65536” &gt;&gt; /etc/subuid<br># echo “jill:165537:65536” &gt;&gt; /etc/subgid<br>The user/group jill is now allocated 65535 user and group IDs, ranging from 165537–231072. That user should be able to begin running commands to work with containers now.</blockquote><h3>結語</h3><p>Podman rootless 模式確實的避免了 Docker root 權限所隱含的安全性問題， 但 rootless 也隱含了不少學習成本在，雖然指令可以無痛學習，但我想對於開發者來說遇到問題解決的精神依舊，小菜鳥在這下台一鞠躬。</p><h3>Reference</h3><ul><li><a href="https://zhuanlan.zhihu.com/p/504265733">开源容器 Podman 常用命令总结！</a></li><li><a href="https://blog.csdn.net/byygyy/article/details/105740029">CentOS8使用podman常见错误解决_比永远更永远的博客-CSDN博客</a></li><li><a href="https://ithelp.ithome.com.tw/articles/10227969">[Day29] Container Security - iT 邦幫忙::一起幫忙解決難題，拯救 IT 人的一天</a></li><li><a href="https://www.twblogs.net/a/5f03a6ff0b1faa3719590b8a">Linux中的UID、GID和SID</a></li><li><a href="https://podman.io/">Podman</a></li><li><a href="https://ithelp.ithome.com.tw/articles/10238749">Podman 淺談 - 為何你應該選擇 Podman 而不是 Docker？ - iT 邦幫忙::一起幫忙解決難題，拯救 IT 人的一天</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f85cc07beff6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>