Day 20:gRPC基础 + MiMo Code初体验 - Java工程师的AI Agent学习笔记

🤖 系列:Java工程师转AI Agent 3个月学习计划

👤 作者:宸丶一 | 28岁Java程序员,正在学习 AI Agent 开发中ing...

🎯 今日目标: gRPC基础、MiMo Code体验、AI编程助手生态

💬 个人格言: 代码改不改变世界我不知道,但先让我准时下班。


前言

Day 19 搞定了记忆衰减,今天换个方向 -- gRPC + AI编程助手

说实话,之前一直没搞懂gRPC和REST到底有啥区别。这次自己写了个计算器服务,跑起来之后才明白:gRPC真的快太多了。0.42ms一次调用,比REST快了100倍,这速度让我有点震惊。

同时体验了小米的MiMo Code,第一次用AI编程助手写代码,感觉就像有个助手在旁边帮你干活,还挺爽的。


学习目标

  1. 搞懂gRPC的原理和优势
  2. 学会用Proto文件定义接口
  3. 实现gRPC服务端和客户端
  4. 体验MiMo Code,理解Agent循环
  5. 了解AI编程助手的生态

一、gRPC是什么?一句话解释

gRPC = 像调用本地函数一样调用远程服务

用Java的话说:gRPC = 远程过程调用的"终极方案"

打个比方:餐厅点餐

REST API(HTTP/1.1):

复制代码
你:(写一份菜单请求)
    "服务员,我要一份红烧肉,返回JSON格式,字段包括name、price..."
    
服务员:(去厨房等)
    ...红烧肉做好了,端给你

你:(又写一份请求)
    "再来一碗米饭"
    
服务员:(又去厨房等)
    ...米饭做好了,端给你

→ 点3个菜要跑3趟,每趟都要等

gRPC(HTTP/2):

复制代码
你:(直接说)
    "红烧肉、米饭、可乐,一起上"
    
服务员:(一趟全搞定)
    ...三个菜同时做好,一起端给你

→ 一次搞定,不用排队等

gRPC核心优势:

  • 比REST快100倍(实测0.42ms/次 vs 50-100ms/次)
  • 类型安全(Proto文件定义严格类型)
  • 跨语言支持(Python和Java能互调)

二、gRPC vs REST:核心区别

对比 REST API gRPC
数据格式 JSON(文本,人可读) Protobuf(二进制,机器可读)
传输协议 HTTP/1.1(单连接排队) HTTP/2(多路复用)
性能 较慢 快2-10倍
类型安全 弱(JSON无强制类型) 强(Proto定义严格类型)
代码生成 手动写HTTP调用代码 自动生成客户端/服务端
浏览器支持 需要gRPC-Web
跨语言 一般 原生支持

