# Child State

Child states allow workflows to branch and handle subtasks independently, making complex workflows manageable. Use them to delegate detailed tasks to specialized agents.

```typescript
workflow({
  task: 'Analyze token',
  rootState: { tokenId: 'abc123' },
  childState: { analyzeVolume: true },
});
```

```typescript
interface TokenAnalysis {
  task: string;
  rootState: { tokenId: string };
  childState: {
    analyzeVolume: boolean;
    additionalMetrics?: boolean;
    performRiskAssessment?: boolean;
  };
}

const tokenWorkflow: TokenAnalysis = {
  task: 'Analyze token',
  rootState: { tokenId: 'abc123' },
  childState: { 
    analyzeVolume: true,
    additionalMetrics: true,
    performRiskAssessment: false
  }
};

function workflowAnalysis(params: TokenAnalysis) {
  // Logic for analyzing token based on child state
  if (params.childState.analyzeVolume) {
    console.log(`Analyzing volume for token ID: ${params.rootState.tokenId}`);
  }
  
  if (params.childState.additionalMetrics) {
    console.log('Calculating additional metrics...');
  }
  
  if (params.childState.performRiskAssessment) {
    console.log('Performing risk assessment...');
  }
}

workflowAnalysis(tokenWorkflow);
```
