Skip to content

fix: encode kind-2 interaction models as model targets in CreateInteraction - #323

Closed
likeravine233 wants to merge 4 commits into
Mag1cFall:mainfrom
likeravine233:pr/interaction-kind2
Closed

likeravine233 wants to merge 4 commits into
Mag1cFall:mainfrom
likeravine233:pr/interaction-kind2

Conversation

@likeravine233

@likeravine233 likeravine233 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

问题

Google 将部分账户的 gemini-4 系列迁移至 Interactions 后端后,ListModels field 79 标为 [background=1, kind=2]。AIS 把 kind=2 模型也按 agent 目标编码(interaction index 18:[名称,nil,config]),上游返回 400:'gemini-4-hydrogen' refers to a model, but was provided in the 'agent' field。

证据(被迁移账户实测)

官网前端抓包:前端调用 CreateInteraction + GetInteractionStream,模型目标在 index 17:

interaction[17] = ["models/gemini-4-hydrogen", [null,null,null,null,null,4,1,65536]]
interaction[26] = [steps]
envelope      = [null,1,1,interaction,proof,1]

目录 flag 分布:[.,.,null,2](omni)走 CreateInteractionStream;[.,.,1,2](gemini-4)与 [.,.,1,1](agent)都走 CreateInteraction+GetInteractionStream——路由没错,错的只是目标编码格式。