为什么gRPC快?两个原因:
#mermaid-svg-dmSEiLGSNMBNCgWZ{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-dmSEiLGSNMBNCgWZ .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-dmSEiLGSNMBNCgWZ .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-dmSEiLGSNMBNCgWZ .error-icon{fill:#552222;}#mermaid-svg-dmSEiLGSNMBNCgWZ .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-dmSEiLGSNMBNCgWZ .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-dmSEiLGSNMBNCgWZ .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-dmSEiLGSNMBNCgWZ .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-dmSEiLGSNMBNCgWZ .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-dmSEiLGSNMBNCgWZ .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-dmSEiLGSNMBNCgWZ .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-dmSEiLGSNMBNCgWZ .marker{fill:#333333;stroke:#333333;}#mermaid-svg-dmSEiLGSNMBNCgWZ .marker.cross{stroke:#333333;}#mermaid-svg-dmSEiLGSNMBNCgWZ svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-dmSEiLGSNMBNCgWZ p{margin:0;}#mermaid-svg-dmSEiLGSNMBNCgWZ .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-dmSEiLGSNMBNCgWZ .cluster-label text{fill:#333;}#mermaid-svg-dmSEiLGSNMBNCgWZ .cluster-label span{color:#333;}#mermaid-svg-dmSEiLGSNMBNCgWZ .cluster-label span p{background-color:transparent;}#mermaid-svg-dmSEiLGSNMBNCgWZ .label text,#mermaid-svg-dmSEiLGSNMBNCgWZ span{fill:#333;color:#333;}#mermaid-svg-dmSEiLGSNMBNCgWZ .node rect,#mermaid-svg-dmSEiLGSNMBNCgWZ .node circle,#mermaid-svg-dmSEiLGSNMBNCgWZ .node ellipse,#mermaid-svg-dmSEiLGSNMBNCgWZ .node polygon,#mermaid-svg-dmSEiLGSNMBNCgWZ .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-dmSEiLGSNMBNCgWZ .rough-node .label text,#mermaid-svg-dmSEiLGSNMBNCgWZ .node .label text,#mermaid-svg-dmSEiLGSNMBNCgWZ .image-shape .label,#mermaid-svg-dmSEiLGSNMBNCgWZ .icon-shape .label{text-anchor:middle;}#mermaid-svg-dmSEiLGSNMBNCgWZ .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-dmSEiLGSNMBNCgWZ .rough-node .label,#mermaid-svg-dmSEiLGSNMBNCgWZ .node .label,#mermaid-svg-dmSEiLGSNMBNCgWZ .image-shape .label,#mermaid-svg-dmSEiLGSNMBNCgWZ .icon-shape .label{text-align:center;}#mermaid-svg-dmSEiLGSNMBNCgWZ .node.clickable{cursor:pointer;}#mermaid-svg-dmSEiLGSNMBNCgWZ .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-dmSEiLGSNMBNCgWZ .arrowheadPath{fill:#333333;}#mermaid-svg-dmSEiLGSNMBNCgWZ .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-dmSEiLGSNMBNCgWZ .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-dmSEiLGSNMBNCgWZ .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-dmSEiLGSNMBNCgWZ .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-dmSEiLGSNMBNCgWZ .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-dmSEiLGSNMBNCgWZ .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-dmSEiLGSNMBNCgWZ .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-dmSEiLGSNMBNCgWZ .cluster text{fill:#333;}#mermaid-svg-dmSEiLGSNMBNCgWZ .cluster span{color:#333;}#mermaid-svg-dmSEiLGSNMBNCgWZ div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-dmSEiLGSNMBNCgWZ .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-dmSEiLGSNMBNCgWZ rect.text{fill:none;stroke-width:0;}#mermaid-svg-dmSEiLGSNMBNCgWZ .icon-shape,#mermaid-svg-dmSEiLGSNMBNCgWZ .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-dmSEiLGSNMBNCgWZ .icon-shape p,#mermaid-svg-dmSEiLGSNMBNCgWZ .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-dmSEiLGSNMBNCgWZ .icon-shape .label rect,#mermaid-svg-dmSEiLGSNMBNCgWZ .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-dmSEiLGSNMBNCgWZ .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-dmSEiLGSNMBNCgWZ .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-dmSEiLGSNMBNCgWZ :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} gRPC为什么快?
原因1: Protobuf二进制序列化
原因2: HTTP/2多路复用
JSON: 对象→文本→网络→解析→对象
Protobuf: 对象→二进制→网络→解析→对象
二进制比文本小3-5倍,解析更快
HTTP/1.1: 一个连接一个请求,排队
HTTP/2: 一个连接多个请求,并行
不用排队,效率高

性能实测:

复制代码
gRPC 100次调用:0.042秒
平均每次:0.42ms

REST API:通常50-100ms/次

→ gRPC比REST快 100-200 倍!

三、Proto文件:接口+DTO的完美结合

Proto文件是gRPC的核心,它定义了服务接口数据结构

用Java的话说:Proto文件 = Interface + DTO

Proto文件示例

protobuf 复制代码
syntax = "proto3";
package calculator;

