fix(core): register agents before ready resolves#1245
Conversation
🦋 Changeset detectedLatest commit: 5d4715d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughAgent registration now occurs synchronously during Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/core/src/voltagent.ts (1)
132-134: Synchronous registration looks correct; consider removing now-redundantapplyDefaultWorkspaceToAgentsat line 88.With agents registered synchronously here,
registerAgentalready invokesapplyDefaultWorkspaceToAgentfor each agent (line 561), so the explicitthis.applyDefaultWorkspaceToAgents(options.agents)call inside the workspace branch (line 88) is redundant. Setting the global workspace beforeregisterAgentsis sufficient.♻️ Proposed simplification
if (options.workspace) { const workspaceInstance = options.workspace instanceof Workspace ? options.workspace : new Workspace(options.workspace); this.registry.setGlobalWorkspace(workspaceInstance); - this.applyDefaultWorkspaceToAgents(options.agents); workspaceInitPromise = workspaceInstance.init(); }You can also drop the now-unused
applyDefaultWorkspaceToAgentshelper if it has no other callers.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/voltagent.ts` around lines 132 - 134, The explicit call to applyDefaultWorkspaceToAgents inside the workspace initialization branch is redundant because registerAgents(options.agents) calls registerAgent which already runs applyDefaultWorkspaceToAgent for each agent; remove the applyDefaultWorkspaceToAgents(...) invocation (and, after removing it, search for any other callers of the helper and delete the applyDefaultWorkspaceToAgents function if it is unused) so the workspace is set globally before registerAgents and agent defaults are still applied via registerAgent/ applyDefaultWorkspaceToAgent; keep ready behavior unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/core/src/voltagent.ts`:
- Around line 132-134: The explicit call to applyDefaultWorkspaceToAgents inside
the workspace initialization branch is redundant because
registerAgents(options.agents) calls registerAgent which already runs
applyDefaultWorkspaceToAgent for each agent; remove the
applyDefaultWorkspaceToAgents(...) invocation (and, after removing it, search
for any other callers of the helper and delete the applyDefaultWorkspaceToAgents
function if it is unused) so the workspace is set globally before registerAgents
and agent defaults are still applied via registerAgent/
applyDefaultWorkspaceToAgent; keep ready behavior unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: bd8970ca-96cf-41d9-82ae-dcfc2a35baaf
📒 Files selected for processing (3)
.changeset/sync-agent-registration-before-ready.mdpackages/core/src/voltagent.spec.tspackages/core/src/voltagent.ts
Deploying voltagent with
|
| Latest commit: |
5d4715d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://cc82107f.voltagent.pages.dev |
| Branch Preview URL: | https://fix-sync-agent-registration.voltagent.pages.dev |
PR Checklist
Please check if your PR fulfills the following requirements:
Bugs / Features
What is the current behavior?
Agents provided to
new VoltAgent({ agents, workspace })are only registered during async initialization. This meansvolt.getAgent(...)can returnundefinedbeforevolt.readyresolves, and callers using the retrieved agent path can miss the expected global workspace behavior.What is the new behavior?
VoltAgent now registers agents synchronously during construction, after global defaults such as workspace are configured.
getAgentandgetAgentscan be used immediately, and retrieved agents already include inherited workspace tools/settings. Async workspace initialization is still represented byvolt.ready.fixes #1242
Notes for reviewers
Thanks to @diluka-pietra for the clear report. I reproduced this with the workspace example and also verified the LLM path from the issue: the retrieved agent can list workspace files and tools instead of responding that it has no workspace access. We should be able to include this in an upcoming patch release.
Summary by cubic
Registers agents synchronously in
@voltagent/coresogetAgentandgetAgentswork right after creating aVoltAgent. Fixes a race where callers could getundefinedor agents missing workspace defaults beforereadyresolves.readystill awaits async workspace init.ready.Written for commit 5d4715d. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
getAgentandgetAgentsmethods, eliminating the need to wait for thereadypromise to complete before retrieving agent instances.Tests