Skip to content

🤯 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.

🐛 fix(agent-runtime): missing agentId in context (#13250)

Neko684a186e3bb5
diff --git a/src/server/modules/AgentRuntime/RuntimeExecutors.ts b/src/server/modules/AgentRuntime/RuntimeExecutors.ts
index 9ab04ab626d..edb71e7252b 100644
--- a/src/server/modules/AgentRuntime/RuntimeExecutors.ts
+++ b/src/server/modules/AgentRuntime/RuntimeExecutors.ts
@@ -976,6 +976,7 @@ export const createRuntimeExecutors = (
log(`[${operationLogId}] Executing tool ${toolName} ...`);
const executionResult = await toolExecutionService.executeTool(chatToolPayload, {
activeDeviceId: state.metadata?.activeDeviceId,
+ agentId: state.metadata?.agentId,
memoryToolPermission: agentConfig?.chatConfig?.memory?.toolPermission,
serverDB: ctx.serverDB,
toolManifestMap: effectiveManifestMap,
@@ -1192,6 +1193,7 @@ export const createRuntimeExecutors = (
const executionResult = await toolExecutionService.executeTool(chatToolPayload, {
activeDeviceId: state.metadata?.activeDeviceId,
+ agentId: state.metadata?.agentId,
memoryToolPermission: batchAgentConfig?.chatConfig?.memory?.toolPermission,
serverDB: ctx.serverDB,
toolManifestMap: batchManifestMap,
diff --git a/src/server/modules/AgentRuntime/__tests__/RuntimeExecutors.test.ts b/src/server/modules/AgentRuntime/__tests__/RuntimeExecutors.test.ts
index 06bcccf4c68..700b18b38e5 100644
--- a/src/server/modules/AgentRuntime/__tests__/RuntimeExecutors.test.ts
+++ b/src/server/modules/AgentRuntime/__tests__/RuntimeExecutors.test.ts
@@ -2089,6 +2089,42 @@ describe('RuntimeExecutors', () => {
}),
);
});
+
+ it('should pass agentId from runtime metadata to executeTool', async () => {
+ const executors = createRuntimeExecutors(ctx);
+ const state = createMockState({
+ metadata: {
+ agentId: 'agent-docs-123',
+ threadId: 'thread-123',
+ topicId: 'topic-123',
+ },
+ });
+
+ const instruction = {
+ payload: {
+ parentMessageId: 'assistant-msg-123',
+ toolsCalling: [
+ {
+ apiName: 'createDocument',
+ arguments: '{"title":"Test","content":"Hello"}',
+ id: 'tool-call-1',
+ identifier: 'lobe-agent-documents',
+ type: 'builtin' as const,
+ },
+ ],
+ },
+ type: 'call_tools_batch' as const,
+ };
+
+ await executors.call_tools_batch!(instruction, state);
+
+ expect(mockToolExecutionService.executeTool).toHaveBeenCalledWith(
+ expect.anything(),
+ expect.objectContaining({
+ agentId: 'agent-docs-123',
+ }),
+ );
+ });
});
describe('resolve_aborted_tools executor', () => {
diff --git a/src/server/services/toolExecution/types.ts b/src/server/services/toolExecution/types.ts
index 98378bb0a51..6c9c0f4ae14 100644
--- a/src/server/services/toolExecution/types.ts
+++ b/src/server/services/toolExecution/types.ts
@@ -5,6 +5,8 @@ import { type ChatToolPayload } from '@lobechat/types';
export interface ToolExecutionContext {
/** Target device ID for device proxy tool calls */
activeDeviceId?: string;
+ /** Agent ID executing the tool call */
+ agentId?: string;
/** Memory tool permission from agent chat config */
memoryToolPermission?: 'read-only' | 'read-write';
/** Server database for LobeHub Skills execution */