Skip to content

agent: add before-response and after-response hooks - #708

Open
Berserk-hub150 wants to merge 15 commits into
antirez:mainfrom
Berserk-hub150:feat/agent-hooks-440
Open

agent: add before-response and after-response hooks#708
Berserk-hub150 wants to merge 15 commits into
antirez:mainfrom
Berserk-hub150:feat/agent-hooks-440

Conversation

@Berserk-hub150

@Berserk-hub150 Berserk-hub150 commented Aug 5, 2026

Copy link
Copy Markdown

Closes #440

Summary

Add optional command hooks to ds4-agent, allowing external commands to run before and after each assistant response.

Hooks are disabled by default and do not change normal agent behavior unless explicitly configured.

CLI options

--before-response-hook CMD
--after-response-hook CMD
--hook-timeout SEC

Features

  • Execute a command before a response starts
  • Execute a command after a response finishes
  • Pass structured JSON events through stdin
  • Support configurable hook timeouts
  • Terminate the hook process group after a timeout
  • Report hook failures to stderr
  • Preserve the active agent session when a hook fails
  • Include response metadata, token counts, interruption status and tool-call status

Documentation and examples

  • Hook lifecycle and security documentation
  • JSON event schema
  • Shell and PowerShell examples
  • HTTP callback example using curl
  • JSONL logging example
  • Regression checklist

Validation

The following commands completed successfully in the gcc:14-bookworm Docker image:

make -f GNUmakefile test-hooks
make -f GNUmakefile cpu

Test result:

ds4 hook tests: ok

The complete CPU build succeeded.

A full make test was also attempted, but the Linux test target requires CUDA nvcc, which is not included in the CPU-only gcc:14-bookworm image.

@Berserk-hub150
Berserk-hub150 marked this pull request as ready for review August 5, 2026 16:57
@Berserk-hub150

Copy link
Copy Markdown
Author

@antirez, before you spend time reviewing the full implementation, is the wrapper-based integration through GNUmakefile and ds4_agent_with_hooks.c acceptable for this project, or would you prefer the hooks to be integrated directly into ds4_agent.c and the main Makefile?

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.

[Feature] add hooks support?

1 participant