Skip to content

Commit bbc299d

Browse files
author
mb
committed
fix(agent-core-v2): align runtime resolution with IAgentLifecycleService on upstream main
1 parent 68ec502 commit bbc299d

8 files changed

Lines changed: 27 additions & 27 deletions

File tree

packages/agent-core-v2/src/agent/fullCompaction/fullCompactionService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { IAgentStateService } from '#/agent/state/agentState';
2626
import { IAgentToolRegistryService } from '#/agent/toolRegistry/toolRegistry';
2727
import { stripDynamicToolContext } from '#/agent/toolSelect/dynamicTools';
2828
import { IAgentToolSelectService } from '#/agent/toolSelect/toolSelect';
29-
import { IAgentManager } from '#/session/agentManager/agentManager';
29+
import { IAgentLifecycleService } from '#/session/agentLifecycle/agentLifecycle';
3030
import { AgentTodo, type TodoRuntime } from '#/session/todo/todoAgentRuntime';
3131
import { renderTodoList } from '#/session/todo/todoItem';
3232
import {
@@ -145,7 +145,7 @@ export class AgentFullCompactionService extends Service implements IAgentFullCom
145145
@IAgentProfileService private readonly profile: IAgentProfileService,
146146
@IAgentToolRegistryService private readonly toolRegistry: IAgentToolRegistryService,
147147
@IAgentToolSelectService private readonly toolSelect: IAgentToolSelectService,
148-
@IAgentManager private readonly manager: IAgentManager,
148+
@IAgentLifecycleService private readonly manager: IAgentLifecycleService,
149149
@IAgentScopeContext private readonly agent: IAgentScopeContext,
150150
@ITelemetryService private readonly telemetry: ITelemetryService,
151151
@IEventDispatcher private readonly dispatcher: IEventDispatcher,

packages/agent-core-v2/src/agent/tools/todo-list/todoListTool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ToolExecution } from '#/tool/toolContract';
22
import { toInputJsonSchema } from '#/tool/input-schema';
33

