Skip to content

feat: run a pre-chat tool before a room's first message - #3270

Open
ckelly17 wants to merge 6 commits into
devfrom
pre-chat-tool
Open

ckelly17 wants to merge 6 commits into
devfrom
pre-chat-tool

Conversation

@ckelly17

@ckelly17 ckelly17 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Description

Lets a deployment name one toolbox tool to run once, when a room is set up and before its first message. The tool's result is put in front of the first user message as model-only text: the model reads it, and the UI shows only what the user typed (uiText). A typical choice is ECU's GetRoomResources, so the model starts with the room's documents, skills and toolboxes in context instead of spending its first step calling the tool.

It works in both the agent harness and Playground chat, each configured where that surface already gets its default tools.

Changes Made

  • PreChatContext (new): shared by both paths.
    • Runs the tool through MCPUtility.executeTool, so the user's access to the toolbox is checked and SMSS_FUNCTION_NAME applies.
    • Looks for the tool in one or more toolboxes, in order.
    • Skips tools that are missing, disabled or ask, and skips if the insight is bound to a different room.
    • Truncates the result to maxChars (default 60,000) and wraps it in <pre_chat_context tool="…">, with a note telling the model it doesn't need to call the tool again.
    • Any failure is logged and skipped, and the chat continues as it would without the setting.
  • Agent harness (SemossAgentHarness, PlatformAgentTools): new properties AGENT_DEFAULT_TOOLS_PRE_CHAT_TOOL, plus optional …_ARGS and …_MAX_CHARS. They only apply when AGENT_DEFAULT_TOOLS_MCP_ID / …_MCP_PROJECT_ID replaces the default tools, and the tool is looked up in that toolbox. Skipped when the agent turns default tools off, when it lists the tool in tool_policy.default_tools.disabled, for PPTX workflow runs, and when the room already has messages.
  • Playground (PlaygroundThemeUtils, AskRoomReactor, AskPlaygroundReactor): new theme map key playground.preChatTool: {tool, toolboxId?, args?, maxChars?}. Without toolboxId, the tool is looked up in playground.defaultTools. AskRoomReactor has a new override method, getPreChatTool(); plain AskRoom returns null, so its behaviour is unchanged. Skipped for prebuilt turns (responseParts).
  • Docs: pre-chat section in docs/agents/mcp_tools.md.
  • Tests: PreChatContextUnitTests and PlaygroundThemeUtilsUnitTests.

A deployment can name one toolbox tool to run when a room is set up and
before its first message. The result is stored as a hidden note and
acknowledgement, so the model starts with it in context and the UI does
not show it.

- Agent harness: AGENT_DEFAULT_TOOLS_PRE_CHAT_TOOL (plus optional _ARGS
  and _MAX_CHARS), looked up in the AGENT_DEFAULT_TOOLS_MCP_ID toolbox
  and skipped when the agent turns that tool off.
- Playground: playground.preChatTool in the active theme map, applied by
  AskPlayground and returned to the client as preChatMessages.
- Both run through PreChatContext: access-checked MCP execution, skipped
  for missing, disabled or ask tools, truncated, and never failing the
  chat.
- Room auto-naming skips platform-generated messages.
When playground.preChatTool has no toolboxId, look for the tool in the
theme's playground.defaultTools (the toolboxes the UI attaches to every
new room), in order, and run it from the first toolbox that has it.
…rewrite

The pre-chat note now goes in front of the first user message instead of a
stored hidden pair, so room naming no longer needs to skip
platform-generated messages, and PreChatContext no longer uses
IModelEngine or AbstractMessage.
@ckelly17
ckelly17 requested a review from a team as a code owner November 5, 2026 06:33
@snyk-io

snyk-io Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

The pre-chat docs and PreChatContext Javadoc still described the earlier
stored hidden pair, preChatTool ornament and preChatMessages field. Describe
the current behaviour: the note goes in front of the first user message's
text, the UI shows uiText, and nothing else is added to room history.
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.

1 participant