// 数据结构(类似Java的DTO)
message CalcRequest {
    double a = 1;
    double b = 2;
}

message CalcResponse {
    double result = 1;
    string message = 2;
}

// 服务接口(类似Java的Interface)
service Calculator {
    rpc Add (CalcRequest) returns (CalcResponse);
    rpc Subtract (CalcRequest) returns (CalcResponse);
    rpc Multiply (CalcRequest) returns (CalcResponse);
    rpc Divide (CalcRequest) returns (CalcResponse);
}

Proto文件的作用:
#mermaid-svg-Re3U4Xa2Yuo65rCe{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-Re3U4Xa2Yuo65rCe .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-Re3U4Xa2Yuo65rCe .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-Re3U4Xa2Yuo65rCe .error-icon{fill:#552222;}#mermaid-svg-Re3U4Xa2Yuo65rCe .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-Re3U4Xa2Yuo65rCe .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-Re3U4Xa2Yuo65rCe .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-Re3U4Xa2Yuo65rCe .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-Re3U4Xa2Yuo65rCe .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-Re3U4Xa2Yuo65rCe .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-Re3U4Xa2Yuo65rCe .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-Re3U4Xa2Yuo65rCe .marker{fill:#333333;stroke:#333333;}#mermaid-svg-Re3U4Xa2Yuo65rCe .marker.cross{stroke:#333333;}#mermaid-svg-Re3U4Xa2Yuo65rCe svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-Re3U4Xa2Yuo65rCe p{margin:0;}#mermaid-svg-Re3U4Xa2Yuo65rCe .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-Re3U4Xa2Yuo65rCe .cluster-label text{fill:#333;}#mermaid-svg-Re3U4Xa2Yuo65rCe .cluster-label span{color:#333;}#mermaid-svg-Re3U4Xa2Yuo65rCe .cluster-label span p{background-color:transparent;}#mermaid-svg-Re3U4Xa2Yuo65rCe .label text,#mermaid-svg-Re3U4Xa2Yuo65rCe span{fill:#333;color:#333;}#mermaid-svg-Re3U4Xa2Yuo65rCe .node rect,#mermaid-svg-Re3U4Xa2Yuo65rCe .node circle,#mermaid-svg-Re3U4Xa2Yuo65rCe .node ellipse,#mermaid-svg-Re3U4Xa2Yuo65rCe .node polygon,#mermaid-svg-Re3U4Xa2Yuo65rCe .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-Re3U4Xa2Yuo65rCe .rough-node .label text,#mermaid-svg-Re3U4Xa2Yuo65rCe .node .label text,#mermaid-svg-Re3U4Xa2Yuo65rCe .image-shape .label,#mermaid-svg-Re3U4Xa2Yuo65rCe .icon-shape .label{text-anchor:middle;}#mermaid-svg-Re3U4Xa2Yuo65rCe .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-Re3U4Xa2Yuo65rCe .rough-node .label,#mermaid-svg-Re3U4Xa2Yuo65rCe .node .label,#mermaid-svg-Re3U4Xa2Yuo65rCe .image-shape .label,#mermaid-svg-Re3U4Xa2Yuo65rCe .icon-shape .label{text-align:center;}#mermaid-svg-Re3U4Xa2Yuo65rCe .node.clickable{cursor:pointer;}#mermaid-svg-Re3U4Xa2Yuo65rCe .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-Re3U4Xa2Yuo65rCe .arrowheadPath{fill:#333333;}#mermaid-svg-Re3U4Xa2Yuo65rCe .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-Re3U4Xa2Yuo65rCe .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-Re3U4Xa2Yuo65rCe .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-Re3U4Xa2Yuo65rCe .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-Re3U4Xa2Yuo65rCe .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-Re3U4Xa2Yuo65rCe .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-Re3U4Xa2Yuo65rCe .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-Re3U4Xa2Yuo65rCe .cluster text{fill:#333;}#mermaid-svg-Re3U4Xa2Yuo65rCe .cluster span{color:#333;}#mermaid-svg-Re3U4Xa2Yuo65rCe div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-Re3U4Xa2Yuo65rCe .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-Re3U4Xa2Yuo65rCe rect.text{fill:none;stroke-width:0;}#mermaid-svg-Re3U4Xa2Yuo65rCe .icon-shape,#mermaid-svg-Re3U4Xa2Yuo65rCe .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-Re3U4Xa2Yuo65rCe .icon-shape p,#mermaid-svg-Re3U4Xa2Yuo65rCe .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-Re3U4Xa2Yuo65rCe .icon-shape .label rect,#mermaid-svg-Re3U4Xa2Yuo65rCe .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-Re3U4Xa2Yuo65rCe .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-Re3U4Xa2Yuo65rCe .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-Re3U4Xa2Yuo65rCe :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} Proto文件
定义数据结构
定义服务接口
自动生成代码
类似Java的DTO
类似Java的Interface
客户端/服务端代码


