Skip to content

Commit 96b939f

Browse files
authored
feat(core): Introduce AgentLoopContext. (#21198)
1 parent 7837194 commit 96b939f

File tree

14 files changed

+196
-66
lines changed

14 files changed

+196
-66
lines changed

packages/a2a-server/src/utils/testing_utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ export function createMockConfig(
7575
validatePathAccess: vi.fn().mockReturnValue(undefined),
7676
...overrides,
7777
} as unknown as Config;
78+
79+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
80+
(mockConfig as unknown as { config: Config; promptId: string }).config =
81+
mockConfig;
82+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
83+
(mockConfig as unknown as { config: Config; promptId: string }).promptId =
84+
'test-prompt-id';
85+
7886
mockConfig.getMessageBus = vi.fn().mockReturnValue(createMockMessageBus());
7987
mockConfig.getHookSystem = vi
8088
.fn()

packages/core/src/agents/agent-scheduler.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('agent-scheduler', () => {
3030
} as unknown as Mocked<ToolRegistry>;
3131
mockConfig = {
3232
getMessageBus: vi.fn().mockReturnValue(mockMessageBus),
33-
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
33+
toolRegistry: mockToolRegistry,
3434
} as unknown as Mocked<Config>;
3535
});
3636

@@ -69,6 +69,6 @@ describe('agent-scheduler', () => {
6969

7070
// Verify that the scheduler's config has the overridden tool registry
7171
const schedulerConfig = vi.mocked(Scheduler).mock.calls[0][0].config;
72-
expect(schedulerConfig.getToolRegistry()).toBe(mockToolRegistry);
72+
expect(schedulerConfig.toolRegistry).toBe(mockToolRegistry);
7373
});
7474
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import type { GeminiClient } from '../core/client.js';
8+
import type { MessageBus } from '../confirmation-bus/message-bus.js';
9+
import type { ToolRegistry } from '../tools/tool-registry.js';
10+
11+
/**
12+
* AgentLoopContext represents the execution-scoped view of the world for a single
13+
* agent turn or sub-agent loop.
14+
*/
15+
export interface AgentLoopContext {
16+
/** The unique ID for the current user turn or agent thought loop. */
17+
readonly promptId: string;
18+
19+
/** The registry of tools available to the agent in this context. */
20+
readonly toolRegistry: ToolRegistry;
21+
22+
/** The bus for user confirmations and messages in this context. */
23+
readonly messageBus: MessageBus;
24+
25+
/** The client used to communicate with the LLM in this context. */
26+
readonly geminiClient: GeminiClient;
27+
}

0 commit comments

Comments
 (0)