Skip to content

fix(core): register agents before ready resolves#1245

Merged
omeraplak merged 1 commit into
mainfrom
fix/sync-agent-registration-before-ready
Apr 25, 2026
Merged

fix(core): register agents before ready resolves#1245
omeraplak merged 1 commit into
mainfrom
fix/sync-agent-registration-before-ready

Conversation

@omeraplak

@omeraplak omeraplak commented Apr 25, 2026

Copy link
Copy Markdown
Member

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 means volt.getAgent(...) can return undefined before volt.ready resolves, 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. getAgent and getAgents can be used immediately, and retrieved agents already include inherited workspace tools/settings. Async workspace initialization is still represented by volt.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/core so getAgent and getAgents work right after creating a VoltAgent. Fixes a race where callers could get undefined or agents missing workspace defaults before ready resolves.

  • Bug Fixes
    • Register agents during construction after applying global defaults; ready still awaits async workspace init.
    • Added tests to ensure retrieved agents include workspace and tools before ready.

Written for commit 5d4715d. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes

    • Agents are now immediately available after initialization via getAgent and getAgents methods, eliminating the need to wait for the ready promise to complete before retrieving agent instances.
  • Tests

    • Added test coverage for agent retrieval and default tool configuration verification.

@changeset-bot

changeset-bot Bot commented Apr 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5d4715d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@voltagent/core Patch

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

@coderabbitai

coderabbitai Bot commented Apr 25, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Agent registration now occurs synchronously during VoltAgent construction instead of being deferred until the ready promise completes, making agents immediately available via getAgent and getAgents with global defaults applied.

Changes

Cohort / File(s) Summary
Changeset Documentation
.changeset/sync-agent-registration-before-ready.md
New changeset entry documenting patch release for @voltagent/core marking agent registration as synchronous during construction.
Test Additions
packages/core/src/voltagent.spec.ts
Added assertion verifying that getAgent returns the preconstructed agent instance with expected workspace and default tools (ls, read_file, execute_command, workspace_search).
Agent Registration Refactoring
packages/core/src/voltagent.ts
Moved agent registration from finalizeInit (inside async ready flow) to constructor initialization, while keeping trigger registration and server initialization in finalizeInit.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Hop! Registration's swift and bright,
No more waiting—agents ready quite!
In the constructor's gentle care,
Global defaults now always there.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(core): register agents before ready resolves' clearly summarizes the main change: making agent registration synchronous so it happens before the ready promise resolves.
Linked Issues check ✅ Passed The changes fully address issue #1242: agents now registered synchronously during construction with global defaults applied, enabling getAgent/getAgents to return agents with workspace tools/settings immediately.
Out of Scope Changes check ✅ Passed All changes are scoped to issue #1242: synchronous agent registration in voltagent.ts, corresponding tests in voltagent.spec.ts, and changeset documentation—no extraneous modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description includes all required sections from the template with substantive content: completed checklist, clear explanation of current vs. new behavior, linked issue reference, and reviewer notes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sync-agent-registration-before-ready

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ghost

This comment has been minimized.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/core/src/voltagent.ts (1)

132-134: Synchronous registration looks correct; consider removing now-redundant applyDefaultWorkspaceToAgents at line 88.

With agents registered synchronously here, registerAgent already invokes applyDefaultWorkspaceToAgent for each agent (line 561), so the explicit this.applyDefaultWorkspaceToAgents(options.agents) call inside the workspace branch (line 88) is redundant. Setting the global workspace before registerAgents is 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 applyDefaultWorkspaceToAgents helper 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0b793d9 and 5d4715d.

📒 Files selected for processing (3)
  • .changeset/sync-agent-registration-before-ready.md
  • packages/core/src/voltagent.spec.ts
  • packages/core/src/voltagent.ts

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying voltagent with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5d4715d
Status: ✅  Deploy successful!
Preview URL: https://cc82107f.voltagent.pages.dev
Branch Preview URL: https://fix-sync-agent-registration.voltagent.pages.dev

View logs

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

@omeraplak omeraplak merged commit 99c201b into main Apr 25, 2026
24 checks passed
@omeraplak omeraplak deleted the fix/sync-agent-registration-before-ready branch April 25, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] global settings doesn't apply to agents which get from voltagent

1 participant