四、gRPC实战:计算器服务

1. 服务端实现

python 复制代码
class CalculatorServicer(calculator_pb2_grpc.CalculatorServicer):
    def Add(self, request, context):
        result = request.a + request.b
        return calculator_pb2.CalcResponse(
            result=result,
            message=f"{request.a} + {request.b} = {result}"
        )

Java对比:

java 复制代码
// 就像实现一个Interface
public class CalculatorService implements Calculator {
    public CalcResponse add(CalcRequest request) {
        double result = request.getA() + request.getB();
        return CalcResponse.newBuilder()
            .setResult(result)
            .build();
    }
}

2. 客户端调用

python 复制代码
# 创建到服务器的连接(通道)
channel = grpc.insecure_channel('localhost:50051')

# 创建客户端存根(Stub)
stub = calculator_pb2_grpc.CalculatorStub(channel)

# 调用远程方法
response = stub.Add(calculator_pb2.CalcRequest(a=10, b=5))
print(f"结果:{response.result}")  # 15.0

3. 运行结果

复制代码
[Add]      10 + 5 = 15.0  ✅
[Subtract] 10 - 5 = 5.0   ✅
[Multiply] 10 * 5 = 50.0  ✅
[Divide]   10 / 5 = 2.0   ✅

[除零测试]
  错误: INVALID_ARGUMENT - 除数不能为零!  ✅

性能测试: 100次调用
  耗时: 0.042秒
  平均: 0.42ms/次  ⚡⚡⚡

五、MiMo Code:AI编程助手初体验

什么是MiMo Code?

小米的AI编程助手(终端版),基于MiMo-V2.5-Pro模型,支持Agent模式(自动调用工具)。

Agent循环流程

工具系统 MiMo API MiMo Code 用户 工具系统 MiMo API MiMo Code 用户 #mermaid-svg-zOifaevm0yZH291U{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-zOifaevm0yZH291U .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-zOifaevm0yZH291U .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-zOifaevm0yZH291U .error-icon{fill:#552222;}#mermaid-svg-zOifaevm0yZH291U .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-zOifaevm0yZH291U .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-zOifaevm0yZH291U .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-zOifaevm0yZH291U .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-zOifaevm0yZH291U .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-zOifaevm0yZH291U .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-zOifaevm0yZH291U .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-zOifaevm0yZH291U .marker{fill:#333333;stroke:#333333;}#mermaid-svg-zOifaevm0yZH291U .marker.cross{stroke:#333333;}#mermaid-svg-zOifaevm0yZH291U svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-zOifaevm0yZH291U p{margin:0;}#mermaid-svg-zOifaevm0yZH291U .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-zOifaevm0yZH291U text.actor>tspan{fill:black;stroke:none;}#mermaid-svg-zOifaevm0yZH291U .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-zOifaevm0yZH291U .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-zOifaevm0yZH291U .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-zOifaevm0yZH291U .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-zOifaevm0yZH291U #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-zOifaevm0yZH291U .sequenceNumber{fill:white;}#mermaid-svg-zOifaevm0yZH291U #sequencenumber{fill:#333;}#mermaid-svg-zOifaevm0yZH291U #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-zOifaevm0yZH291U .messageText{fill:#333;stroke:none;}#mermaid-svg-zOifaevm0yZH291U .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-zOifaevm0yZH291U .labelText,#mermaid-svg-zOifaevm0yZH291U .labelText>tspan{fill:black;stroke:none;}#mermaid-svg-zOifaevm0yZH291U .loopText,#mermaid-svg-zOifaevm0yZH291U .loopText>tspan{fill:black;stroke:none;}#mermaid-svg-zOifaevm0yZH291U .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-zOifaevm0yZH291U .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-zOifaevm0yZH291U .noteText,#mermaid-svg-zOifaevm0yZH291U .noteText>tspan{fill:black;stroke:none;}#mermaid-svg-zOifaevm0yZH291U .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-zOifaevm0yZH291U .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-zOifaevm0yZH291U .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-zOifaevm0yZH291U .actorPopupMenu{position:absolute;}#mermaid-svg-zOifaevm0yZH291U .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-zOifaevm0yZH291U .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-zOifaevm0yZH291U .actor-man circle,#mermaid-svg-zOifaevm0yZH291U line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-zOifaevm0yZH291U :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 重复直到没有工具调用 alt有工具调用没有工具调用 输入需求调用API返回响应执行工具返回结果把结果加入对话返回新响应输出最终结果

就像餐厅点餐:

  1. 你:我要红烧肉(用户输入)
  2. 服务员:好的(调用API)
  3. 服务员去厨房拿红烧肉(执行工具)
  4. 服务员把红烧肉端给你(结果返回)
  5. 你:再来碗米饭(继续对话)

MiMo Code的工具

工具 作用 安全性
read_file 读取文件内容 只读
write_file 写入文件 文件操作
edit_file 编辑文件 文件操作
search_code 搜索代码 只读
list_dir 列目录 只读
run_shell 执行Shell命令 命令白名单

六、AI编程助手生态

国产AI编程助手

工具 公司 模型 特点
MiMo Code 小米 MiMo 简单易用,专注MiMo模型
ZCode 智谱 GLM-5.2 国产一哥
Trae 字节 字节模型 支持 Code+Work 双模式
WorkBuddy 腾讯 ? 企业级AI助手

国际AI编程助手

工具 公司 模型 特点
OpenCode 开源社区 多模型 框架设计好,可切换模型
Codex OpenAI GPT 功能强大
Hermes Nous Research 多模型 自进化Agent,自动生成技能

国产 vs 国际

