-
-
Notifications
You must be signed in to change notification settings - Fork 52.7k
Closed as duplicate of#2538
Description
Problem Statement
When an agent session is churning through tool calls (long-running exec, polling background processes, etc.), there's no visibility into what it's doing from external UIs like Discord. The channel goes silent even though the agent is actively working.
Example: A session running benchmarks for 2+ minutes with no Discord updates — stuck in a toolUse → toolResult → toolUse loop, never producing a user-facing message.
Proposed Solution
Add a Tool Hook Bridge that connects the existing agent event system to the internal hooks system, enabling workspace hooks to react to tool lifecycle events.
Architecture
Agent Runtime
↓ emitAgentEvent({ stream: "tool", phase: "start|update|result" })
Agent Event Bus (agent-events.js)
↓ onAgentEvent()
Tool Hook Bridge (NEW: infra/agent-hook-bridge.js)
↓ triggerInternalHook({ type: "tool", action: phase })
Internal Hooks System
↓
Workspace Hook Scripts (e.g., Discord visibility hook)
New Hook Events
tool:start— Tool execution begins (includes args)tool:update— Streaming output during execution (hook handles throttling)tool:result— Tool execution completes (includes result, isError)
Context Provided to Hooks
{
type: "tool",
action: "start" | "update" | "result",
sessionKey: "agent:main:discord:channel:123456",
timestamp: Date,
context: {
runId: string,
toolName: string,
toolCallId: string,
args?: any, // on start
partialResult?: any, // on update
result?: any, // on result
isError?: boolean, // on result
meta: object,
sessionMeta: { // Parsed for convenience
agentId: string,
platform: string, // discord, telegram, etc.
channelType: string,
channelId: string,
}
}
}Use Cases
- Ephemeral status messages — Post "⏳ Running: `exec npm run benchmark`..." to Discord, update when done
- Typing indicators — Show typing while tools are executing
- Audit logging — Track all tool usage for debugging/compliance
- Timeout warnings — Alert if a tool is taking unusually long
- Real-time dashboards — Stream tool activity to WebSocket UIs
Implementation Plan
- Create
src/infra/agent-hook-bridge.tswithstartAgentHookBridge()function - Subscribe to agent events and translate to hook events
- Parse session keys to provide structured
sessionMeta - Call from gateway startup after hooks are loaded
- Document new hook event types
Design Decisions
- Update events not filtered — Hook scripts handle their own rate limiting (allows both throttled Discord updates AND real-time WebSocket streaming)
- Fire-and-forget —
void triggerInternalHook()so tool execution isn't blocked by slow hooks - Reuse existing utilities — Uses
parseAgentSessionKeyfrom session-key-utils.js - Dedicated module — Keeps gateway startup clean
Related
- Discussed in Discord #Feature channel
- External review by Gemini agent confirmed architecture approach
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels