feat: gated prompt for artefacts

This commit is contained in:
Alex committed 2026-06-28 19:21:07 +02:00
1 parent 3254543292
commit ec39836ff6
11 files changed
+315 -8

No files matched your search

@@ -1132,6 +1132,32 @@ class StreamProcessor:
logger.warning(f"Failed to pre-fetch tools: {type(e).__name__}")
return None
def _enabled_tool_names(self) -> Optional[set]:
"""Resolve the tool names enabled for this turn, for ``tools.enabled`` gating.
Mirrors the executor the agent will use (same user/agent context), so an
agent yields its configured tools and an agentless chat yields user tools
plus defaults. Returns None on failure so the prompt gate fails open
(keeps the section) rather than hiding guidance when resolution breaks.
"""
try:
from application.agents.tool_executor import ToolExecutor
user = self.decoded_token.get("sub") if self.decoded_token else None
tool_executor = ToolExecutor(
user_api_key=self.agent_config.get("user_api_key"),
user=user,
decoded_token=self.decoded_token,
agent_id=self.agent_id,
)
client_tools = self.data.get("client_tools")
if client_tools:
tool_executor.client_tools = client_tools
return tool_executor.get_enabled_tool_names()
except Exception:
logger.warning("Failed to resolve enabled tool names for prompt gating")
return None
def _fetch_tool_data(
self,
tool_doc: Dict[str, Any],
@@ -1517,6 +1543,8 @@ class StreamProcessor:
docs=docs,
docs_together=docs_together,
tools_data=tools_data,
attachments=self.attachments,
enabled_tools=self._enabled_tool_names(),
artifact_parent={"conversation_id": self.conversation_id},
)