🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(agent-runtime): preserve Gemini 3 thoughtSignature in call_tools_batch normalization (#14032)
Arvin Xu3b306a8aed40
diff --git a/packages/agent-runtime/src/core/__tests__/runtime.test.ts b/packages/agent-runtime/src/core/__tests__/runtime.test.tsindex 9932cb44039..62bd17109b0 100644--- a/packages/agent-runtime/src/core/__tests__/runtime.test.ts+++ b/packages/agent-runtime/src/core/__tests__/runtime.test.ts@@ -1172,6 +1172,59 @@ describe('AgentRuntime', () => {expect(result.nextContext?.payload).toHaveProperty('toolCount', 3);});+ // Regression test for LOBE-7759: Gemini 3 thoughtSignature must survive the+ // OpenAI ToolsCalling -> ChatToolPayload normalization in call_tools_batch,+ // otherwise Gemini 3 400s on the second tool_call turn.+ it('should preserve thoughtSignature when normalizing call_tools_batch ToolsCalling payload', async () => {+ const signature = 'EoMYCoAYA_gemini3_thought_signature_fixture';++ class ThoughtSignatureAgent implements Agent {+ tools = {+ gemini_tool: vi.fn().mockResolvedValue({ result: 'ok' }),+ };++ async runner(context: AgentRuntimeContext, _state: AgentState) {+ if (context.phase === 'user_input') {+ return {+ payload: [+ {+ function: { arguments: '{}', name: 'gemini_tool' },+ id: 'call_gemini_1',+ thoughtSignature: signature,+ type: 'function' as const,+ },+ ],+ type: 'call_tools_batch' as const,+ };+ }+ return { type: 'finish' as const, reason: 'completed' as const };+ }+ }++ // Intercept normalized call_tools_batch to capture the ChatToolPayload handed downstream.+ let capturedToolsCalling: ChatToolPayload[] | undefined;+ const agent = new ThoughtSignatureAgent();+ const runtime = new AgentRuntime(agent, {+ executors: {+ call_tools_batch: async (instruction: any, state: AgentState) => {+ capturedToolsCalling = instruction.payload.toolsCalling;+ return { events: [], newState: state };+ },+ },+ });++ const state = AgentRuntime.createInitialState({+ operationId: 'thought-signature-test',+ messages: [{ role: 'user', content: 'Call Gemini 3 tool' }],+ });++ await runtime.step(state);++ expect(capturedToolsCalling).toHaveLength(1);+ expect(capturedToolsCalling![0].thoughtSignature).toBe(signature);+ expect(capturedToolsCalling![0].apiName).toBe('gemini_tool');+ });+it('should support agent returning instruction array', async () => {// Agent that returns array of instructionsclass ArrayReturnAgent implements Agent {diff --git a/packages/agent-runtime/src/core/runtime.ts b/packages/agent-runtime/src/core/runtime.tsindex aae5d53769f..c4e168c0026 100644--- a/packages/agent-runtime/src/core/runtime.ts+++ b/packages/agent-runtime/src/core/runtime.ts@@ -140,6 +140,7 @@ export class AgentRuntime {arguments: tc.function.arguments,id: tc.id,identifier: tc.function.name,+ thoughtSignature: tc.thoughtSignature,type: 'default' as any,}));diff --git a/packages/agent-runtime/src/types/state.ts b/packages/agent-runtime/src/types/state.tsindex 09df85e834d..ffd59521314 100644--- a/packages/agent-runtime/src/types/state.ts+++ b/packages/agent-runtime/src/types/state.ts@@ -155,6 +155,12 @@ export interface ToolsCalling {name: string; // A JSON string of arguments};id: string;+ /**+ * Gemini 3.x thought signature, captured from `functionCall.thoughtSignature` in the+ * streaming response. Must be round-tripped back in subsequent requests or Gemini will+ * 400 with a misleading "ordering" error. Optional; only set for Gemini 3.x tool calls.+ */+ thoughtSignature?: string;type: 'function';}