feat: 篇2 第11、12章正文(模型客户端 / MCP 工具)

This commit is contained in:
2026-10-20 21:48:52 +08:00
parent 0b6ead7c51
commit c7c3fda5eb
10 changed files with 291 additions and 43 deletions

View File

@@ -95,7 +95,10 @@ const maxToolCallIterations = 4</pre>
plugin *plugin.Plugin
}
func (p adkRunnerPlugin) Name() string { return p.name }
// Name 返回 ADK 插件包装器的名称.
func (p adkRunnerPlugin) Name() string {
return p.name
}
func (p adkRunnerPlugin) OnUserMessage(_ context.Context, _, _, _ string, _ ports.Agent, content model.ChatContent) error {
if p.plugin.OnUserMessageCallback() != nil {
@@ -115,7 +118,10 @@ func (p adkRunnerPlugin) BeforeAgent(_ context.Context, _, _, _ string, agent po
这就是 P1-13 记的「ADK 插件是空壳」。另一个内置插件更直接:</p>
<pre data-lang="go" data-name="internal/infrastructure/adk/adapter.go:529-546">type myTestPlugin struct{}
func (myTestPlugin) Name() string { return "myTestPlugin" }
// Name 返回插件名, 用于错误信息和日志展示.
func (myTestPlugin) Name() string {
return "myTestPlugin"
}
// OnUserMessage 在用户消息到达时打印调试信息.
func (myTestPlugin) OnUserMessage(_ context.Context, _, _, _ string, _ ports.Agent, content model.ChatContent) error {
@@ -135,7 +141,7 @@ func (myTestPlugin) BeforeAgent(_ context.Context, _, _, _ string, agent ports.A
<p>删掉 11-12 两条 import、<code>defaultPlugins</code> 里的 <code>myLogPlugin</code> 分支(488-494)、以及 548-572 整个类型,文件依旧编译,
<code>runLLM</code> / <code>streamLLM</code> / <code>Runner</code> 一个字符都不用动。所以「基于 Google ADK」这句话只在依赖清单上成立,
在运行时是站不住的。<br>
顺带一个可维护性风险:<code>go.mod</code> 里那个依赖一旦改 API,`p.plugin` 的两个 nil 判断就可能编译不过,而它对功能没有任何贡献。
顺带一个可维护性风险:<code>go.mod</code> 里那个依赖一旦改 API,<code>p.plugin</code> 的两个 nil 判断就可能编译不过,而它对功能没有任何贡献。
这种「只被当作类型标签的依赖」,升也不是、删也不是,属于典型的过早引入。</p>
</div>