Efficient AI Agent Team Building Framework - Make AI coding assistants reliably execute complex tasks
Why StepWise • Quick Start • Core Features • API Reference • Examples • 中文文档
When working with AI coding assistants on complex development tasks, we often face three major pain points:
| Pain Point | StepWise Solution |
|---|---|
| Long tasks drift, multi-tasks get missed | Break tasks into stable small steps, data validation ensures correct output, condition checks verify execution results |
| Private data handling is difficult | Support Skill-generating Agents, auto-summarize Skills after multiple successful attempts |
| Debugging is hard, progress lost on interruption | Checkpoint recovery, debug mode for quick validation |
StepWise enables AI coding assistants (Claude Code, OpenCode, etc.) to complete complex tasks reliably through task step control, data validation, conditional routing, and checkpoint recovery.
Supports Claude Code and OpenCode, defaults to Claude Code:
import { setAgentType, setTaskName, StepWise } from 'stepwise';
// Set AI coding assistant type (optional, default: 'claude')
setAgentType('claude'); // Use Claude Code (default)
// setAgentType('opencode'); // Use OpenCode
setTaskName('MyTask');
const agent = new StepWise('MainAgent');Break complex tasks into stable small steps, with Shell command verification:
import { setTaskName, StepWise } from 'stepwise';
setTaskName('RefactorModule');
const agent = new StepWise('MainAgent');
// Break complex tasks into multiple small steps
await agent.execPrompt('Step 1: Analyze module dependencies');
await agent.execPrompt('Step 2: Extract common interface definitions');
await agent.execPrompt('Step 3: Refactor core logic');
// Run build and tests to verify changes
const buildResult = await agent.execShell('npm run build');
if (!buildResult.success) {
await agent.execPrompt('Fix build errors');
}
// Completed steps are automatically skipped, supports checkpoint recoveryCollect structured data reliably with built-in validation and retry mechanisms:
// Internal mechanisms ensure stable collection
const result = await agent.execCollectPrompt('Collect all API endpoints', {
keys: [
{ name: 'name', description: 'API name', type: 'string' },
{ name: 'method', description: 'HTTP method', type: 'string' },
{ name: 'path', description: 'API path', type: 'string' }
]
});
// Optionally, add custom validation with checkPrompt
const result = await agent.execCollectPrompt('Collect user data', {
keys: [...],
checkPrompt: 'Verify all email addresses are valid'
});Use forEachParallel to process collected data concurrently:
import { setTaskName, forEachParallel, WorkerConfig, loadCollectData } from 'stepwise';
setTaskName('ProcessAPIs');
// Load previously collected data
const apis = loadCollectData('api_endpoints.json');
// Configure parallel workers with git worktree isolation
const workerConfigs: WorkerConfig[] = [
{ branchName: 'Worker1' },
{ branchName: 'Worker2' },
];
await forEachParallel(apis, workerConfigs, async (ctx) => {
// Each worker has isolated workspace via git worktree
await ctx.stepWise.execPrompt(
'Generate test for API: $name ($method $path)',
{ data: ctx.item }
);
});
// All branches merged automatically after completionUse execCheckPrompt as a routing node to branch to different agents:
const checkResult = await agent.execCheckPrompt('Check if tests pass');
if (!checkResult.result) {
const fixAgent = new StepWise('FixAgent');
await fixAgent.execPrompt('Fix failing tests');
} else {
const deployAgent = new StepWise('DeployAgent');
await deployAgent.execPrompt('Deploy to staging');
}After multiple successful attempts, auto-summarize Skills:
await agent.execPrompt('Configure database connection');
await agent.execPrompt('Create data model');
await agent.execPrompt('Implement CRUD interfaces');
// Auto-summarize on new session
await agent.execPrompt('Next task', { newSession: true });
// Or manually trigger
const summaryResult = await agent.summarize();
console.log('Generated Skill files:', summaryResult.skillFiles);Resume from interruption and use debug mode for quick validation:
import { StepWise, setTaskName, setResumePath, enableDebugMode } from 'stepwise';
// Enable debug mode: collect only 1 item for quick workflow validation
enableDebugMode(true);
setResumePath('MyTask_20260315_143000_123');
setTaskName('MyTask');
const agent = new StepWise('MainAgent');
// Completed steps are automatically skipped
await agent.execPrompt('Step 1: Analyze project'); // Skipped
await agent.execCollectPrompt('Step 2: Collect data', fmt); // Skipped
await agent.execPrompt('Step 3: Process item $name', { data: { name: 'item1' } }); // Resume here| Method | Usage | Description |
|---|---|---|
execPrompt |
Normal task | Execute a single prompt task |
execCollectPrompt |
Collection task | Collect structured data with built-in validation and retry |
execCheckPrompt |
Routing node | Check condition and return true/false for branch routing |
execReport |
Report task | Generate summary report |
execShell |
Shell command | Execute Shell commands (build, test, etc.) |
summarize |
Skill generation | Summarize session and generate Skill |
| Method | Usage | Description |
|---|---|---|
setTaskName |
Set task name | Required, identifies task directory |
setAgentType |
Set AI coding assistant | Optional, default 'claude', options: 'opencode' |
setResumePath |
Set resume path | Resume task from interruption point |
enableDebugMode |
Enable debug mode | Quick validation, collect only 1 item |
setSkipSummarize |
Skip auto-summarize | Disable auto-summarize when creating new session |
saveCollectData |
Save collected data | Save data to JSON file |
loadCollectData |
Load collected data | Load data from JSON file |
| Method | Usage | Description |
|---|---|---|
forEachParallel |
Parallel processing | Auto-manage git worktree for true parallel execution |
For detailed API documentation, see API Reference.
Automatic task directory generation:
stepwise_exec_infos/
└── TaskName_20260315_143000_123/ # TaskName directory (timestamp with ms)
├── report/ # Report output (shared by all agents)
├── Agent1_20260315_143001_456/ # StepWise Agent directory
│ ├── data/ # Execution state
│ │ └── progress.json
│ ├── logs/ # Execution logs
│ │ ├── 1_task/
│ │ ├── 2_collect/
│ │ └── execute.log
│ └── collect/ # Collected data
│ └── 2_collect/
└── Agent2_20260315_143002_789/ # Another agent
└── ...
StepWise implements step control through task sequence numbers and progress persistence:
- Task Sequence Number: Each step has a unique number, auto-incremented
- Progress Persistence: Execution state saved to
progress.json - Session Reuse: Uses
--resumemode to maintain context continuity
- JSON format validation
- Field completeness validation
- Type matching validation
- Auto-generate fix prompts on validation failure
checkPromptoption for custom validation
execCheckPromptoutputs{ result: true/false }tocheck_result.json- Use result to route to different agents
- Enables conditional workflow branching
- Trigger timing: Creating new session or manual call
- Generation conditions: Tasks with multiple successful attempts, valuable experience
- Storage location: Project-level
.claude/skills/directory
StepWise works with AI coding assistants through their headless mode with session reuse:
# Claude Code example
claude --dangerously-skip-permissions --session-id <uuid> -p "your prompt"
claude --dangerously-skip-permissions --resume <session-id> -p "your prompt"
# OpenCode example
opencode run --session <uuid> "your prompt"
# OpenCode auto-detects new vs resume sessionKey mechanisms:
- Session Reuse: Each task step reuses the previous session, maintaining context
- Progress Persistence: Execution state is persisted to local JSON files
- Index Matching: During recovery, completed steps are matched and skipped by index
- Worktree Isolation:
forEachParallelcreates git worktrees for true parallel execution
- API Reference - Detailed API documentation
- Examples - Complete usage examples
- 中文文档 - Chinese documentation
This project is licensed under the MulanPSL2 - Mulan Permissive Software License, Version 2.