refactor(channels): move tool hint rendering out of core (#6498)

* refactor(channels): move tool hint rendering out of core

* test: align progress privacy check with structured tool events
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-29 10:37:29 +08:00
1 parent b1cc89e922
commit acc3750c28
30 files changed
+530 -124

No files matched your search

-7
View File
@@ -290,7 +290,6 @@ class AgentLoop:
context_window_tokens: int | None = None,
max_tool_result_chars: int | None = None,
provider_retry_mode: str = "standard",
tool_hint_max_length: int | None = None,
cron_service: CronService | None = None,
restrict_to_workspace: bool = False,
session_manager: SessionManager | None = None,
@@ -365,10 +364,6 @@ class AgentLoop:
else defaults.max_tool_result_chars
)
self.provider_retry_mode = provider_retry_mode
self.tool_hint_max_length = (
tool_hint_max_length if tool_hint_max_length is not None
else defaults.tool_hint_max_length
)
self.tools_config = _tc
self.network_config = network_config or NetworkConfig()
self.web_config = _tc.web
@@ -515,7 +510,6 @@ class AgentLoop:
context_window_tokens=context_window_tokens,
max_tool_result_chars=defaults.max_tool_result_chars,
provider_retry_mode=defaults.provider_retry_mode,
tool_hint_max_length=defaults.tool_hint_max_length,
restrict_to_workspace=config.tools.restrict_to_workspace,
channels_config=config.channels,
timezone=defaults.timezone,
@@ -1320,7 +1314,6 @@ class AgentLoop:
attributes=dict(request_ctx.attributes),
session_key=active_session_key,
workspace=effective_scope.project_path,
tool_hint_max_length=self.tool_hint_max_length,
registered_hook_factories=self._hook_factories,
turn_hook_factories=list(hook_factories or []),
registered_hooks=self._extra_hooks,
+2 -16
View File
@@ -10,13 +10,11 @@ from loguru import logger
from nanobot.agent.hook import AgentHook, AgentHookContext
from nanobot.bus.outbound_events import ProgressEvent, StreamDeltaEvent, StreamEndEvent
from nanobot.events import NO_EVENTS, EventSink
from nanobot.providers.base import ToolCallRequest
from nanobot.utils.helpers import IncrementalThinkExtractor, strip_think
from nanobot.utils.progress_events import (
build_tool_event_finish_payloads,
build_tool_event_start_payload,
)
from nanobot.utils.tool_hints import format_tool_hints
class AgentProgressHook(AgentHook):
@@ -28,14 +26,12 @@ class AgentProgressHook(AgentHook):
*,
streaming: bool = False,
session_key: str | None = None,
tool_hint_max_length: int = 40,
log_content: bool = True,
) -> None:
super().__init__(reraise=True)
self._publish = events.publish
self._streaming = streaming
self._session_key = session_key
self._tool_hint_max_length = tool_hint_max_length
self._log_content = log_content
self._stream_buf = ""
self._think_extractor = IncrementalThinkExtractor()
@@ -50,9 +46,6 @@ class AgentProgressHook(AgentHook):
return None
return strip_think(text) or None
def _tool_hint(self, tool_calls: list[Any]) -> str:
return format_tool_hints(tool_calls, max_length=self._tool_hint_max_length)
async def on_stream(self, context: AgentHookContext, delta: str) -> None:
prev_clean = strip_think(self._stream_buf)
self._stream_buf += delta
@@ -118,11 +111,7 @@ class AgentProgressHook(AgentHook):
}
if phase == "start":
await self.on_stream_end(context, resuming=True)
tool_call = ToolCallRequest(id=str(call_id), name=name, arguments=arguments)
tool_hint = self._strip_think(self._tool_hint([tool_call])) or name
await self._publish(ProgressEvent(
content=tool_hint, tool_hint=True, tool_events=[payload],
))
await self._publish(ProgressEvent(tool_hint=True, tool_events=[payload]))
logger.info(
"Provider-hosted tool call: {}({})",
name,
@@ -138,11 +127,8 @@ class AgentProgressHook(AgentHook):
thought = self._strip_think(context.response.content if context.response else None)
if thought:
await self._publish(ProgressEvent(content=thought))
tool_hint = self._strip_think(self._tool_hint(context.tool_calls))
tool_events = [build_tool_event_start_payload(tc) for tc in context.tool_calls]
await self._publish(ProgressEvent(
content=tool_hint or "", tool_hint=True, tool_events=tool_events,
))
await self._publish(ProgressEvent(tool_hint=True, tool_events=tool_events))
for tc in context.tool_calls:
args_str = (
json.dumps(tc.arguments, ensure_ascii=False)[:200]
-2
View File
@@ -30,7 +30,6 @@ class AgentTurnHookSpec:
metadata: dict[str, Any] | None = None
session_key: str | None = None
workspace: Path | None = None
tool_hint_max_length: int = 40
registered_hook_factories: list[AgentTurnHookFactory] = field(default_factory=list)
turn_hook_factories: list[AgentTurnHookFactory] = field(default_factory=list)
registered_hooks: list[AgentHook] = field(default_factory=list)
@@ -48,7 +47,6 @@ def build_agent_turn_hook(spec: AgentTurnHookSpec) -> AgentHook:
events=spec.events,
streaming=spec.streaming,
session_key=spec.session_key,
tool_hint_max_length=spec.tool_hint_max_length,
log_content=log_content,
)
if spec.ephemeral and not spec.run_extra_hooks_for_ephemeral: