React Agent与MCP

2025年的今天,大语言模型的能力早已不再限于chatbot(只会聊天),各家模型都在文本预测的基础上扩展LLM的能力,例如Structured Outputs(结构化输出),Function calling(函数调用),MCP(模型上下文协议),同时,有人提出一种结合LLM思考与行动的协同机制-React。 React Agent 通过让LLM循环执行 推理(Reasoning)->行动(Action)->观察(Observation) 来完成任务。 本质上,可以用下面这段最小代码解释: 1for { 2 response := callLLM(context) 3 if response.ToolCalls { 4 context = executeTools(response.ToolCalls) 5 } 6 if response.Finished { return } 7} ReAct: Synergizing Reasoning and Acting in Language Models eino-React实现 Function calling LLM自身训练的结构化输出能力以及通过openai-api服务实现,让LLM能够按照指定格式输出json格式的数据,来表明自己需要去使用什么函数,参数是什么,同时支持流式生成。 例如: 之后你应该在输入的messages里面加入除user,assistant的另一个角色,名为tool,tool的content内容为函数调用结果,至于函数是如何调用,LLM和openai-api服务并不参与,由开发者执行。此时再次对话,LLM会根据上下文中函数调用结果生成回答。 openai-function-calling MCP MCP (Model Context Protocol)是一种开放协议,用于标准化应用程序如何向大型语言模型(LLMs)提供上下文。可以将 MCP 想象为 AI 应用的 typec 接口。正如 typec 提供了一种标准化的方式将您的设备连接到各种外设和配件,MCP 也提供了一种标准化的方式,将 AI 模型连接到不同的数据源和工具。 ...

July 22, 2025

用GO+Ebiten写一个飞机大战

Ebitengine介绍 Ebitengine (旧称 Ebiten) 是一款由Go 语言开发的开源游戏引擎。Ebitengine 的简单 API 可以让您的 2D 游戏开发更加简单快捷,并支持同时发布到多平台。 安装 1$ go get -u github.com/hajimehoshi/ebiten/v2 示例代码 1// Game implements ebiten.Game interface. 2type Game struct{} 3 4// Update proceeds the game state. 5// Update is called every tick (1/60 [s] by default). 6func (g *Game) Update() error { 7 // Write your game's logical update. 8 return nil 9} 10 11// Draw draws the game screen. 12// Draw is called every frame (typically 1/60[s] for 60Hz display). 13func (g *Game) Draw(screen *ebiten.Image) { 14 // Write your game's rendering. 15} 16 17// Layout takes the outside size (e.g., the window size) and returns the (logical) screen size. 18// If you don't have to adjust the screen size with the outside size, just return a fixed size. 19func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) { 20 return 320, 240 21} 22 23func main() { 24 game := &Game{} 25 // Specify the window size as you like. Here, a doubled size is specified. 26 ebiten.SetWindowSize(640, 480) 27 ebiten.SetWindowTitle("Your game's title") 28 // Call ebiten.RunGame to start your game loop. 29 if err := ebiten.RunGame(game); err != nil { 30 log.Fatal(err) 31 } 32} 框架结构 从上面的示例代码可以看出,Ebitengine的使用十分简单,我们只需要一个实现ebiten.Game这个接口的对象,将其传入RunGame即可。 ...

April 6, 2023