fix(agent): provide current workspace access before model requests

This commit is contained in:
Xubin Ren committed 2026-10-11 17:06:39 +08:00
1 parent d7d4b97df3
commit 1d69f630d7
17 files changed
+265 -44

No files matched your search

+7 -1
View File
@@ -620,6 +620,8 @@ class AgentLoop:
from nanobot.agent.tools.context import ToolContext
from nanobot.agent.tools.loader import ToolLoader
runtime_control = AgentRuntimeControl(self)
self.register_runtime_context_provider(runtime_control.workspace_context)
ctx = ToolContext(
config=self.tools_config,
workspace=str(self.workspace),
@@ -632,7 +634,7 @@ class AgentLoop:
image_generation_provider_configs=self._image_generation_provider_configs,
timezone=self.context.timezone or "UTC",
workspace_sandbox=self.workspace_scopes.sandbox_status,
runtime_control=AgentRuntimeControl(self),
runtime_control=runtime_control,
)
loader = ToolLoader()
registered = loader.load(ctx, self.tools)
@@ -741,6 +743,7 @@ class AgentLoop:
sender_id=ctx.msg.sender_id,
turn_id=ctx.delivery.route.turn_id or ctx.turn_id,
workspace=scope.project_path,
workspace_scope=scope,
log_content=ctx.session.policy.log_content and not ctx.ephemeral,
persist_session=ctx.session.policy.persist and not ctx.ephemeral,
can_receive_background_results=self._running,
@@ -1085,6 +1088,8 @@ class AgentLoop:
sender_id=pending_msg.sender_id,
turn_id=request_ctx.turn_id,
workspace=scope.project_path,
# Injected input continues the active run's tool policy.
workspace_scope=effective_scope,
log_content=request_ctx.log_content,
)
blocks = await self._resolve_runtime_context_for_request(
@@ -1197,6 +1202,7 @@ class AgentLoop:
)
request_ctx = dataclasses.replace(
request_ctx,
workspace_scope=effective_scope,
log_content=(
request_ctx.log_content and not ephemeral
and (session is None or session.policy.log_content)