Kaga Blog

Notes on engineering, systems, and learning.

AI:Advanced Tool Use

Advanced Tool Use 来源:https://www.anthropic.com/engineering/advanced-tool-use 图示 Tool Search Tool 对比图(Context Usage: Traditional vs. Tool Search Tool) Programmatic Tool Calling 流程图(Programmatic Tool Calling Flow) 核心要点 整体目标:解决三个老问题 工具太多:定义太长,把上下文挤爆 链路太长:工具链一长,来回调用慢且耗 tokens 仅靠 Schema 不够:只有 JSON Schema 时,模型仍会经常填错参数/用错工具 Tool Search Tool(工具搜索): 不再一次性把几十上百个工具定义全部塞进上下文,而是只提前加载一个“搜索工具 + 少数高频工具”。当 Claude 需要某类能力时,先用搜索工具按名字/描述去检索,再按需把少量匹配工具的定义展开进上下文。 收益:减少 token 开销(官方示例:上下文消耗可降低 80%+),同时降低“选错工具”的概率 适用:MCP 多服务、工具数量 10+ 的场景 Programmatic Tool Calling(编程式工具调用): 以前是“自然语言 → 一次推理 → 调一个工具 → 结果全丢回模型上下文”,多步流程就意味着多次推理 + 大量中间数据灌进上下文。现在改成:Claude 写一段 Python 脚本,在沙盒里 orchestrate 工具调用(循环、并发、条件分支都写在代码里),工具结果先在代码里处理,最后只把“结论”返回给 Claude。 收益:大数据场景下只让模型看到汇总结果,而不是几 MB 的原始日志;显著省 tokens、降延迟,也更不容易“算错账” Tool Use Examples(工具使用示例):...

December 21, 2025

AI:评估AI Agent的上下文压缩策略

评估AI Agent的上下文压缩策略 执行摘要 长会话超出上下文窗口会让AI Agent丢失关键信息。Factory.ai为此构建了基于探针的评估框架,用来衡量不同上下文压缩策略的“功能质量”。对比Factory、OpenAI与Anthropic三种方法,Factory的“锚定迭代式摘要”在保留技术细节上最佳:通过持续维护并增量合并结构化摘要,在准确性与上下文感知上领先,说明结构比单纯的压缩率更决定任务成败。 1. 核心问题:长对话中的上下文丢失 AI Agent在调试、代码审查或功能实现等复杂任务中,会产生数百万Token的对话历史,远超模型上下文窗口。激进压缩常导致代理遗忘关键信息(如改动过的文件、已尝试的方案),从而反复读取、重复探索。 研究指出,优化目标不应是“单次请求的Token数”(tokens per request),而应是“完成任务所需的总Token数”(tokens per task)。更高质量的上下文保留能减少返工,进而降低总消耗。 2. 评估框架:基于探针的功能性质询 传统摘要指标(如ROUGE或嵌入相似度)无法回答关键问题:压缩后的上下文还能否支撑代理继续工作。Factory.ai因此设计探针评估:向压缩后的代理提问必须依赖具体历史细节的问题,以直接衡量其功能质量。 探针类型 该框架使用四种探针,覆盖不同维度的信息保留: 探针类型 测试内容 示例问题 回忆(Recall) 事实性信息的保留 “最初的错误信息是什么?” 工件(Artifact) 文件追踪 “我们修改了哪些文件?描述每个文件的变化。” 延续(Continuation) 任务规划 “我们下一步该做什么?” 决策(Decision) 推理链 “我们针对Redis问题讨论了哪些方案,最终决定是什么?” 评估维度 由LLM裁判(GPT-5.2)按六个维度评分(0-5分),面向软件开发场景: 准确性 (Accuracy): 技术细节(如文件路径、函数名)是否正确。 上下文感知 (Context Awareness): 响应是否反映了当前的对话状态。 工件追踪 (Artifact Trail): 代理是否知道哪些文件被读取或修改过。 完整性 (Completeness): 响应是否解决了问题的所有部分。 连续性 (Continuity): 工作能否在不重新获取信息的情况下继续。 指令遵循 (Instruction Following): 响应是否遵循了格式或约束要求。 3. 三种压缩策略对比 研究评估了三种生产级的压缩策略: Factory:锚定迭代式摘要 (Anchored Iterative Summarization) 机制: 维护一个包含明确分区(如会话意图、文件修改、决策)的持久化结构性摘要。当需要压缩时,仅对新截断的对话部分进行摘要,并将其合并到现有摘要中。 核心洞察: 结构强制保留。通过为特定信息类型设置专门的区域,可以防止关键细节(如文件路径)在自由形式的摘要中被无声地丢弃。 OpenAI:不透明压缩端点(/responses/compact) 机制: 生成面向重建保真度的不透明压缩表示。...

December 21, 2025

English:N+1 的复利