#mermaid-svg-RHnH0q21IdmUa9Pk{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-RHnH0q21IdmUa9Pk .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-RHnH0q21IdmUa9Pk .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-RHnH0q21IdmUa9Pk .error-icon{fill:#552222;}#mermaid-svg-RHnH0q21IdmUa9Pk .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-RHnH0q21IdmUa9Pk .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-RHnH0q21IdmUa9Pk .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-RHnH0q21IdmUa9Pk .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-RHnH0q21IdmUa9Pk .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-RHnH0q21IdmUa9Pk .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-RHnH0q21IdmUa9Pk .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-RHnH0q21IdmUa9Pk .marker{fill:#333333;stroke:#333333;}#mermaid-svg-RHnH0q21IdmUa9Pk .marker.cross{stroke:#333333;}#mermaid-svg-RHnH0q21IdmUa9Pk svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-RHnH0q21IdmUa9Pk p{margin:0;}#mermaid-svg-RHnH0q21IdmUa9Pk .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-RHnH0q21IdmUa9Pk .cluster-label text{fill:#333;}#mermaid-svg-RHnH0q21IdmUa9Pk .cluster-label span{color:#333;}#mermaid-svg-RHnH0q21IdmUa9Pk .cluster-label span p{background-color:transparent;}#mermaid-svg-RHnH0q21IdmUa9Pk .label text,#mermaid-svg-RHnH0q21IdmUa9Pk span{fill:#333;color:#333;}#mermaid-svg-RHnH0q21IdmUa9Pk .node rect,#mermaid-svg-RHnH0q21IdmUa9Pk .node circle,#mermaid-svg-RHnH0q21IdmUa9Pk .node ellipse,#mermaid-svg-RHnH0q21IdmUa9Pk .node polygon,#mermaid-svg-RHnH0q21IdmUa9Pk .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-RHnH0q21IdmUa9Pk .rough-node .label text,#mermaid-svg-RHnH0q21IdmUa9Pk .node .label text,#mermaid-svg-RHnH0q21IdmUa9Pk .image-shape .label,#mermaid-svg-RHnH0q21IdmUa9Pk .icon-shape .label{text-anchor:middle;}#mermaid-svg-RHnH0q21IdmUa9Pk .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-RHnH0q21IdmUa9Pk .rough-node .label,#mermaid-svg-RHnH0q21IdmUa9Pk .node .label,#mermaid-svg-RHnH0q21IdmUa9Pk .image-shape .label,#mermaid-svg-RHnH0q21IdmUa9Pk .icon-shape .label{text-align:center;}#mermaid-svg-RHnH0q21IdmUa9Pk .node.clickable{cursor:pointer;}#mermaid-svg-RHnH0q21IdmUa9Pk .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-RHnH0q21IdmUa9Pk .arrowheadPath{fill:#333333;}#mermaid-svg-RHnH0q21IdmUa9Pk .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-RHnH0q21IdmUa9Pk .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-RHnH0q21IdmUa9Pk .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-RHnH0q21IdmUa9Pk .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-RHnH0q21IdmUa9Pk .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-RHnH0q21IdmUa9Pk .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-RHnH0q21IdmUa9Pk .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-RHnH0q21IdmUa9Pk .cluster text{fill:#333;}#mermaid-svg-RHnH0q21IdmUa9Pk .cluster span{color:#333;}#mermaid-svg-RHnH0q21IdmUa9Pk div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-RHnH0q21IdmUa9Pk .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-RHnH0q21IdmUa9Pk rect.text{fill:none;stroke-width:0;}#mermaid-svg-RHnH0q21IdmUa9Pk .icon-shape,#mermaid-svg-RHnH0q21IdmUa9Pk .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-RHnH0q21IdmUa9Pk .icon-shape p,#mermaid-svg-RHnH0q21IdmUa9Pk .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-RHnH0q21IdmUa9Pk .icon-shape .label rect,#mermaid-svg-RHnH0q21IdmUa9Pk .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-RHnH0q21IdmUa9Pk .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-RHnH0q21IdmUa9Pk .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-RHnH0q21IdmUa9Pk :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 国际
国产
简单易用
国产一哥
双模式
企业级
多模型
功能强大
自进化
MiMo Code - 小米
ZCode - 智谱
Trae - 字节
WorkBuddy - 腾讯
OpenCode - 开源社区
Codex - OpenAI
Hermes - Nous Research
入门级
进阶级
专业级
终极级

对比总结:

类型 工具 特点 适合人群
入门级 MiMo Code 简单直接,专注MiMo 新手入门
进阶级 ZCode、Trae、WorkBuddy 功能更丰富 日常开发
专业级 OpenCode、Codex 多模型支持 专业开发者
终极级 Hermes 自进化,自动生成技能 深度研究

七、今日收获

知识层面

  1. gRPC的原理和优势
  2. Proto文件的作用(接口+DTO)
  3. Agent循环的基本逻辑
  4. AI编程助手的生态

技能层面

  1. 能定义Proto文件
  2. 能实现gRPC服务端和客户端
  3. 能解决端口占用、版本不匹配等常见问题
  4. 会用MiMo Code体验AI编程

