Skip to content

fix(core): apply global workspace to registered agents#1228

Merged
omeraplak merged 1 commit intomainfrom
fix/global-workspace-default
Apr 23, 2026
Merged

fix(core): apply global workspace to registered agents#1228
omeraplak merged 1 commit intomainfrom
fix/global-workspace-default

Conversation

@omeraplak
Copy link
Copy Markdown
Member

@omeraplak omeraplak commented Apr 23, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

Agents constructed before new VoltAgent({ workspace }) do not inherit the global workspace. This means workspace toolkits are missing unless the workspace is passed directly to the Agent constructor.

What is the new behavior?

VoltAgent now applies the configured global workspace to registered agents that did not explicitly configure a workspace. This adds the workspace toolkits, preserves explicit workspace: false, and keeps workspace defaults such as maxSteps.

fixes #1227

Notes for reviewers

Reproduced in examples/with-workspace: before the fix the agent had workspace missing and only currentDate; after the fix it has the workspace id and the expected workspace tools.

Validation run:

  • pnpm --filter @voltagent/core test:single -- src/voltagent.spec.ts src/workspace/index.spec.ts
  • pnpm --filter @voltagent/core typecheck
  • pnpm --filter @voltagent/core build
  • pnpm --dir examples/with-workspace build
  • pnpm biome check .changeset/global-workspace-default.md packages/core/src/agent/agent.ts packages/core/src/voltagent.ts packages/core/src/voltagent.spec.ts

Summary by cubic

Fixes agents created before registration not inheriting the global workspace. Registered agents without an explicit workspace now get workspace defaults and toolkits. Fixes #1227 in @voltagent/core.

  • Bug Fixes
    • Apply global workspace to preconstructed agents that didn’t set one.
    • Preserve explicit workspace settings, including workspace: false.
    • Add workspace toolkits (and tool routing pool when enabled).
    • Set default maxSteps (100) and apply the workspace skills prompt hook when applicable.

Written for commit 6b2552f. Summary will update on new commits.

Summary by CodeRabbit

  • New Features
    • Agents created without an explicit workspace now automatically inherit workspace configuration from their parent VoltAgent, including when created before registration.
    • Default maximum steps automatically configured to 100 for agents using inherited workspace settings, reducing manual configuration overhead.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 23, 2026

🦋 Changeset detected

Latest commit: 6b2552f

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

@joggrbot

This comment has been minimized.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

📝 Walkthrough

Walkthrough

This pull request implements automatic propagation of global workspace defaults to agents created before registration. When a VoltAgent is constructed with a workspace, it now applies that workspace to pre-existing agents via a new __setDefaultWorkspace method, enabling agents to access workspace-derived toolkits and skills without explicit workspace configuration at construction time.

Changes

Cohort / File(s) Summary
Changeset Configuration
.changeset/global-workspace-default.md
Documents a patch release for @voltagent/core marking the feature to apply global workspace defaults to agents.
Agent Workspace Configuration
packages/core/src/agent/agent.ts
Adds state tracking for workspace configuration (workspaceConfigured, toolkitOptions, promptOptions, hook/maxSteps flags) and introduces __setDefaultWorkspace method to retroactively apply workspace, recompute prompt resolution hooks, and register workspace toolkits. Refactors workspace hook resolution to accept narrower type signature.
VoltAgent Workspace Application
packages/core/src/voltagent.ts
Adds helper methods (applyDefaultWorkspaceToAgent, applyDefaultWorkspaceToAgents) to fetch and conditionally apply global workspace to agents. Constructor now propagates workspace to pre-existing agents, and registerAgent applies default workspace alongside existing defaults.
Integration Tests
packages/core/src/voltagent.spec.ts
Expands registry reset logic to clear workspace and tool routing state. Introduces new VoltAgent defaults test validating that agents inherit global workspace, default maxSteps, and workspace-derived tools post-registration.

Sequence Diagram

sequenceDiagram
    participant User
    participant VoltAgent
    participant Agent
    participant Workspace
    participant Registry

    User->>Agent: new Agent({ tools: [...] })
    User->>VoltAgent: new VoltAgent({ agents, workspace })
    VoltAgent->>Workspace: Initialize workspace
    VoltAgent->>Registry: Fetch workspace from registry
    VoltAgent->>Agent: applyDefaultWorkspaceToAgent()
    Agent->>Agent: __setDefaultWorkspace(workspace)
    Agent->>Agent: Set workspace, update maxSteps
    Agent->>Agent: Recompute onPrepareMessages hook
    Agent->>Agent: Register workspace toolkits
    VoltAgent->>VoltAgent: Complete initialization
    User->>Agent: generateText(prompt)
    Agent->>Agent: Access workspace tools via onPrepareMessages
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • feat: expose workspace context #1052: Exposes and forwards workspace in Agent's operation context and tool execution, complementing this PR's workspace propagation at initialization.
  • feat: add voltagent-level memory #967: Introduces registry-backed global defaults pattern with __setDefaultX internal methods on Agent, establishing the architectural pattern extended here for workspace defaults.

Poem

🐰 A rabbit's ode to workspace harmony:

When agents dance before their stage is set,
The workspace whispers what they can't forget,
With tools and skills now flowing through their veins,
No registration fret, just shared domains! 🌿✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: applying global workspace to registered agents, matching the core objective of the pull request.
Description check ✅ Passed The description comprehensively covers all required template sections, including current/new behavior, linked issues, tests, changesets, and validation steps.
Linked Issues check ✅ Passed The pull request successfully addresses issue #1227 by implementing workspace application to agents, adding workspace toolkits and defaults as required.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the global workspace issue: agent workspace configuration tracking, workspace application logic, and comprehensive test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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/global-workspace-default

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

