Custom Workflow Callbacks for Agent Hook (Script & Tool Integration)
Feature Description
The current Agent Hook in Kiro only allows invoking the AI via a preset prompt whenever a watched file changes. This is powerful, but it can exhaust limited AI calls and doesn’t support conditional logic, rollback, or retry with preserved context.
I’d like to extend Agent Hook so that its callback can trigger any custom workflow. Within that workflow, we should be able to:
- Call the AI with a specified prompt when needed.
- Run arbitrary scripts or invoke MCP Tools for lightweight, on-premise logic.
- Combine AI calls and scripts in the same hook, choosing the best tool for each step.
Use Case
-
Task List Automation
- You have a
task.mdfile that gets an “x” appended when a task finishes. - After the final “x,” run
git committo snapshot the completed state automatically. - During each sub-step, AI writes a newline to
task.md, but you only want the hook to fire on real “x” additions—scripts can filter out noise and prevent needless AI calls.
- You have a
-
Rate-Limit & Retry Handling
- When the daily AI quota is reached or an API error occurs, fall back to a local summarization script or queue the call for retry.
- Scripts can checkpoint state, so retries pick up from the right context without losing prior progress.
-
Conditional Logic
- Only invoke AI prompts on specific file patterns or content changes (e.g., lines starting with “TODO”).
- For other modifications, run quick validations or formatters via scripts to keep the workflow efficient.
Additional Context
No response
If the AI task ends (either successfully or with an error), it can serve as a trigger:
- If it completes successfully, save the current Git state and instruct the AI to “execute the next task”;
- If it fails, roll back to the previous Git state. If the termination reason is “usage limit,” then end the hook; otherwise, restart the current task.
Good job@!
Good job@! 好 job@!
Sorry, it seems there was a misunderstanding. I used AI to polish the grammar, which unfortunately caused an error in the use of pronouns. I was merely sharing an idea—I’m not the developer. Apologies for the confusion; I’ve corrected the pronoun-related issue.
Thank you for the suggestion. Agent Hooks were introduced in Kiro IDE 0.7 with support for runCommand and askAgent actions, enabling custom workflow callbacks at key agent lifecycle events. Pre and Post Tool Use hooks were added in IDE 0.9. See https://kiro.dev/docs/hooks/ for details. Closing as resolved.