Kiro Agent Documentation
repository·main·Indexed 18 days ago
https://github.com/ghuntley/amazon-kiro.kiro-agent-source-code-analysisA 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.
What's inside Kiro Agent
- 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.
Overview of the Kiro Extension
mainThe Kiro extension provides an AI-integrated, spec-based development environment. It allows users to define systems and components using natural language specifications within a local application, which then generates the corresponding code for deployment.How the Prompt Engineering System works
mainKiro uses a hierarchical prompt structure to ensure high-quality AI responses across different models and tasks:
- Base System Prompt: Establishes Kiro's identity, capabilities (file system, code assistance), and security rules via
getBasePrompt(). - 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. - Context Injection: Dynamically injects environment data like OS, platform, shell, workspace state, and open files.
- Task-Specific Prompts: Workflow-oriented instructions (e.g., Specification Generation).
- 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}}).- Base System Prompt: Establishes Kiro's identity, capabilities (file system, code assistance), and security rules via
Use Specs for structured feature development
mainSpecs 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.Understand the concept of a Hook
mainIn 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:
- File Events: Which specific file changes or events the agent should listen for.
- 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.
Use Steering to provide context and rules
mainSteering 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...- Always included: The default behavior for files in
Use Autonomy Modes in Kiro
mainKiro operates in two primary modes to manage how changes are applied to your workspace:
- Autopilot mode: Kiro can modify files within the opened workspace autonomously.
- Supervised mode: Kiro proposes changes, but the user has the opportunity to review and revert them after application.
Understand the Kiro Agent Architecture
mainThe 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.
Generate codebase embeddings locally with all-MiniLM-L6-v2
mainThe Kiro Agent uses theall-MiniLM-L6-v2sentence transformer model viatransformers.jsto generate codebase embeddings locally. This allows for local semantic search and code analysis without sending raw code to an external embedding provider.Create an implementation plan task list
mainOnce 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
- After generating or updating the
tasks.mdfile, the agent must ask:"Do the tasks look good?". - The agent must use the
userInputtool with the exact reason string:spec-tasks-review. - If the user requests changes, the agent must iterate on the document and ask for approval again.
- 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.mdfile and clicking "Start task" next to individual items.- File Location: The implementation plan must be created at
Create and manage Agent Hooks
mainAgent 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 UIto start building a new hook.
Manage External Dependencies for Bundling
mainThe 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:
- Update the curated list: Open
scripts/analyze-externals.mjsand add the package name to theUNBUNDLEABLE_PACKAGESarray. - Categorize the package: Place the package in the appropriate section within the array:
// VSCode runtime provided: Forvscodemodules.// Native binaries that can't be bundled: For packages containing.nodefiles.// ESBuild and platform-specific binaries: For@esbuild/*packages.// Runtime dependencies with native binaries or dynamic requires.// Relative imports that can't be bundled.
- Apply changes: Run
npm run analyze-externalsto update bothscripts/esbuild.mjsand.vscodeignoreautomatically.
// Example: Adding a package to scripts/analyze-externals.mjs const UNBUNDLEABLE_PACKAGES = [ // ... existing packages 'your-new-package', ];- Update the curated list: Open