
How It Works
The AI engine operates through a sophisticated multi-step workflow:- Context Collection: Gathers workspace files, open tabs, and project structure
- System Prompt Generation: Constructs detailed instructions based on your task and environment
- LLM Communication: Sends requests to configured AI models with rich context
- Tool Execution: Processes model responses and executes file operations, commands, and searches
- Iterative Refinement: Continues the loop until task completion
Supported LLM Providers
HAI Build supports a wide range of AI providers for maximum flexibility:- Cloud Providers
- Fast Inference
- Specialized
- Anthropic: Claude 4.5 Sonnet, Claude 3 Opus, Claude Haiku
- OpenAI: GPT-4, GPT-4 Turbo, GPT-3.5
- Google: Gemini 2.0, Gemini Pro, Gemini Flash
- AWS Bedrock: Claude, Llama, Command models
- GCP Vertex AI: Full model catalog
For detailed provider configuration, see LLM Providers Configuration guide.
Code Generation Workflows
Plan and Act Mode
HAI Build features a dual-mode system for handling complex tasks: Plan Mode:- Creates detailed implementation plans before writing code
- Uses reasoning models for strategic thinking
- Generates comprehensive task breakdowns
- Perfect for complex features and refactoring
- Executes code changes directly
- Fast iteration on well-defined tasks
- Ideal for bug fixes and small features
Native Tool Calling
HAI Build leverages native function calling for precise tool execution:- Parallel Execution: Models can call multiple tools simultaneously
- Structured Output: Tools receive properly formatted parameters
- Error Handling: Automatic retry with error context
- Context Preservation: Tool responses integrate seamlessly into conversation
- Claude 4.5+ (Anthropic)
- GPT-4 and GPT-4 Turbo (OpenAI)
- Gemini 2.0+ (Google)
Intelligent Context Management
Automatic Context Window Handling
The AI engine automatically manages context limits:Context Compaction
Context Compaction
When approaching token limits, HAI Build:
- Summarizes older conversation history
- Preserves critical file contents
- Maintains task continuity across resets
- Executes PreCompact hooks for custom context injection
File Context Tracking
File Context Tracking
Tracks which files are in the AI’s context:
- Shows context status in file explorer
- Automatically adds relevant files
- Warns when removing files from context
- Provides context usage metrics (see
src/core/context/context-tracking/FileContextTracker.ts:9)
Environment Context
HAI Build automatically includes:- Operating system and platform details
- Available CLI tools (git, npm, docker, etc.)
- Workspace structure and multi-root support
- Active terminal sessions and shells
src/core/context/context-tracking/EnvironmentContextTracker.ts:8
Advanced Features
Custom Instructions
Tailor AI behavior with custom rules:Cline Rules
Create
.clinerules files to define coding standards, patterns, and preferences.External Rules
Import rules from
.cursorrules, .windsurfrules, or .agentrules.System Prompt Customization
The system prompt is built from modular components:Reasoning Effort Control
For OpenAI o1/o3 models, control reasoning depth:low, medium, high
Code Editing Intelligence
Two-Tool Approach
HAI Build uses specialized tools for different editing scenarios: write_to_file: Complete file creation or replacement- New file scaffolding
- Boilerplate generation
- Major refactoring requiring full rewrites
- Function updates
- Variable renames
- Localized changes
- Multiple SEARCH/REPLACE blocks in one operation
src/core/prompts/system-prompt/components/editing_files.ts:1
Multi-File Diff Generation
For complex changes across multiple files:- Preview all changes before applying
- Accept or reject changes file-by-file
- Smart conflict detection and resolution
- Integration with VS Code diff viewer
Performance Optimization
Streaming Responses
All LLM interactions use streaming for:- Real-time feedback as the AI “thinks”
- Partial message display in the UI
- Early cancellation of problematic responses
- Lower perceived latency
src/core/task/StreamResponseHandler.ts:1
Request Retry Logic
Automatic retry with exponential backoff:- Handles rate limits gracefully
- Recovers from transient network errors
- Displays retry status in the UI
- Configurable max attempts and delays
src/core/api/retry.ts:1
Best Practices
Be Specific
Provide clear, detailed task descriptions. The more context you give, the better the AI performs.
Troubleshooting
Model not responding
Model not responding
- Check API key validity in Settings
- Verify network connectivity
- Review provider status pages
- Check context window limits
Poor code quality
Poor code quality
- Add custom instructions via
.clinerules - Use Plan mode for complex tasks
- Provide more context in your prompt
- Try a more capable model
Context window exceeded
Context window exceeded
- Enable Auto Compact feature
- Use Focus Chain to maintain progress
- Break task into smaller steps
- Remove unnecessary files from context
Next Steps
Task Management
Integrate AI-generated tasks from Specif AI
Experts
Use domain experts for specialized code generation
MCP Integration
Extend AI capabilities with Model Context Protocol
Inline Editing
Make quick AI-assisted edits in your code