44
import { IAgentScopeContext } from '#/agent/scopeContext/scopeContext';
5-
import { IAgentManager } from '#/session/agentManager/agentManager';
5+
import { IAgentLifecycleService } from '#/session/agentLifecycle/agentLifecycle';
66
import { AgentTodo, type TodoRuntime } from '#/session/todo/todoAgentRuntime';
77
import {
88
TODO_LIST_TOOL_NAME,
@@ -25,7 +25,7 @@ export class TodoListTool implements ITodoListTool {
2525
readonly parameters: Record<string, unknown> = toInputJsonSchema(TodoListInputSchema);
2626

2727
constructor(
28-
@IAgentManager private readonly manager: IAgentManager,
28+
@IAgentLifecycleService private readonly manager: IAgentLifecycleService,
2929
@IAgentScopeContext private readonly scope: IAgentScopeContext,
3030
) {}
3131

packages/agent-core-v2/src/agent/userTool/userToolService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
} from '#/tool/toolContract';
1414
import { IAgentToolRegistryService } from '#/agent/toolRegistry/toolRegistry';
1515
import { IAgentStateService } from '#/agent/state/agentState';
16-
import { IAgentManager } from '#/session/agentManager/agentManager';
16+
import { IAgentLifecycleService } from '#/session/agentLifecycle/agentLifecycle';
1717
import { AgentInteraction } from '#/session/interaction/interactionAgentRuntime';
1818
import { IAgentScopeContext } from '#/agent/scopeContext/scopeContext';
1919
import { IEventDispatcher } from '#/state/eventDispatcher';
@@ -41,7 +41,7 @@ export class AgentUserToolService extends Service implements IAgentUserToolServi
4141
@IAgentScopeContext private readonly scopeContext: IAgentScopeContext,
4242
@IAgentToolRegistryService private readonly registry: IAgentToolRegistryService,
4343
@IAgentProfileService private readonly profile: IAgentProfileService,
44-
@IAgentManager private readonly manager: IAgentManager,
44+
@IAgentLifecycleService private readonly manager: IAgentLifecycleService,
4545
@IEventDispatcher private readonly dispatcher: IEventDispatcher,
4646
@IAgentStateService private readonly agentState: IAgentStateService,
4747
) {

packages/agent-core-v2/src/session/subagent/mirrorAgentRun.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { tryAgentContextOf } from '#/agent/scopeContext/scopeContext';
77
import { isProviderRateLimitError } from '#/kosong/contract/errors';
88
import { type TokenUsage } from '#/kosong/contract/usage';
99
import { ITelemetryService } from '#/app/telemetry/telemetry';
10+
import type { SubagentCreatedEvent } from '#/app/telemetry/events';
1011
import { Event2 } from '#/app/event/event2';
11-
import { IAgentManager } from '#/session/agentManager/agentManager';
12+
import { IAgentLifecycleService } from '#/session/agentLifecycle/agentLifecycle';
1213
import { IEventDispatcher } from '#/state/eventDispatcher';
1314

1415
import { type AgentRunHandle, ISessionSubagentService } from './subagent';

packages/agent-core-v2/src/session/subagent/subagentService.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { ILogService } from '#/_base/log/log';
2929
import { ISessionContext } from '#/session/sessionContext/sessionContext';
3030
import { RuntimeWorkspaceView } from '#/runtime/runtimeWorkspaceView';
3131
import { createHooks } from '#/hooks';
32-
import { IAgentManager, MAIN_AGENT_ID } from '#/session/agentManager/agentManager';
32+
import { IAgentLifecycleService, MAIN_AGENT_ID } from '#/session/agentLifecycle/agentLifecycle';
3333
import { agentContextOf } from '#/agent/scopeContext/scopeContext';
3434

3535
import {
@@ -64,7 +64,7 @@ export class SessionSubagentService extends Service implements ISessionSubagentS
6464
}
6565

6666
constructor(
67-
@IAgentManager private readonly agentManager: IAgentManager,
67+
@IAgentLifecycleService private readonly agentLifecycle: IAgentLifecycleService,
6868
@ISessionAgentProfileCatalog private readonly catalog: ISessionAgentProfileCatalog,
6969
@IConfigService private readonly configService: IConfigService,
7070
@IFlagService private readonly flags: IFlagService,
@@ -75,14 +75,14 @@ export class SessionSubagentService extends Service implements ISessionSubagentS
7575
super();
7676
}
7777

78-
async run(agent: AgentContext, request: AgentRunRequest, opts: RunAgentOptions): Promise<AgentRunHandle> {
79-
const current = this.agentManager.get(agent.agentId);
78+
run(agent: AgentContext, request: AgentRunRequest, opts: RunAgentOptions): Promise<AgentRunHandle> {
79+
const current = this.agentLifecycle.get(agent.agentId);
8080
if (current !== agent) {
8181
throw new Error2(ErrorCodes.AGENT_NOT_FOUND, `Agent "${agent.agentId}" does not exist`, {
8282
details: { agentId: agent.agentId },
8383
});
8484
}
85-
const handle = this.agentManager.handleOf(agent.agentId);
85+
const handle = this.agentLifecycle.handleOf(agent.agentId);
8686
if (handle === undefined) {
8787
throw new Error2(ErrorCodes.AGENT_NOT_FOUND, `Agent "${agent.agentId}" does not exist`, {
8888
details: { agentId: agent.agentId },
@@ -162,12 +162,12 @@ export class SessionSubagentService extends Service implements ISessionSubagentS
162162
let created: IAgentScopeHandle;
163163
try {
164164
if (plan.fork) {
165-
const forked = await this.agentManager.fork(agentContextOf(caller), {
165+
const forked = await this.agentLifecycle.fork(agentContextOf(caller), {
166166
labels: opts.labels,
167167
});
168-
created = this.agentManager.handleOf(forked.agentId)!;
168+
created = this.agentLifecycle.handleOf(forked.agentId)!;
169169
} else {
170-
const createdContext = await this.agentManager.create({
170+
const createdContext = await this.agentLifecycle.create({
171171
binding: {
172172
profile: plan.profileName,
173173
model: plan.model,
@@ -176,7 +176,7 @@ export class SessionSubagentService extends Service implements ISessionSubagentS
176176
labels: opts.labels,
177177
runtimeId: lease!.runtime.identity.runtimeId,
178178
});
179-
created = this.agentManager.handleOf(createdContext.agentId)!;
179+
created = this.agentLifecycle.handleOf(createdContext.agentId)!;
180180
}
181181
} catch (error) {
182182
throw wrapSubagentModelError(
@@ -232,7 +232,7 @@ export class SessionSubagentService extends Service implements ISessionSubagentS
232232
}
233233

234234
private requireCaller(agentId: string): IAgentScopeHandle {
235-
const handle = this.agentManager.handleOf(agentId);
235+
const handle = this.agentLifecycle.handleOf(agentId);
236236
if (handle === undefined) {
237237
throw new Error2(ErrorCodes.AGENT_NOT_FOUND, `Caller agent "${agentId}" does not exist`, {
238238
details: { agentId },

packages/agent-core-v2/test/agent/userTool/userTool.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,17 +399,17 @@ describe('AgentUserToolService (wire-backed)', () => {
399399

400400
it('resolves the current interaction runtime at execution time', async () => {
401401
let currentInteraction = createInteractionStub();
402-
const managerStub: IAgentManager = {
402+
const managerStub: IAgentLifecycleService = {
403403
resolve: () => currentInteraction,
404-
} as unknown as IAgentManager;
404+
} as unknown as IAgentLifecycleService;
405405

406406
const ixDynamic = disposables.add(new TestInstantiationService());
407407
ixDynamic.stub(IFileSystemStorageService, new InMemoryStorageService());
408408
ixDynamic.set(IAppendLogStore, new SyncDescriptor(AppendLogStore));
409409
ixDynamic.set(IAgentStateService, new AgentStateService());
410410
ixDynamic.set(IAgentToolRegistryService, new SyncDescriptor(AgentToolRegistryService));
411411
ixDynamic.stub(IAgentProfileService, createProfileStub());
412-
ixDynamic.stub(IAgentManager, managerStub);
412+
ixDynamic.stub(IAgentLifecycleService, managerStub);
413413
ixDynamic.set(IAgentUserToolService, new SyncDescriptor(AgentUserToolService));
414414
registerTestAgentWire(ixDynamic, testWireScope(SCOPE, 'user-tool-dynamic'), {
415415
log: ixDynamic.get(IAppendLogStore),

packages/agent-core-v2/test/app/skillCatalog/types.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ describe('skill/types', () => {
5555
name: 'cv_ssh-ops',
5656
description: 'SSH ops',
5757
path: '/skills/cv_ssh-ops',
58+
dir: '/skills/cv_ssh-ops',
59+
content: '',
5860
source: 'user',
5961
metadata: {
6062
type: 'prompt',
@@ -64,7 +66,7 @@ describe('skill/types', () => {
6466
groups: ['cv', 'cv/ops'],
6567
tags: ['cv', 'ssh'],
6668
},
67-
} as SkillDefinition;
69+
};
6870
expect(summarizeSkill(skill)).toEqual({
6971
name: 'cv_ssh-ops',
7072
description: 'SSH ops',

packages/agent-core-v2/test/session/subagent/spawn.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,15 +512,12 @@ describe('SessionSubagentService planSpawn and spawn', () => {
512512
expect(forkAgent).not.toHaveBeenCalled();
513513
});
514514

515-
it('rejects running a turn on a stale AgentContext', async () => {
515+
it('rejects running a turn on a stale AgentContext', () => {
516516
const svc = service();
517517
const staleContext = stubAgentContext(CALLER_ID, 0);
518518

519-
await expect(
519+
expect(() =>
520520
svc.run(staleContext, { kind: 'prompt', prompt: 'hello' }, { signal: new AbortController().signal }),
521-
).rejects.toMatchObject({
522-
code: ErrorCodes.AGENT_NOT_FOUND,
523-
message: `Agent "${CALLER_ID}" does not exist`,
524-
});
521+
).toThrow(`Agent "${CALLER_ID}" does not exist`);
525522
});
526523
});

0 commit comments

Comments
 (0)