981-1008: Prefer private backing state over widening public mutability.

hooks and maxSteps appear mutable only so __setDefaultWorkspace can update internal defaults. Keeping public getters with private backing fields would preserve the previous read-only API shape and avoid consumers mutating values without updating constructor-time flags like maxStepsConfigured/configuredHooks. As per coding guidelines, Maintain type safety in TypeScript-first codebase.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/agent/agent.ts` around lines 981 - 1008, The fields hooks
and maxSteps should be made private-backed (e.g., private _hooks and private
_maxSteps) and exposed via public getters so external code cannot mutate them
directly; update the constructor to initialize the private backing fields and
change any access sites to use the getters, then modify __setDefaultWorkspace to
assign the backing fields (setting configuredHooks and maxStepsConfigured as it
already does) instead of mutating the public properties; ensure references to
configuredHooks and maxStepsConfigured remain correct and remove or rename the
original public mutable fields (hooks, maxSteps) so the public API remains
read-only while internal defaults can still be updated via the private backing
fields.
packages/core/src/voltagent.spec.ts (1)

62-87: Add coverage for the explicit workspace opt-out path.

This regression covers inherited global workspace, but the PR also needs to preserve agents constructed with workspace: false. A small companion assertion would protect that behavior from regressing.

Suggested test addition
   it("applies workspace to preconstructed registered agents without explicit workspace", async () => {
     const workspace = new Workspace({ id: "global-workspace" });
     const agent = new Agent({
       name: "assistant",
       instructions: "Be helpful.",
       model: "openai/gpt-4o-mini",
     });
+    const optOutAgent = new Agent({
+      name: "no-workspace",
+      instructions: "Be helpful.",
+      model: "openai/gpt-4o-mini",
+      workspace: false,
+    });

     expect(agent.getWorkspace()).toBeUndefined();
     expect(agent.getTools()).toHaveLength(0);

     const voltAgent = new VoltAgent({
-      agents: { assistant: agent },
+      agents: { assistant: agent, noWorkspace: optOutAgent },
       workspace,
       checkDependencies: false,
     });

     expect(agent.getWorkspace()).toBe(workspace);
     expect(agent.maxSteps).toBe(100);
     expect(agent.getTools().map((tool) => tool.name)).toEqual(
       expect.arrayContaining(["ls", "read_file", "execute_command", "workspace_search"]),
     );
+    expect(optOutAgent.getWorkspace()).toBeUndefined();
+    expect(optOutAgent.getTools().map((tool) => tool.name)).not.toEqual(
+      expect.arrayContaining(["ls", "read_file", "execute_command", "workspace_search"]),
+    );

     await voltAgent.ready;
     await voltAgent.shutdown();
   });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/voltagent.spec.ts` around lines 62 - 87, Add a test case
that verifies an agent constructed with an explicit workspace opt-out keeps
workspace unset after being passed into VoltAgent: create a second Agent with
workspace: false (e.g., new Agent({ name: "outsider", ..., workspace: false })),
include it in the VoltAgent constructor alongside the existing agent and global
Workspace, then assert that outsider.getWorkspace() remains undefined while the
other preconstructed agent still inherits the global Workspace; reference the
existing VoltAgent, Agent, and Workspace usage in the spec to locate where to
add this assertion.
🤖 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/agent/agent.ts`:
- Around line 981-1008: The fields hooks and maxSteps should be made
private-backed (e.g., private _hooks and private _maxSteps) and exposed via
public getters so external code cannot mutate them directly; update the
constructor to initialize the private backing fields and change any access sites
to use the getters, then modify __setDefaultWorkspace to assign the backing
fields (setting configuredHooks and maxStepsConfigured as it already does)
instead of mutating the public properties; ensure references to configuredHooks
and maxStepsConfigured remain correct and remove or rename the original public
mutable fields (hooks, maxSteps) so the public API remains read-only while
internal defaults can still be updated via the private backing fields.

In `@packages/core/src/voltagent.spec.ts`:
- Around line 62-87: Add a test case that verifies an agent constructed with an
explicit workspace opt-out keeps workspace unset after being passed into
VoltAgent: create a second Agent with workspace: false (e.g., new Agent({ name:
"outsider", ..., workspace: false })), include it in the VoltAgent constructor
alongside the existing agent and global Workspace, then assert that
outsider.getWorkspace() remains undefined while the other preconstructed agent
still inherits the global Workspace; reference the existing VoltAgent, Agent,
and Workspace usage in the spec to locate where to add this assertion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d4680422-f583-4644-86b5-df40bced7ae8

📥 Commits

Reviewing files that changed from the base of the PR and between f658e9f and 6b2552f.

📒 Files selected for processing (4)
  • .changeset/global-workspace-default.md
  • packages/core/src/agent/agent.ts
  • packages/core/src/voltagent.spec.ts
  • packages/core/src/voltagent.ts

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 4 files

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying voltagent with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6b2552f
Status: ✅  Deploy successful!
Preview URL: https://f26fe90c.voltagent.pages.dev
Branch Preview URL: https://fix-global-workspace-default.voltagent.pages.dev

View logs

@omeraplak omeraplak merged commit ba8d7e0 into main Apr 23, 2026
24 checks passed
@omeraplak omeraplak deleted the fix/global-workspace-default branch April 23, 2026 02:59
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 workspace doesn't work

1 participant