Skip to content

[FEATURE] HooksΒ #1564

@dobesv

Description

@dobesv

πŸ“‹ Prerequisites

πŸ“ Feature Summary

Support hooks similar to claude code / opencode / etc

❓ Problem Statement / Motivation

A hooks system can give a lot of power to the agent developer/operator to add capabilities without having to modify the core product, for example:

  • memory systems
  • PII/abuse redaction
  • tool policy to support approve/block/ask based on tool content rather than just the name (or even use an LLM to analyze the tool call and recommend)
  • keyword based prompt injection
  • running built/lint automatically after a code change
  • notifications to the user about bot prompts/activities (e.g. to slack or another messenger)

Basically it allows for kagent to be a better platform to build on top of without having to provide everything built-in.

See also

πŸ’‘ Proposed Solution

I think an OK initial implementation would be to support the same protocol as claude code and install it using containers, similar to how skills are done currently but for hooks.

You would list hooks in the agent spec in a similar manner as this:

- hooks:    
  - ref: repo/img:version # docker container to load
    event: PreToolUse # hook called before running a tool, to return approve/deny/ask for that tool call
    type: claude-command # Having a hook type allows for additional hook modes to be added in the future with a different protocol     
    matcher: "bash|shell_exec" # Only run if the tool matches the pattern
    command: 'check-tool-use.sh' # Hook implementation
  - ref: repo/img:version # docker container to load
    event: SessionStart # Runs before the first user message in a session
    type: claude-command
    command: 'inject-session-metadata-message.py'

If the same container ref is used by multiple hooks it should be mounted only once.

The hooks are a command that reads a single JSON object as input and writes a single JSON object as output, or writes a message to stderr and exits with code 2.

See claude code docs for more details: https://code.claude.com/docs/en/hooks

πŸ”„ Alternatives Considered

Up until now I have been keeping a fork of kagent that has some added features that I need. The hook would allow me to move some of that stuff into hooks.

🎯 Affected Service(s)

App Service

πŸ“š Additional Context

No response

πŸ™‹ Are you willing to contribute?

  • I am willing to submit a PR for this feature

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions