Kiro Agent Documentation

repository·main·Indexed 18 days ago

https://github.com/ghuntley/amazon-kiro.kiro-agent-source-code-analysis

A VS Code extension for specification-based development that transforms natural language requirements into production-ready code. It features a structured workflow (requirements, design, implementation), multi-provider AI support (OpenAI, Anthropic, AWS Bedrock, Ollama, Gemini), and local codebase embeddings using the all-MiniLM-L6-v2 model via Transformers.js. Includes built-in system tools for file and shell operations, Model Context Protocol (MCP) integration, and a customizable hook system for automation.

Tokens
16.6K
Snippets
46
Records
70
Agent score
62%

What's inside Kiro Agent

  1. Overview of Kiro Agent

    main
    Kiro Agent is a VS Code extension that provides a spec-based development environment. It allows developers to define systems and components using natural language specifications, which the agent then uses to generate production-ready code. It features multi-provider AI support, an advanced prompt engineering system, and a comprehensive tool ecosystem for file system and shell operations.
  2. How the Prompt Engineering System works

    main

    Kiro uses a hierarchical prompt structure to ensure high-quality AI responses across different models and tasks:

    1. Base System Prompt: Establishes Kiro's identity, capabilities (file system, code assistance), and security rules via getBasePrompt().
    2. Model-Specific Formatting: An optimization layer that uses specialized templates (e.g., GPT Edit Prompt, Claude Edit Prompt) to match the instruction-following patterns of specific providers.
    3. Context Injection: Dynamically injects environment data like OS, platform, shell, workspace state, and open files.
    4. Task-Specific Prompts: Workflow-oriented instructions (e.g., Specification Generation).
    5. Tool Integration: Action-specific prompting for built-in tools.

    Template System

    Kiro uses a Template Factory pattern with Handlebars support. It automatically detects models via autodetectPromptTemplates() and compiles templates with support for variable interpolation ({{variable}}), conditionals ({{#if condition}}), and loops ({{#each items}}).

  3. Use Specs for structured feature development

    main

    Specs are a formal way to build and document features with Kiro. Instead of a single prompt, a Spec iterates through requirements, design, and implementation tasks. This allows for incremental development of complex features with high control and feedback.

    Like Steering files, Specs can reference external files using the #[[file:<relative_file_name>]] syntax.

  4. Understand the concept of a Hook

    main

    In the Kiro Agent system, a hook is a configuration file that defines the relationship between file system events and AI agent actions. It acts as a bridge that automates workflows by specifying:

    1. File Events: Which specific file changes or events the agent should listen for.
    2. Agent Operations: What specific requests or prompts should be sent to the AI Agent when those file events occur.

    Hooks are used during the 'Hook Creation' workflow stage to automate software engineering tasks based on user-defined descriptions.

  5. Use Steering to provide context and rules

    main

    Steering allows you to include additional context, standards, or norms for your team in Kiro's interactions. Steering files are stored in the .kiro/steering/ directory of your workspace.

    Inclusion Modes

    • Always included: The default behavior for files in .kiro/steering/.
    • Conditional: Use a front-matter section to include files only when specific files are read into context.
    • Manual: Use a front-matter key to allow the user to include the steering file manually via a context key (#) in chat.

    Referencing Files

    Within steering files, you can reference other files (like OpenAPI or GraphQL specs) to influence Kiro's implementation using the #[[file:<relative_file_name>]] syntax.

    ---
    inclusion: fileMatch
    fileMatchPattern: 'README*'
    ---
    # Team Standards
    Always follow these patterns...
  6. Understand the Kiro Agent Architecture

    main

    The extension is built using a monorepo architecture consisting of several specialized packages. Key components include:

    Extension Structure

    • @amzn/codewhisperer-runtime: AWS CodeWhisperer integration.
    • continuedev/*: Core AI chat functionality (core, extension, GUI, config).
    • kiro-shared: Shared utilities and types.
    • kiro-shared-types: TypeScript definitions.
    • kiricons: Icon system (495+ SVG icons).
    • hook-editor: Automation hook editor.
    • webview-components: UI components.

    Core Modules

    • VsCodeExtension: The central coordinator.
    • VsCodeIde: Integration with the VS Code API.
    • DiffManager: Manages code changes.
    • TabAutocompleteModel: Handles AI-powered completions.
    • Core: Processes main business logic.
  7. Create an implementation plan task list

    main

    Once a design has been approved, the Kiro Agent enters the Implementation Planning workflow stage to create an actionable checklist of coding tasks. This plan is stored in a specific file within the project structure to guide subsequent code generation.

    Task List Requirements

    • File Location: The implementation plan must be created at .kiro/specs/{feature_name}/tasks.md.
    • Format: A numbered checkbox list with a maximum of two levels of hierarchy:
      • Top-level items (e.g., epics) used only when necessary.
      • Sub-tasks using decimal notation (e.g., 1.1, 1.2).
    • Task Content: Each task must include:
      • A clear objective involving writing, modifying, or testing code.
      • Sub-bullets providing additional context.
      • Specific references to granular sub-requirements from the requirements document.

    Constraints and Scope

    • Coding Focus Only: Tasks must be actionable by a coding agent (e.g., "Implement X function", "Create Y component").
    • Excluded Tasks: Do NOT include tasks for user testing, deployment, performance metrics, user training, or documentation creation. Automated end-to-end tests are allowed, but manual application running is not.
    • Incremental Progress: Tasks must be sequenced to build incrementally, prioritizing test-driven development (TDD) and validating core functionality early.

    Approval Workflow

    1. After generating or updating the tasks.md file, the agent must ask: "Do the tasks look good?".
    2. The agent must use the userInput tool with the exact reason string: spec-tasks-review.
    3. If the user requests changes, the agent must iterate on the document and ask for approval again.
    4. The workflow is only complete once the user provides explicit approval (e.g., "yes", "approved", "looks good").

    Note: This workflow is strictly for creating planning artifacts. It does not perform the actual feature implementation. Once approved, users can begin execution by opening the tasks.md file and clicking "Start task" next to individual items.

  8. Create and manage Agent Hooks

    main

    Agent Hooks allow you to trigger Kiro executions automatically based on IDE events or user actions.

    Common Use Cases

    • File Save: Trigger tests or linting automatically when a file is saved.
    • Translation Updates: Ensure all languages are updated when a translation string changes.
    • Manual Triggers: Create a 'spell-check' hook that runs when a user clicks a button.

    How to access

    • Explorer View: Use the 'Agent Hooks' section in the explorer to view or create hooks.
    • Command Palette: Search for Open Kiro Hook UI to start building a new hook.
  9. Manage External Dependencies for Bundling

    main

    The extension uses ESBuild to bundle dependencies into dist/extension.js. However, certain packages must remain external (unbundled) due to native binaries, dynamic requires, or platform-specific constraints.

    To add a new package that cannot be bundled, follow these steps:

    1. Update the curated list: Open scripts/analyze-externals.mjs and add the package name to the UNBUNDLEABLE_PACKAGES array.
    2. Categorize the package: Place the package in the appropriate section within the array:
      • // VSCode runtime provided: For vscode modules.
      • // Native binaries that can't be bundled: For packages containing .node files.
      • // ESBuild and platform-specific binaries: For @esbuild/* packages.
      • // Runtime dependencies with native binaries or dynamic requires.
      • // Relative imports that can't be bundled.
    3. Apply changes: Run npm run analyze-externals to update both scripts/esbuild.mjs and .vscodeignore automatically.
    // Example: Adding a package to scripts/analyze-externals.mjs
    const UNBUNDLEABLE_PACKAGES = [
      // ... existing packages
      'your-new-package',
    ];