三大马车之一–English:N+1 的复利 English 这个世界上90%的信息都是 written in English 的。 可理解性输入 南加州大学的荣休教授斯蒂芬•克拉申(Stephen D.Krashen)博士的假说理论 罗肖尼 https://m.bilibili.com/video/BV1aD4y127GE 阅读篇 词汇积累 如何永久的记住一个单词? 推荐 medium https://medium.com/ 听力篇 精听 听写 Daily Dictation https://dailydictation.com/ 泛听 Podcast 通勤路上听,健身时候听 口语篇 AI 口语教练 付费版: ChatGPT通话模式 免费版: Pi https://pi.ai/discover 真人口语老师 性价比版: pdd 菲教 高价版: Cambly 欧美外教 口语练习 Elsa Speak AI 语音技术,发音纠正 个性化学习,大量的课程 实用性强,日常对话场景,职场英语训练 写作篇 积累自己的语料库 句乐部:https://julebu.co 改变 观看纯英文字幕的Youtube、Netflix 视频, 无字幕理解计算机科学领域内的英文视频, 阅读英文版技术博客、书籍。 雅思阅读均分:8.0 听力均分:7.0 Tips 把英文当成工具: 最好的情况下不是学习英文,而是使用英文学习自己喜欢的东西。 N+1 原则 学英语和健身中都隐含一种“难度分级”的方法。把当前自身能够做到的程度再加一点点难度,作为目标(N+1,踮踮脚能够到)。 比如学英语中的“做大量有趣的可理解输入”,对应到健身上可以叫“做大量有趣的可承受训练”: 与当前水平相匹配的那个难度,就像一个钩子(hook)。找到那个hook,走向更精进的地方。 细想一下,其实我们从小学到大学的课程分级,本身就是在帮我们做难度的「分级」。 联想:遇到问题时,尝试「目标拆解」、「分类」,找到合适的 N+1。

November 11, 2024

Fitness:N+1 的复利

三大马车之一–Fitness:N+1 的复利 Fitness 训练概况 微习惯 从徒手训练到健身房 新手上路,从观看健身视频开始, 实战类, 详细动作教程:凯圣王 https://m.bilibili.com/space/2100737396 日常类, 健身经验分享:烧毁一切就是美 https://m.bilibili.com/space/1024129080 理论类, 健身知识科普:仰望尾迹云 https://m.bilibili.com/space/1879203169 训练思路 数量 x 重量 = 训练容量 追求质量,放下虚荣心,比如卧推触胸、引体向上肩膀下回旋 简单的动作做高级 补剂 辨别智商税 关键因素

November 11, 2024

Docker

Docker Guidelines Dockerfile Best Practices Use Official Base Images Why: Official images are maintained and frequently updated, ensuring reliability and security. How: FROM node:14-alpine Minimize Image Size Why: Smaller images lead to faster deployments and reduced storage costs. How: Use minimal base images (e.g., Alpine Linux). Remove unnecessary packages and files. Combine commands to reduce layers. RUN apt-get update && \ apt-get install -y package1 package2 && \ rm -rf /var/lib/apt/lists/* Leverage Caching Why: Utilizing Docker’s layer caching speeds up builds....

October 15, 2024

Kubernetes

Introduction Kubernetes (k8s) is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. Kubernetes Architecture Masters The master node manages the Kubernetes cluster. It coordinates all activities, such as scheduling, scaling, and updating applications. Components: API Server: The front-end of the Kubernetes control plane. etcd: A distributed key-value store for configuration data. Controller Manager: Manages controllers that handle routine tasks. Scheduler: Assigns workloads to nodes based on resource availability and policies....

October 15, 2024

Lua

Introduction to Lua Lua is a powerful, efficient, lightweight, embeddable scripting language. It is designed to be embedded in other applications, providing flexibility and extensibility. Lua is widely used in game development, embedded systems, web applications, and more due to its simple syntax, fast execution, and ease of integration. What is Lua? Key Features Lightweight and Fast: Lua is designed to have a small footprint and execute rapidly, making it ideal for performance-critical applications....

October 15, 2024

Nginx

Introduction to Nginx Nginx (pronounced as “Engine-X”) is a high-performance, open-source web server, reverse proxy server, and email (IMAP/POP3) proxy server. What is Nginx? Key Features High Performance: Ability to handle thousands of concurrent connections with minimal memory footprint. Reverse Proxying: Acts as an intermediary for requests from clients seeking resources from servers. Load Balancing: Distributes incoming traffic across multiple servers to ensure reliability and uptime. SSL/TLS Support: Provides secure connections using SSL/TLS protocols....

October 15, 2024

Openresty

Introduction to OpenResty OpenResty is a dynamic web platform that integrates Nginx with the powerful Lua scripting language. It is designed to build scalable web applications, web services, and dynamic web gateways. By combining the high performance of Nginx with the flexibility of Lua, OpenResty enables developers to handle complex processing at the edge of the network. What is OpenResty? OpenResty extends Nginx by bundling it with a set of powerful Lua libraries and modules (known as LuaJIT)....

October 15, 2024

Go's Common Data Structures

1. Strings Strings in Go are immutable sequences of bytes, typically used to represent UTF-8 encoded text. Structure type stringStruct struct { str unsafe.Pointer len int } Memory Layout stringStruct +----------------+ | str (uintptr) | ---> [byte array] | len (int) | +----------------+ Detailed Implementation Creation When a string literal is used, the compiler allocates the bytes in read-only memory. Runtime string creation (e.g., string concatenation) allocates new memory and copies bytes....

October 11, 2024