修改内容

  • models.go:field79 kind==2 记录为 interaction_model 能力位(路由不变,background=1 仍走任务路径)
  • interaction.go 编码器:EncodeCreateInteractionRequest 按 kind 分流——kind=2 在 index 17 写 ["models/X", genConfig](genConfig 与 CreateInteractionStream 同构:thinking level / 1 / max tokens),kind=1 维持 index 18 agent 目标
  • interaction.go 终态解码:status 2(requires_action,模型输出 function call 时上游的终态)不再抛协议错误——从终态 interaction 的 steps(索引 26)递归提取 content[10] 函数调用 [name,args,id?],发 EventToolCall + finish_reason="tool_calls";status 6(incomplete)映射为 length finish
  • interaction.go tools:kind=2 目标在请求显式声明 tools 时写 interaction[7](共享 agentTools 编码器;未声明时不注入目录默认工具,与官网抓包一致)
  • service.go + 配置:新增 DISABLE_INTERACTION_MODELS(admin disable_interaction_models)——置位时 kind=2 模型不按目录标记走 interaction 路径,改与普通模型一样走 GenerateContent。拦截点在 interactionRoute,目录解析保持原样;kind=1 agent 任务不受影响。用途:任务路径配额池实测远小于 GenerateContent(见 gemini-4 全系在部分账户被标为 field79 后台任务(kind=2)后,CreateInteraction 把模型名误写入 agent 槽位被上游 400 #321 评论),且 flagged 账户实测 GenerateContent 仍被服务端接受(单账户单日样本)
  • field 53 视频输出格式仅对视频能力模型发送(原为无条件发送,非视频模型会触发上游报错)

验证

在被迁移账户(field79=[.,.,1,2])实测:gemini-4 全系(hydrogen/argon)单轮、多轮、截断全部 200,路径与官网一致(CreateInteraction + GetInteractionStream);status 2 的 502 崩溃为实测触发;DISABLE_INTERACTION_MODELS 置位后同账户 gemini-4 经 GenerateContent 返回 200(含 tool_calls)。边界:requires_action 的 call 提取与任务路径 tools 编码未在真实事件上端到端验证(该账户任务路径配额见底无法触发,见 #321 评论);GenerateContent 可用性为单账户单日样本。

关联 issue:#321、#322

@likeravine233

Copy link
Copy Markdown
Contributor Author

更新:经官网前端抓包(同一被迁移账户实测,见 #321),当前 PR 的路由修法可用但与官网行为不一致——前端实际调用 CreateInteraction + GetInteractionStream,在 interaction index 17 携带模型目标 ["models/X", genConfig](genConfig 与 CreateInteractionStream 同构)。

将把本 PR 改为编码器修复:路由不变(background=1 → 任务路径本身正确),EncodeCreateInteractionRequest 按 field79 kind 区分——kind=2 模型在 index 17 写 ["models/X", genConfig],kind=1 agent 维持 index 18 agent 目标。正在验证,稍后更新分支。

…action

Google migrated some accounts' gemini-4 models to the Interactions
backend, setting catalog field79 to [background=1, kind=2]. The website
creates these via CreateInteraction with the target at index 17 as
["models/X", genConfig] (same shape as CreateInteractionStream), then
streams via GetInteractionStream. AIS encoded kind-2 models into the
index-18 agent target, so upstream rejected with 'refers to a model,
but was provided in the agent field'.

- models.go: record field79 kind==2 as interaction_model capability
  (routing unchanged: background=1 still selects the task path)
- interaction.go: EncodeCreateInteractionRequest branches on kind —
  kind-2 models encode the model target at index 17 with a
  generation config identical to the stream path; kind-1 agents
  keep the index-18 agent target
- emit the field-53 video output format only for video-capable models
- map interaction final state 6 (incomplete) to a length finish
  instead of a protocol error

Verified on a migrated account against the website's own request
capture and live traffic: gemini-4 family single/multi-turn all 200.
@likeravine233 likeravine233 changed the title fix: 被标为后台任务的 kind=2 模型经 CreateInteractionStream 生成 fix: encode kind-2 interaction models as model targets in CreateInteraction Nov 24, 2026
Interaction final status 2 (requires_action) ends the interaction after a
function call. Decode call contents from the interaction steps and emit
EventToolCall events with a tool_calls finish reason instead of failing
with an unrecognized final state.
encodeModelInteractionTarget dropped request tools entirely so upstream
never saw function declarations. Encode them at interaction field 7 with
the shared tool encoder, only when the request declares tools.
…tent

Catalog field-79 flags mark kind=2 models for the interaction path, but
the flag is a frontend hint: GenerateContent is still accepted for these
models (verified on a flagged account), and the interaction task path
meters against a much smaller quota pool. The new config option lets
users on flagged accounts keep tool calls and normal quota via the
default path. Gate lives in interactionRoute so catalog parsing stays
faithful; kind=1 agent tasks are unaffected.
@likeravine233

Copy link
Copy Markdown
Contributor Author

背景与最新进展(给 reviewer 的上下文)

问题来源:Google 正在按账户灰度迁移 gemini-4 系列到 Interactions 后端。被标记账户的 ListModels 目录中 field 79 变为 [background, kind=2](kind=2 是这次迁移引入的新类型,此前只有 kind=1 的 deep-research/antigravity 在用 interaction 协议)。AIS 的路由本身是对的——background=1 → CreateInteraction+GetInteractionStream 任务路径、无 background → CreateInteractionStream——错在编码器把所有 interaction 模型都按 kind=1 的 agent 目标格式(index 18:[名称, nil, config])编码,上游 400:"refers to a model, but was provided in the 'agent' field"。

本 PR 的解法:忠实复刻官网前端 wire 格式,不做创造性绕过——

  1. field79 kind=2 记录为独立能力位 interaction_model,编码器按 kind 分流:kind=2 在 index 17 写 ["models/X", genConfig](genConfig 与 CreateInteractionStream 完全同构),kind=1 维持 index 18 agent 目标不变
  2. 补齐任务路径在真实使用下暴露的两个缺口:status 2(requires_action,模型输出 function call 的上游终态) 原样抛协议错误导致 502 → 现从终态 interaction steps 提取 call 发 EventToolCall;tools 声明从未写入 interaction[7] → 请求显式声明时编码(未声明不注入默认工具,与官网抓包一致)
  3. 新增 DISABLE_INTERACTION_MODELS:置位时 kind=2 模型改走 GenerateContent。动机见下

为什么需要 DISABLE_INTERACTION_MODELS(实测驱动,非推测):

  • 被标记账户上任务路径的配额池远小于 GenerateContent:约 15 次成功 CreateInteraction 后持续 429(账号停用 40 分钟后首条请求即 429、跨日配额重置点后仍 429),同账号同时段 GenerateContent 正常 200——两池独立计量
  • 同一 flagged 账户上 GenerateContent 被服务端接受并正常计量:说明目录 flag 是前端引导,后端未强制切换。对该类账户用户,钉到 GenerateContent 意味着回到正常配额 + 成熟的 tool_calls 解码路径
  • 拦截点在 interactionRoute(路由决策唯一入口),目录解析保持原样便于调试;kind=1 不受影响——agent 任务在 GenerateContent 上无法表达,没有可绕方向

验证状态(诚实边界):编码修复、requires_action 触发、429 行为、GenerateContent 可用性均为真实账户实测;requires_action 的 call 提取与任务路径 tools 编码未端到端验证(账户任务配额见底后无法触发真事件);GenerateContent 可用性为单账户单日样本,若 Google 后端转为硬拦截,本选项退化为无效但不影响默认行为。

关联调查记录:#321 评论(完整时间线与限额数据)

@Mag1cFall

Copy link
Copy Markdown
Owner

今天之内我会修完,昨天抓包后就睡觉了;然后为了方便 这个PR不会合入,但最后给你加上contributor,感谢你的PR~

@likeravine233

Copy link
Copy Markdown
Contributor Author

今天之内我会修完,昨天抓包后就睡觉了;然后为了方便 这个PR不会合入,但最后给你加上contributor,感谢你的PR~

没关系,非常感谢老大辛苦维护项目

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants