Skip to content

refactor(bot): Extract platform-agnostic tool system#1

Open
RSO wants to merge 10 commits intomainfrom
refactor/bot-tool-system
Open

refactor(bot): Extract platform-agnostic tool system#1
RSO wants to merge 10 commits intomainfrom
refactor/bot-tool-system

Conversation

@RSO
Copy link
Contributor

@RSO RSO commented Feb 4, 2026

Summary

This PR introduces a tool registry system that enables dynamic tool loading based on the owner's integrations, laying the groundwork for:

  • Supporting multiple chat platforms (Discord, Teams) beyond Slack
  • Adding new tool integrations (GitLab, Sentry, Axiom) without modifying core bot logic

Changes

New Tool System (/src/lib/bot/tools/)

  • types.ts: Core type definitions (BotTool, ToolResult, ToolExecutionContext, RequesterInfo)
  • registry.ts: Global tool registry with registerTool, getTool, getAllTools
  • tool-loader.ts: Dynamic tool loading based on owner's active integrations
  • implementations/spawn-cloud-agent.ts: Extracted spawn_cloud_agent tool
  • index.ts: Barrel export with auto-registration

Updated slack-bot.ts

  • Removed ~180 lines of hardcoded tool code
  • Now uses getToolDefinitionsForOwner() to dynamically load tools
  • Uses getTool() from registry to execute tool calls
  • Tools only available if owner has the required integration (e.g., github)

Architecture

Tool Registry (startup)
    └── spawn_cloud_agent (requiredIntegration: 'github')
    └── [future tools...]

Request Flow:
    1. getToolDefinitionsForOwner(owner)
       └── Check owner's integrations
       └── Filter tools by requiredIntegration
    2. LLM calls tool
    3. getTool(name).execute(args, context)

Testing

  • Manual testing of Slack bot with spawn_cloud_agent tool
  • Verified tool is only available when owner has GitHub integration

PR Stack

This is PR 1 of 7 in the Slack bot tech debt reduction initiative:

  1. Tool System (this PR)
  2. Bot Core extraction
  3. Platform Adapter interface
  4. Slack Adapter implementation
  5. Simplified Webhook routes
  6. Context Provider system
  7. Generic logging with migration

RSO added 10 commits February 4, 2026 09:14
Introduce core type definitions for the bot tool system:
- ToolResult: result returned from tool execution
- RequesterInfo: user attribution info for PRs
- ToolExecutionContext: context passed to tool execution
- BotTool: main interface for tools with dynamic loading support
Add global tool registry for managing bot tools:
- registerTool: register a tool at module load time
- getTool: look up a tool by name
- getAllTools: get all registered tools
- hasRegisteredTool: check if a tool exists
- getRegisteredToolCount: get count for debugging
Add tool loader that dynamically loads tools based on owner's integrations:
- getToolsForOwner: returns tools available to an owner
- getToolDefinitionsForOwner: returns OpenAI tool definitions
- Tools with requiredIntegration only available if owner has that integration
Move spawn_cloud_agent tool from slack-bot.ts to dedicated implementation:
- Extracted tool definition and execution logic
- Added BotTool interface implementation
- Set requiredIntegration to 'github' for dynamic loading
- Returns ToolResult with sessionId in metadata
- Renamed logging prefix from [SlackBot] to [SpawnCloudAgent]
Create index.ts that:
- Re-exports all types, registry, and loader functions
- Auto-registers spawn_cloud_agent tool on module import
- Provides usage documentation in JSDoc
Update slack-bot.ts to use the new tool system:
- Import tools from @/lib/bot/tools instead of inline definitions
- Dynamically load tools based on owner's integrations
- Use getTool() from registry to execute tool calls
- Build ToolExecutionContext with requester info for tools
- Remove ~180 lines of tool-specific code (moved to tools module)

This enables:
- Dynamic tool availability based on owner's integrations
- Easy addition of new tools without modifying slack-bot.ts
- Consistent tool interface across different tools
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