fix(hooks): restore direct message callback when hooks disabled
This commit is contained in:
parent
5c0418349b
commit
3132756623
2 changed files with 12 additions and 0 deletions
|
|
@ -134,4 +134,5 @@ Recommended ordering:
|
||||||
|
|
||||||
- Hook panics are recovered internally; one bad hook does not crash the loop.
|
- Hook panics are recovered internally; one bad hook does not crash the loop.
|
||||||
- Hook errors are logged and execution continues unless `Cancel` is set.
|
- Hook errors are logged and execution continues unless `Cancel` is set.
|
||||||
|
- Observe-only hooks (`message_received`, `after_tool_call`, `llm_input`, `llm_output`, `session_start`, `session_end`) must treat events as read-only.
|
||||||
- Keep hook handlers fast and non-blocking to avoid latency impact.
|
- Keep hook handlers fast and non-blocking to avoid latency impact.
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,17 @@ func (al *AgentLoop) SetHooks(h *hooks.HookRegistry) error {
|
||||||
if agent, ok := al.registry.GetAgent(agentID); ok {
|
if agent, ok := al.registry.GetAgent(agentID); ok {
|
||||||
if tool, ok := agent.Tools.Get("message"); ok {
|
if tool, ok := agent.Tools.Get("message"); ok {
|
||||||
if mt, ok := tool.(*tools.MessageTool); ok {
|
if mt, ok := tool.(*tools.MessageTool); ok {
|
||||||
|
if h == nil {
|
||||||
|
mt.SetSendCallback(func(_ context.Context, channel, chatID, content string) error {
|
||||||
|
al.bus.PublishOutbound(bus.OutboundMessage{
|
||||||
|
Channel: channel,
|
||||||
|
ChatID: chatID,
|
||||||
|
Content: content,
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
mt.SetSendCallback(func(ctx context.Context, channel, chatID, content string) error {
|
mt.SetSendCallback(func(ctx context.Context, channel, chatID, content string) error {
|
||||||
if sent, reason := al.sendOutbound(ctx, bus.OutboundMessage{
|
if sent, reason := al.sendOutbound(ctx, bus.OutboundMessage{
|
||||||
Channel: channel,
|
Channel: channel,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue