Migrate a workflow from state-based to tool-based agent. This helps users transition their existing workflows to the new agent.
(
pipeline_id: str,
connection_manager: ConnectionManager = Depends(lambda: ConnectionManager()),
current_user: User = Depends(get_current_user)
)
| 182 | |
| 183 | @router.post("/migrate") |
| 184 | async def migrate_workflow( |
| 185 | pipeline_id: str, |
| 186 | connection_manager: ConnectionManager = Depends(lambda: ConnectionManager()), |
| 187 | current_user: User = Depends(get_current_user) |
| 188 | ) -> Dict[str, Any]: |
| 189 | """ |
| 190 | Migrate a workflow from state-based to tool-based agent. |
| 191 | |
| 192 | This helps users transition their existing workflows to the new agent. |
| 193 | """ |
| 194 | # Get both managers |
| 195 | state_manager = get_enhanced_workflow_manager(connection_manager, use_tools=False) |
| 196 | tools_manager = get_enhanced_workflow_manager(connection_manager, use_tools=True) |
| 197 | |
| 198 | # Get existing workflow |
| 199 | workflow = state_manager.get_workflow(pipeline_id) |
| 200 | if not workflow: |
| 201 | raise HTTPException(status_code=404, detail="Workflow not found") |
| 202 | |
| 203 | # Create simplified message for tool-based agent |
| 204 | migration_summary = [] |
| 205 | |
| 206 | if workflow.urls: |
| 207 | migration_summary.append(f"Found {len(workflow.urls)} URLs to process") |
| 208 | |
| 209 | if workflow.schema_fields: |
| 210 | schema_desc = ", ".join([f.name for f in workflow.schema_fields]) |
| 211 | migration_summary.append(f"Schema fields: {schema_desc}") |
| 212 | |
| 213 | if workflow.generated_code: |
| 214 | migration_summary.append("Has generated code ready") |
| 215 | |
| 216 | # Process with new agent |
| 217 | message = f"""Migrate this workflow to use the new tool-based approach. |
| 218 | |
| 219 | Current state: {workflow.phase.value} |
| 220 | {' '.join(migration_summary)} |
| 221 | |
| 222 | Please analyze the current workflow and suggest how to proceed with the available tools.""" |
| 223 | |
| 224 | result = await tools_manager.process_message(pipeline_id, message, current_user.username) |
| 225 | |
| 226 | return { |
| 227 | "success": True, |
| 228 | "original_workflow": { |
| 229 | "phase": workflow.phase.value, |
| 230 | "urls_count": len(workflow.urls), |
| 231 | "schema_fields_count": len(workflow.schema_fields), |
| 232 | "has_code": bool(workflow.generated_code) |
| 233 | }, |
| 234 | "migration_result": result, |
| 235 | "recommendations": [ |
| 236 | "Use smart_scraper for single-page extraction", |
| 237 | "Use smart_crawler for multi-page scraping", |
| 238 | "Use search_scraper to find new URLs", |
| 239 | "The new agent handles state automatically" |
| 240 | ] |
| 241 | } |
nothing calls this directly
no test coverage detected