Skip to content

Commit 99c201b

Browse files
authored
fix(core): register agents before ready resolves (#1245)
1 parent 0b793d9 commit 99c201b

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@voltagent/core": patch
3+
---
4+
5+
Register agents synchronously during VoltAgent construction so getAgent and getAgents can return agents with global defaults before ready resolves.

packages/core/src/voltagent.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ describe("VoltAgent defaults", () => {
8282
expect.arrayContaining(["ls", "read_file", "execute_command", "workspace_search"]),
8383
);
8484

85+
const retrievedAgent = voltAgent.getAgent("assistant");
86+
expect(retrievedAgent).toBe(agent);
87+
expect(retrievedAgent?.getWorkspace()).toBe(workspace);
88+
expect(retrievedAgent?.getTools().map((tool) => tool.name)).toEqual(
89+
expect.arrayContaining(["ls", "read_file", "execute_command", "workspace_search"]),
90+
);
91+
8592
await voltAgent.ready;
8693
await voltAgent.shutdown();
8794
});

packages/core/src/voltagent.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ export class VoltAgent {
129129
// Setup graceful shutdown handlers
130130
this.setupShutdownHandlers();
131131

132+
// Register agents synchronously so getAgent/getAgents can be used immediately after construction.
133+
// Workspace defaults are applied before registration; workspace initialization is still awaited by ready.
134+
this.registerAgents(options.agents);
135+
132136
const finalizeInit = () => {
133-
// ✅ NOW register agents - they can access global telemetry exporter
134-
this.registerAgents(options.agents);
135137
this.registerTriggers(options.triggers);
136138

137139
// Register workflows if provided

0 commit comments

Comments
 (0)