Kiro icon indicating copy to clipboard operation
Kiro copied to clipboard

Custom Workflow Callbacks for Agent Hook (Script & Tool Integration)

Open sduoooh opened this issue 1 year ago • 4 comments

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

  1. Task List Automation

    • You have a task.md file that gets an “x” appended when a task finishes.
    • After the final “x,” run git commit to 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.
  2. 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.
  3. 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

sduoooh avatar Jul 26 '25 07:07 sduoooh

If the AI task ends (either successfully or with an error), it can serve as a trigger:

  1. If it completes successfully, save the current Git state and instruct the AI to “execute the next task”;
  2. 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.

sduoooh avatar Jul 26 '25 07:07 sduoooh

Good job@!

plotqq avatar Jul 26 '25 11:07 plotqq

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.

sduoooh avatar Jul 26 '25 11:07 sduoooh

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.

AnilMaktala avatar Apr 15 '26 16:04 AnilMaktala