思维层面

  1. "先用别人的,再研究原理,最后自己造"
  2. 工具描述要清晰完整,让Agent不会调错
  3. Agent要有循环检测和最大轮次限制

八、思考题答案

Q1:gRPC和REST的核心区别是什么?

区别 REST gRPC
数据格式 JSON(文本) Protobuf(二进制)
性能 较慢 快2-10倍
类型安全 弱(JSON无强制类型) 强(Proto定义严格类型)
代码生成 手动写 自动生成

Q2:为什么gRPC比REST快?

两个原因:

  1. Protobuf二进制序列化 -- 比JSON小3-5倍,解析快
  2. HTTP/2多路复用 -- 一个连接并发多个请求

Q3:Proto文件的作用是什么?

Proto文件 = Interface + DTO

  • 定义数据结构(类似Java的DTO)
  • 定义服务接口(类似Java的Interface)

Q4:MiMo Code的Agent循环是怎么工作的?

用户输入 → 调用API → 检查工具调用 → 执行工具 → 结果加入对话 → 重复直到完成

Q5:MiMo Code有哪些工具?

  • read_file(读文件)
  • write_file(写文件)
  • edit_file(编辑文件)
  • search_code(搜索代码)
  • list_dir(列目录)
  • run_shell(执行命令)

Q6:工具描述应该怎么写?

json 复制代码
{
    "name": "read_file",
    "description": "读取文件内容,支持文本和图片",
    "parameters": {
        "path": {
            "type": "string",
            "description": "文件路径"
        }
    }
}

关键点:清晰、完整、没有歧义

Q7:如果Agent重复调用同一个工具,应该怎么处理?

  • 设置最大轮次限制(比如8轮)
  • 实现循环检测(检测重复调用同一工具)
  • 添加超时机制

Q8:MiMo Code和OpenCode有什么区别?

对比 MiMo Code OpenCode
定位 小米的AI编程助手 开源AI编程框架
模型 只支持MiMo 支持Claude、GPT、MiMo等
语言 Python Go
特点 简单易用 功能丰富

九、明日计划

  1. 分析OpenCode的架构设计
  2. 对比MiMo Code和OpenCode的异同
  3. 尝试自己实现一个Mini版AI编程助手

十、总结

今天学了gRPC基础和MiMo Code体验,核心收获:

  1. gRPC比REST快100倍 -- 实测0.42ms/次
  2. Proto文件 = Interface + DTO -- 定义接口和数据结构
  3. Agent循环 -- 用户输入 → API → 工具调用 → 结果 → 重复
  4. AI编程助手生态 -- MiMo Code、OpenCode、ZCode、Trae等

一句话总结: gRPC让Agent调用Java服务更快,MiMo Code让AI编程更简单。


📝 小小腾老师的评分

维度 得分 评价
gRPC掌握程度 ⭐⭐⭐⭐ 能独立实现,但HTTP/2原理还需要深入
Proto文件理解 ⭐⭐⭐⭐ 掌握了核心,但自动生成代码的原理还没学
MiMo Code体验 ⭐⭐⭐⭐⭐ 会用工具,理解了Agent循环
思考题完成 ⭐⭐⭐⭐ 75分,大部分理解,少部分需要补充
实践能力 ⭐⭐⭐⭐⭐ 代码跑通,问题解决能力强
学习态度 ⭐⭐⭐⭐⭐ 遇到不会的诚实说,不瞎编

总分:75分(良好)

老师说: 今天的实践能力很强,代码都跑通了,问题也解决了。理论理解还需要加强,特别是gRPC的底层原理。明天继续加油!


💡 学习心得: 先用别人的,再研究原理,最后自己造

🎯 明日目标: OpenCode源码分析

📅 学习进度: Day 20/35(57%完成)


下一篇: Day 21:OpenCode架构分析 - 学习AI编程框架的设计思路