<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Python on 大飞的博客</title>
    <link>https://www.dafei.me/tags/python/</link>
    <description>Recent content in Python on 大飞的博客</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    <lastBuildDate>Tue, 02 Jun 2026 10:00:00 +0000</lastBuildDate>
    <atom:link href="https://www.dafei.me/tags/python/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>源码分析（一）：Netflix Headroom 是怎么把 LLM 账单砍掉一半的</title>
      <link>https://www.dafei.me/posts/oss-01-headroom/</link>
      <pubDate>Tue, 02 Jun 2026 10:00:00 +0000</pubDate>
      <guid>https://www.dafei.me/posts/oss-01-headroom/</guid>
      <description>&lt;p&gt;最近看到一个叫 &lt;strong&gt;Headroom&lt;/strong&gt; 的项目，Netflix 高级工程师 Tejas Chopra 个人开源的，号称能帮你把发给 LLM 的 token 减少 30-70%，而且不丢信息。&lt;/p&gt;
&lt;p&gt;我把源码读了一遍，发现里面有几个设计很有意思，记下来。&lt;/p&gt;
&lt;p&gt;项目地址：https://github.com/chopratejas/headroom&lt;/p&gt;
&lt;p&gt;本文分析的主要源文件：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/chopratejas/headroom/blob/main/headroom/transforms/content_router.py&#34;&gt;&lt;code&gt;headroom/transforms/content_router.py&lt;/code&gt;&lt;/a&gt; — 内容识别与路由&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/chopratejas/headroom/blob/main/headroom/transforms/content_detector.py&#34;&gt;&lt;code&gt;headroom/transforms/content_detector.py&lt;/code&gt;&lt;/a&gt; — 内容类型检测&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/chopratejas/headroom/tree/main/crates/headroom-core/src/transforms/smart_crusher&#34;&gt;&lt;code&gt;crates/headroom-core/src/transforms/smart_crusher/&lt;/code&gt;&lt;/a&gt; — SmartCrusher Rust 实现&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/chopratejas/headroom/blob/main/crates/headroom-core/src/transforms/log_compressor.rs&#34;&gt;&lt;code&gt;crates/headroom-core/src/transforms/log_compressor.rs&lt;/code&gt;&lt;/a&gt; — 日志压缩 Rust 实现&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/chopratejas/headroom/blob/main/headroom/transforms/cache_aligner.py&#34;&gt;&lt;code&gt;headroom/transforms/cache_aligner.py&lt;/code&gt;&lt;/a&gt; — CacheAligner&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/chopratejas/headroom/blob/main/headroom/ccr/tool_injection.py&#34;&gt;&lt;code&gt;headroom/ccr/tool_injection.py&lt;/code&gt;&lt;/a&gt; — CCR 工具注入&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;它解决的是什么问题&#34;&gt;它解决的是什么问题&lt;/h2&gt;
&lt;p&gt;你在用 Claude 或 GPT 做 agent 的时候，工具调用（tool call）的返回结果会吃掉大量 token。&lt;/p&gt;
&lt;p&gt;比如你让 agent 查数据库，返回了 500 条记录，每条有 15 个字段。但其中 12 个字段在所有记录里都是完全相同的值，真正有用的只有 3 个字段。你把 500 × 15 的数据全塞给 LLM，它实际只需要 500 × 3。&lt;/p&gt;
&lt;p&gt;这就是浪费。Headroom 做的事，就是在你把数据发给 LLM 之前，先把这些废话压掉。&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
